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

Tomas Zelinsky tomas.zelinsky at tuke.sk
Thu Jan 21 13:45:04 CET 2010


   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/


More information about the R-help mailing list