Skip to content
Prev 155615 / 398502 Next

writing simple function through script

Benoit Boulinguiez <benoit.boulinguiez <at> ensc-rennes.fr> writes:
This is my most frequently used Brian Ripley trick which I always have to look
up in my examples list. Getting the environment right is the most difficult part
in writing R packages

Dieter

DNase1 <- subset(DNase, Run == 1)
DNase1$Qe = rnorm(nrow(DNase1),1,0.1)
LgmFormula = density ~ SSlogis(log(conc), Asym, xmid, scal)
fm1DNase1 <- nls(LgmFormula, DNase1)

y0 = function(Xdata)
{
  LgmFormula = density ~ SSlogis(log(conc), Asym, xmid, scal)
  # the following fails
  #nls(LgmFormula, Xdata, weights=Xdata$Qe)
# Brian Ripley trick to get around an issue in lme (not only)
# http://finzi.psych.upenn.edu/R/Rhelp02a/archive/16599.html
  eval(substitute(nls(LgmFormula,Xdata),  list(form=LgmFormula)))
}

y0(DNase1)