I was attempting to use the residual resampling approach to generate 999 
bootstrap samples of alpha and beta and find their confidence intervals. 
However, I keep getting the error message:Error in nls(resample.mp ~ 
cases/(alpha + (beta * cases)), start = init.values,  :         singular 
gradientafter R has only produced a few bootstraps.Could anyone suggest where I 
am going wrong? Would greatly appreciate it!Mary 
manpower<-read.table("http://www.creem.st-and.ac.uk/len/classes/mt3607/data/manhours_surgical.dat";,
 header=TRUE)#attach dataattach(manpower)B<-999#number of data 
pointsn<-dim(manpower)[1]#alpha level to use for the confidence 
limitsalpha<-0.05#matrix that's going to contain the bootstrap 
coefficientsboot.coef<-matrix(NA, B+1, 2)#fit the initial 
modelinit.values<-c(alpha=20,beta=0)model<-nls(manhours~cases/(alpha+(beta*cases)),
 start=init.values, trace=TRUE)pred<-predict(model)resid<-resid(model)#do the 
bootstrapfor (i in 1:B){  #resample the residuals  resample.ind!
 ex<-sample(1:n,n,replace=T)  resample.mp<-pred+resid[resample.index]  #refit 
the model  init.values<-c(alpha=20,beta=0)  
new.model<-nls(resample.mp~cases/(alpha+(beta*cases)),start=init.values, 
trace=TRUE)  #extract the parameter estimates  
boot.coef[i,]<-coef(new.model)}#add the original parameter estimates 
boot.coef[B+1,]<-coef(model)#calculate confidence intervalsfor(i in 1:2){  
ci<-quantile(boot.coef[,i],probs=c(alpha/2,(1-alpha/2)))  cat("residual 
bootstrap confidence intervals for parameter",i,"are",ci,"\n")}

Miss your Messenger buddies when on-the-go? Get Messenger on your Mobile! 
_________________________________________________________________
Win Indiana Jones prizes with Live Search

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to