Orat
Orat

Reputation:

Bootstrapping with R

I have some trouble in calculating a confidence interval with bootstrap method using R. Here is a minimal example that I get stuck.

library(simpleboot)
set.seed(123)
random <- data.frame(x=runif(10), y=runif(10))
pi <- function(df){4*length(subset(df, x^2 + y^2 < 1)$x)/length(df$x)}
pi.boot <- one.boot(random, pi, 1000) # I got an error here

I got an error which says

Error in [.data.frame(x, idx) : undefined columns selected

Would you help me to find out what is wrong with it? Thank you.

Upvotes: 1

Views: 286

Answers (1)

Robert
Robert

Reputation: 5152

See if this is what you want:

x<-1:nrow(random)
pif <- function(yt,dft){4*length(subset(dft[yt,], x^2 + y^2 < 1)$x)/length(dft[yt,]$x)}
pi.boot <- one.boot(x, pif, 1000,dft=random) # no error 

#print(pi.boot)
boot.ci(pi.boot)  
#hist(pi.boot)

BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 1000 bootstrap replicates

CALL : 
boot.ci(boot.out = pi.boot)

Intervals : 
Level      Normal              Basic         
95%   ( 2.202,  4.194 )   ( 2.400,  4.400 )  

Level     Percentile            BCa          
95%   ( 2.0,  4.0 )   ( 1.6,  3.6 )  
Calculations and Intervals on Original Scale
Warning : BCa Intervals used Extreme Quantiles
Some BCa intervals may be unstable

Upvotes: 1

Related Questions