[R] sampling and nls formula

Susan Imholt
Tue, 07 Feb 2006 00:06:34 -0000

Hello,

I am trying to bootstrap a function that extracts the log-likelihood value and
the nls coefficients from an nls object.  I want to sample my dataset (pdd) with
replacement and for each sampled dataset, I want to run nls and output the nls
coefficients and the log-likelihood value.

Code:
x<-c(1,2,3,4,5,6,7,8,9,10)
y<-c(10,11,12,15,19,23,26,28,28,30)
pdd<-data.frame(x,y)

i<-sample(10, replace=TRUE)

pdd.lik.coef<-function(data,i){
     d<-data[i,]
     pdd.nls<-nls(d$y~(a*(d$x)^2)/(b+(d$x)^2), data=pdd, start = list(a = 30,
b = 36), trace=FALSE)
     pdd.logLik<-logLik(pdd.nls)
     coeff <- coef(pdd.nls)
     lik.coef <- c(pdd.logLik, coeff)
}

pdd.boot<-boot(data=pdd, statistic=pdd.lik.coef, R=1000)
pdd.boot$t

My problem lies in the pdd.lik.coef function. It seems that nls recognizes all
letters in the formula d$y~(a*(d$x)^2)/(b+(d$x)^2) as parameters, so
"d$y" and "d$x" in the formula aren't being recognized
properly to be sampled, rather the "d" is interpreted as a parameter.
When I try to bootstrap this function, I get an error message: "Error in
eval(expr, envir, enclos) : object "d" not found" (because I
didn't specify an estimate for d as a parameter, since I didn't intend
for it to be a parameter).

Any suggestions?

Thanks,
Susie Imholt
Master's Candidate
Huxley College of the Environment
Western Washington University
Bellingham, WA  USA




_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!