[R] Lost in substitute: nlsList and nlme with dynamic formula
Dieter Menne
dieter.menne at menne-biomed.de
Thu Aug 23 14:36:13 CEST 2007
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
More information about the R-help
mailing list