[R-sig-ME] nlme model not working but lme models are fine [SEC=UNCLASSIFIED]

Gosse, Michelle Michelle.Gosse at foodstandards.gov.au
Tue Jan 10 20:05:47 CET 2012


Hi all,

I have a nicely working lme model from the lme4 package, however I have been requested to produce a nonlinear model and I am having problems with the model specification.

My working lme4 code is:
Male.lme1 <- lmer(BoxCoxXY ~ AgeFactor + IntakeDay + (1|RespondentID),
	data=Male.Data,
	weights = SampleWeight)

Where:
BoxCoxXY are transformed nutrient intake values AgeFactor is the age band for the subject, this has been converted to a factor. There are 4 agebands in the current dataset, and these are in ascending order. The values for AgeFactor are 1,2,3,4.
IntakeDay is either "IntakeDay1" or IntakeDay2", depending on whether it is the first 24-hour recall period or the second, for food intake (used to calculate the raw nutrient intake) RespondentID is the subject number, this has been converted to a factor I'm doing the analysis separately by gender, so all my data relate to males, hence the data frame names.

I am now trying to fit this data using nlme in the nlme package. I've been taking hints from the Machines and Wafers data, as these seem closest to my data frame. I just can't get the nlme model to work.

In my R session, at this point I've detached lme4 and attached nlme. These two bits of code work fine, and the lme coefficient estimates from the nlme package are exactly the same as those from the lme in the lme4 package, so I believe I have the linear model specified correctly in nlme, the issue seems to be getting the nlme model to work. The working code in nlme is (I am using lme to generate the fixed effect coefficients to put into the nlme model as the starting parameters):

Male.Group <- groupedData(BoxCoxXY ~ RespondentID|AgeFactor, data=Male.Data) # This seems to be the most sensible grouping as the subjects are grouped within age, with repeated intake measures grouped within subject.

male.lme2 <- lme(BoxCoxXY ~ ordered(AgeFactor) + IntakeDay,
		data = Male.Group,
		random = ~ 1 | RespondentID)
		

When I run the next bit,I get an error. Error and traceback() provided after the syntax:

Male.nlme <- nlme(BoxCoxXY ~ ordered(AgeFactor) + IntakeDay,
		fixed = ordered(AgeFactor) + IntakeDay ~ 1,
		random = RespondentID ~ 1,
		data = Male.Group,
		start= fixef(male.lme2)
		)

I get the error message:
Error in eval(expr, envir, enclos) : object 'AgeFactor' not found

The results of traceback() are:
8: eval(expr, envir, enclos)
7: eval(x[[length(x)]], dat)
6: FUN(X[[1L]], ...)
5: lapply(form, function(x, dat, N) {
       val <- eval(x[[length(x)]], dat)
       if (length(val) == 1) {
           return(as.factor(rep(val, N)))
       }
       else {
           return(as.factor(val)[drop = TRUE])
       }
   }, dat = object, N = nrow(object))
4: getGroups.data.frame(dataMix, eval(parse(text = paste("~1", deparse(groups[[2]]), 
       sep = "|"))))
3: getGroups(dataMix, eval(parse(text = paste("~1", deparse(groups[[2]]), 
       sep = "|"))))
2: nlme.formula(BoxCoxXY ~ ordered(AgeFactor) + IntakeDay, fixed = ordered(AgeFactor) + 
       IntakeDay ~ 1, random = RespondentID ~ 1, data = Male.Group, 
       start = fixef(male.lme2))
1: nlme(BoxCoxXY ~ ordered(AgeFactor) + IntakeDay, fixed = ordered(AgeFactor) + 
       IntakeDay ~ 1, random = RespondentID ~ 1, data = Male.Group, 
       start = fixef(male.lme2))

Could someone advise me where I have gone wrong? I don't understand how nlme cannot find AgeFactor where the other syntax didn't have an issue.

cheers
Michelle

UNCLASSIFIED
**********************************************************************
This email and any files transmitted with it are confide...{{dropped:9}}




More information about the R-sig-mixed-models mailing list