[R] bootstrap

David Winsemius dwinsemius at comcast.net
Sun Mar 6 20:26:01 CET 2011


On Mar 6, 2011, at 1:52 PM, Ashish Kumar wrote:

> In the boot package,consider a scalar function to boot.
>
>> estimator <- function(x, d) {
> +  mean(x[d])
> + }
>>
>> data <- city$u
>> b <- boot(data, estimator, R=1000)
>> b$t0
> [1] 64
>> ci <- boot.ci(b, type=c("bca"), conf=.95)
>> ci$bca
>     conf
> [1,] 0.95 49.44 991.39 36.78807 110.0254
>
> Now if I want estimators to return a vector,E.g. it's
> {c(mean(x[d]), sd(x[d]))}, boot.ci() should give me
> a vector of low bounds and high bounds of the 95% confidence
> interval. But that does not happen.

It appears to have happened. The last two numbers in the output below  
are what are supposed to be your CI.
>
>> estimator <- function(x, d) {
> +  c(mean(x[d]), sd(x[d]))
> + }

>>
>> data <- city$u
>> b <- boot(data, estimator, R=1000)
>> b$t0
> [1] 64.00000 56.21585

So you got a vector of estimates. What is the problem? did you look at  
str(b)?

>> ci <- boot.ci(b, type=c("bca"), conf=.95)
>> ci$bca
>     conf
> [1,] 0.95 68.27 995.48 39.2 105.4292

You may have mis-informed boot.ci, since it was expecting the second  
column to be variances and you supplied it sd's. Look at the  
documentation for the index argument in boot.ci.


-- 
David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list