[R] nlme questions
Christian Mora
christian_mora at arauco.cl
Fri Nov 18 13:32:33 CET 2005
Yes, I agree. But if you define at the beginning of the code:
data$trt1<-as.factor(data$trt1)
data$trt2<-as.factor(data$trt2)
being trt1 and trt2 dummy variables with values 0 or 1, and then run the
model, for instance:
fit_1<-nlme(Y~b0/(1+exp((b1-X)/b2)),fixed=b0+b1+b2~trt1+trt2,
random=b0+b1+b2~1,data=data,start=fixef(fit_0))
the augPred function doesn't work and return the error
"Error in predict.nlme(object, value[1:(nrow(value)/nL),,drop=FALSE], : Levels 0,1 not allowed for trt1,
trt2"
but, if you modify the code as
fit_2<-nlme(Y~b0/(1+exp((b1-X)/b2)),fixed=b0+b1+b2~factor(trt1)+factor(trt2),
random=b0+b1+b2~1,data=data,start=fixef(fit_0))
i.e. indicating again that trt1 and trt2 are factors, even when they were
previouslly defined as factors through the function "as.factors", then
augPred works
"Austin, Matt" <maustin at amgen.com> on 18-11-2005 07:19:24
To: "'Christian Mora'" <christian_mora at arauco.cl>, Spencer Graves
<spencer.graves at pdf.com>
cc: r-help at stat.math.ethz.ch
Subject: RE: [R] nlme questions
Warning: non-expert thoughts to follow.
When passing an object to a predict method, the method looks at (a copy) of
the original information from the dataframe that was used in the fit. Your
original data contains information on trt1 and trt2, but factor(trt1) and
factor(trt2) cannot be found in the original data. If you did the factor
conversion in the original data
myDat <- factor(myDat$trt1)
myDat <- factor(myDat$trt2)
then used myDat as the dataframe in the nlme call, all information would be
available for the augPred method. That's why it works when you use trt1
and
trt2 instead of factor(trt1) and factor(trt2). There is actually an
implicit factor conversion happening in the nlme call if trt1 and trt2 are
character variables, however if trt1 and trt2 are defined as numeric (ie 0
1) then it will fit as a numeric.
--Matt
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Christian Mora
> Sent: Friday, November 18, 2005 4:01 AM
> To: Spencer Graves
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] nlme questions
>
>
>
>
>
>
>
> Spencer;
>
> Thanks for your suggestions. I found the problem is in the
> library nlme. If
> you define phi1~factor(trt1)+factor(trt2) instead of
> phi1~trt1+trt2 the
> augPred function works. A bug? I don't know.
>
> Christian
>
>
>
>
>
>
> Spencer Graves <spencer.graves at pdf.com> on 17-11-2005 20:19:32
>
> To: Christian Mora <christian_mora at arauco.cl>
> cc: r-help at stat.math.ethz.ch
>
> Subject: Re: [R] nlme questions
>
>
> Both your questions seem too vague to me. You might get
> more useful
> replies if you provide a simple example in a few lines of R
> code that a
> reader could copy from your email into R and see the result (as
> suggested in the posting guide!
> "www.R-project.org/posting-guide.html").
> The process of preparing such a simple example might by
> itself provide
> the insight you desire. Alternatively, you might work line by line
> through the code for the R function you are using. Also, if you don't
> have Pinheiro and Bates (2000) Mixed-Effects Models in S and S-PLUS
> (Springer), I suggest you get it; it is excellent for things
> like this.
>
> I'm sorry I couldn't help more.
> spencer graves
>
> Christian Mora wrote:
>
> >
> >
> >
> > Dear R users;
> >
> > Ive got two questions concerning nlme library 3.1-65
> (running on R 2.2.0
> /
> > Win XP Pro). The first one is related to augPred function. Ive been
> working
> > with a nonlinear mixed model with no problems so far.
> However, when the
> > parameters of the model are specified in terms of some
> other covariates,
> > say treatment (i.e. phi1~trt1+trt2, etc) the augPred
> function give me the
> > following error: "Error in predict.nlme(object,
> > value[1:(nrow(value)/nL),,drop=FALSE], : Levels 0,1 not
> allowed for trt1,
> > trt2". The same model specification as well as the augPred
> function under
> > SPlus 2000 run without problems. The second question has to
> deal with the
> > time needed for the model to converge. It really takes a
> lot of time to
> fit
> > the model on R in relation to the time required to fit the
> same model on
> > SPlus. I can imagine this is related to the optimization
> algorithm or
> > something like that, but I would like to have a different opinion on
> these
> > two issues.
> >
> > Thanks in advance
> >
> > Christian Mora
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
> --
> Spencer Graves, PhD
> Senior Development Engineer
> PDF Solutions, Inc.
> 333 West San Carlos Street Suite 700
> San Jose, CA 95110, USA
>
> spencer.graves at pdf.com
> www.pdf.com <http://www.pdf.com>
> Tel: 408-938-4420
> Fax: 408-280-7915
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list