[R] syntax of nlme
Douglas Bates
bates at stat.wisc.edu
Mon Sep 11 20:21:45 CEST 2006
On 9/11/06, Thomas Wutzler <thomas.wutzler at web.de> wrote:
> Hello,
>
>
> How do I specify the formula and random effects without a startup object
> ? I thought it would be a mixture of nls and lme.
> after trying very hard, I ask for help on using nlme.
>
> Can someone hint me to some examples?
There are quite a few examples in the book Pinheiro and Bates (2000),
"Mixed-effects Models in S and S-PLUS"
> I constructed a try using the example from nls:
>
> #variables are density, conc and Run
> #all works fine with nls
> DNase1 <- subset(DNase, Run == 1 )
> fm2DNase1 <- nls( density ~ 1/(1 + exp((xmid - log(conc))/scal)),
> data = DNase1,
> start = list(xmid = 0, scal = 1),
> trace = TRUE)
>
> #Now I want to do a mixed model with covariate Run
Do you mean that "Run" is the grouping factor for the random effects?
Your formulas for fixed and random in the function call below don't
make sense. The left hand side of each formula should be an
expression that involves parameters xmid and/or scal, not the
covariate conc or the grouping factor Run.
Also the starting estimates should either be a named numeric vector or
a list with a component called "fixed" that is a named numeric vector.
> #how is the syntax?
> DNase12 <- subset(DNase, Run == 1 | Run == 2)
> fm2DNase1 <- nlme( density ~ 1/(1 + exp((xmid - log(conc))/scal)),
> data = DNase12,
> fixed = conc ~ 1,
> random = Run ~ 1,
> start = list(xmid = 0, scal = 1)
> )
> #gives: Error in eval(expr, envir, enclos) : object "xmid" not found
> library(nlme)
> fm2DNase1 <- nlme( density ~ 1/(1 + exp((xmid - log(conc))/scal)),
+ data = DNase,
+ fixed = xmid + scal ~ 1,
+ random = xmid ~ 1|Run,
+ start = list(fixed = c(xmid = 0, scal = 1)))
By the way, that model doesn't make sense. The fitted values from the
model must be in the range [0,1] but the observed values exceed 2
> range(DNase$density)
[1] 0.011 2.003
Also, it is not a good idea to fit a nonlinear mixed effects model
when you have only two levels of the grouping factor. You are
estimating variances. Doing so with only two distinct groups is quite
inaccurate.
More information about the R-help
mailing list