Skip to content

Estimation of S.E. based on bootstrapping (functions with two or more arguments)

2 messages · Tomas Zelinsky, Chuck Cleland

#
Hi all,

   I need to estimate S.E. of a certain indicator. The function to compute the
   value of indicator contains two arguments. Can anybody tell me how to do it?

   Example:
   
   We have data:
   a <- c(1:10)
   b <- c(11:20)
   data <- data.frame(a, b)

   Function to compute value of the indicator:
   indicator <- function(X, Y) sum(X)/(sum(Y)*2)

   Next I need to do the bootstrapping and estimate mean value of indicator and
   its standard error.

   If the function (indicator in my case) contained only one argument, there
   would not  be a problem, the code would look like:

   resamples <- lapply(1:1000, function(i) sample(data, replace = T))
   r.indicator <- sapply(resamples, indicator)
   mean(r.indicator)
   sqrt(var(r.indicator))


   But in case of function with two arguments it doesn???t work. I tried to do it
   like:
   resamples <- lapply(1:1000, function(i) data[sample(1:nrow(data), replace =
   TRUE),])
   r.indicator <- sapply(resamples, indicator)

   but it didn't work.


   Can anybody help?

   Thanks a lot.

   Tomas

   __________  Informacia  od  ESET NOD32 Antivirus, verzia databazy 4792
   (20100121) __________
   Tuto spravu preveril ESET NOD32 Antivirus.
   [1]http://www.eset.sk

References

   1. http://www.eset.sk/
#
On 1/21/2010 7:45 AM, Tomas Zelinsky wrote:
How about using boot() in package boot?  Using your example:

 a <- c(1:10)
 b <- c(11:20)
DF <- data.frame(a,b)

library(boot)

boot(DF,
     statistic = function(d, ind){sum(d$a[ind])/sum(d$b[ind]*2)},
     R = 1000)

ORDINARY NONPARAMETRIC BOOTSTRAP

Call:
boot(data = DF, statistic = function(d, ind) {
    sum(d$a[ind])/sum(d$b[ind] * 2)
}, R = 1000)

Bootstrap Statistics :
     original       bias    std. error
t1* 0.1774194 -0.001594390  0.01902264