[R] a difficulty in boot package
Uwe Ligges
ligges at statistik.tu-dortmund.de
Sat Jun 20 17:10:02 CEST 2009
Seunghee Baek wrote:
> Hi,
> I have a problem in programming for bootstrapping.
> I don't know why it show the error message.
> Please see my code below:
> #'st' is my original dataset.
> #functions of 'fml.mlogl','pcopula.fam4','ltd','invltd' are already defined
>
> boot.OR<-function(data,i)
> {
> E=data[i,]
> ml1<-glm(c_VAsex90_bf ~ trt,family=binomial,data=E)
> ml2<-glm(c_VAsex90_bm ~ trt,family=binomial,data=E)
> marg.covariates<-cbind(rep(1,length(E$trt)),E$trt)
> dep.covariates<-cbind(rep(1,length(E$age_avr)),E$age_avr)
> start<-c(ml1$coef,ml2$coef,0,0)
> fml1<-optim(start,fml.mlogl,control=c(maxit=10000),hessian=F)
> x<-(1+exp(fml1$par[1]))^(-1)
> y<-(1+exp(fml1$par[3]))^(-1)
> b<-exp(fml1$par[5]+fml1$par[6]*43)+1
> p00<-ltd(-log(pcopula.fam4(exp(-invltd(x,b)),exp(-invltd(y,b)),b)),b)
> p1<-exp(fml1$par[1])/(1+exp(fml1$par[1]))
> p2<-exp(fml1$par[3])/(1+exp(fml1$par[3]))
> OR<-p00*(p00+p1+p2-1)/(1-p2-p00)/(1-p1-p00)
> OR
> }
>
> set.seed(101)
>
> boot(st,boot.OR,R=500)
>
> #------------------------------------------------------------#
> I gives following error message:
> Error in fn(par, ...) : object "dep.covariates" not found
Since you have not specified all function I can only guess that you need
dep.covariance in function fml.mlogl() in your optim() call. In that
case you need to pass it as an argument, otherwise it is not in the
search path given R's scoping rules.
Hence, for example, define
fml.mlogl <- function(......., dep.covariates)
and call ist with
optim(........, dep.covariates=dep.covariates)
Best,
Uwe Ligges
> I hope you can help me in this problem.
>
> Thanks,
> Becky
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list