[R] Add covariate in nlme?
Ben Bolker
bbolker at gmail.com
Wed Apr 18 14:38:26 CEST 2012
hwouters <heidiwout <at> gmail.com> writes:
>
> Hi R-experts,
>
> I have a problem using nlme. I use the following code to group my data:
>
> Parameterg <- groupedData( result ~ time | Batch,
> data = Batchdata,
> labels = list( x = "Time", y = "analysis")
> )
While groupedData() is the recommended approach in the
Pinheiro and Bates book (and simplifies automated plotting etc.),
it is often more transparent to instead specify the grouping
factor within the random effects definition (i.e. eps~time|Batch
below, I think ... ?)
> and then uses the nlme function to fit a nonlinear mixed model that
> includes
> Process as a fixed covariate:
A.
> nlme.model001epr <- nlme(result ~ A0 * exp(- ( exp(A1) * exp(-Ea /
> (0.0083144*TEMP.K)) * exp(eps)) * time),
> data = Parameterg,
> fixed=list(A0+Ea~1,A1~Process),
> random=eps~1,
> start=c(93, 92, 34.5,37),
> control=list(msVerbose=TRUE, maxIter = 200),
> verbose=TRUE, method="REML",
> na.action=na.pass)
Have you tried removing any NA values up front rather than
using na.pass?
> this fit give the following error:
> Error in MEEM(object, conLin, control$niterEM) :
> Singularity in backsolve at level 0, block 1
>
> HOWEVER, in SAS the same model with covariate is WORKING!
B.
> When I'm changing the fixed part in nmle as follows
> fixed=list(A0+Ea~1,A1~1|Process),
This looks like the wrong syntax to me. What are you trying to accomplish
here that's different from A1~Process above?
>
> then the following error is popping up:
>
> Error in contr.treatment(n = 0L) :
> not enough degrees of freedom to define contrasts
> In addition: Warning messages:
> 1: In Ops.factor(1, Process) : | not meaningful for factors
> 2: In Ops.factor(1, Process) : | not meaningful for factors
>
> However, when adding the process as a random effect it works:
> nlme.model001epr <- nlme(result ~ A0 * exp(- ( exp(A1) * exp(-Ea /
> (0.0083144*TEMP.K)) * exp(eps) ) * time),
> data = Parameterg,
> fixed=list(A0+Ea+A1~1),
> random=eps~1|Process/Batch,
> start=c(93, 92, 34.5),
> control=list(msVerbose=TRUE, maxIter = 200),
> verbose=TRUE, method="REML",
> na.action=na.pass)
> Does anybody knows what the correct implementation is for adding a
> covariate
> in a nlme and what might be my problem here?
There's a difference in your attempts above -- I will say up front
that I'm not quite sure how the information encoded in groupedData
propagates to your final model.
In A. eps is a random effect, I assume that it inherits its grouping
structure (Batch) from the groupedData structure, but I'm not sure. A1
varies (fixed) across Processes.
B. doesn't work at all.
in C. you are adding a random effect of Batch nested within process
to eps ; A1 no longer varies.
Bottom line: I'm not sure what you're actually trying to do here.
Follow-ups should go to r-sig-mixed-models <at> r-project.org.
A reproducible example would be strongly recommended (see e.g
http://tinyurl.com/reproducible-000 )
Ben Bolker
More information about the R-help
mailing list