[R] bootstrap: boot package

Roger Peng rpeng at stat.ucla.edu
Fri Jan 25 22:50:40 CET 2002


Hi Rob, here's an example I worked out:

> data <- rnorm(100)
> f <- function(x, i) { median(x[i]) }
> b <- boot(data, f, R = 1000)
> b

ORDINARY NONPARAMETRIC BOOTSTRAP


Call:
boot(data = data, statistic = f, R = 1000)


Bootstrap Statistics :
       original      bias    std. error
t1* -0.07986221 0.008121274  0.09311031

> boot.ci(b, type="perc")
BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
Based on 1000 bootstrap replicates

CALL : 
boot.ci(boot.out = b, type = "perc")

Intervals : 
Level     Percentile     
95%   (-0.2264,  0.1228 )  
Calculations and Intervals on Original Scale


-roger
_______________________________
UCLA Department of Statistics
rpeng at stat.ucla.edu
http://www.stat.ucla.edu/~rpeng

On Fri, 25 Jan 2002, Rob Gould wrote:

> I'm teaching a class and using R for the first time.  We're talking 
> about the bootstrap, and I've been trying to get R to replicate some 
> simple bootstrap programs with no success.  I'd like to be able to use 
> the boot.ci function to produce confidence intervals (non-parametric) 
> for some simple statistics, and this requires first creating a "boot" 
> object.  The boot object, in turn, requires a statistic that takes two 
> inputs: the data and the second a vector of indices, frequencies, or 
> weights which "define" the bootstrap.  My question, I guess, is which 
> option do I choose to "define" an ordinary sample-with-replacement?  And 
> where does this vector come from?  Suppose I want to bootstrap a 
> confidence interval for the mean.  Do i have to write my own "mean" 
> function to provide for this defining vector of indices?
> 
> Just to clarify, I want to use the boot command to replicate this:
> bstraps <- c()
> for (i in 1:R){
> bstraps <- c(mean(sample(data,replace=T,n=length(data))), bstraps)}
> 
> thanks,
> Rob
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list