[R] boot.ci and NA values

Lucia Costanzo lcostanz at uoguelph.ca
Fri Sep 28 21:47:39 CEST 2007


Hi,

I have been trying to run the code below. In the event of non-convergence, 
the statistic in the boot function returns NA as a value. To obtain a BCA 
confidence interval, I use boot.ci but, if NA recorded as a value for the 
statistic for one the replicates the following error appears:

Error in if (const(t, min(1e-08, mean(t)/1e+06))) { :
         missing value where TRUE/FALSE needed

To overcome this, I reformat the output of the bootstrap calculation by 
removing all instances of NA. By doing so the error message does not 
reappear but, I am suspicious of the results.  When I run a simulation 
with 1000 iterations, the coverage probability is 1.

Is this the correct approach for tackling NA values when using boot.ci?

Thanks, Lucia


library(boot)
source(file = "http://www.uoguelph.ca/~lcostanz/mima1.ssc")

# ----- Teo Dataset -----
studynum <-c(1, 2, 3, 4, 5, 6, 7)
y <- 
c(-0.79851,-0.938269639,-1.252762968,-0.042559614,0.209720531,-2.249410331,-1.181993898)
w <- 
c(0.644007,5.903041825,1.531728665,0.489578714,4.19421878,0.872663243,0.705810147)
genData2<-data.frame(studynum, y, w)

set.seed(4700)

mima.func<-function(x, i) {

 	x<-x[i,] # select obs. in bootstrap sample
 	reREML<-mima1(x$y, 1/x$w, mods = c(), method = "REML", out="yes")

 	if (length(reREML) == 0)
 	{
 		ests<-c(NA,NA)
 	}
 	else
 	{
 		ests<-c(reREML$b,reREML$vart)
 	}
}

boot.teo4a<-boot(genData2, mima.func, R=2000,)

ci.teo4<-boot.ci(boot.teo4a, conf = c(0.95), type = c("bca"))

#remove all instances of NA
boot.teo4 = boot.teo4a
boot.teo4$t0 = na.omit(boot.teo4$t0)
boot.teo4$t = na.omit(boot.teo4$t)
boot.teo4$R = length(boot.teo4$t[,1])
boot.teo4$call[4] = boot.teo4$R
ci.teo4<-boot.ci(boot.teo4, conf = c(0.95), type = c("bca"))



More information about the R-help mailing list