[R] Lost in substitute: nlsList and nlme with dynamic formula

From: Dieter Menne <dieter.menne_at_menne-biomed.de>
Date: Thu, 23 Aug 2007 14:36:13 +0200


DeaR

I am trying to use a dynamically create formula with nlsList and nlme, but I cannot get the environment of the string-generated formal to work similarly to the manually entered one.

Any idea?

Dieter

#-----

library(nlme)
# Pinheiro/Bates p 280
fm1Indom.lis = nlsList(conc~SSbiexp(time,A1,lrc1,A2,lrc2),   data=Indometh)
nlme(fm1Indom.lis,random=pdDiag(A1+lrc1+A2~1))
# works...

# Simulating a dynamic formula

form = as.formula("conc~SSbiexp(time,A1,lrc1,A2,lrc2)") fm2Indom.lis = nlsList(form,data=Indometh)
# still correct

nlme(fm2Indom.lis,random=pdDiag(A1+lrc1+A2~1))
#Error in switch(mode(x), "NULL" = structure(NULL, class = "formula"), :
# invalid formula

# B.D. Ripley val(subst) workaround
# http://finzi.psych.upenn.edu/R/Rhelp02a/archive/16599.html
fm3Indom.lis = eval(substitute(nlsList(form,data=Indometh)),   list(form=form))
nlme(fm3Indom.lis,random=pdDiag(A1+lrc1+A2~1))
#.. Same error



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 and provide commented, minimal, self-contained, reproducible code. Received on Thu 23 Aug 2007 - 12:45:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 23 Aug 2007 - 13:34:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.