Question

I am trying to bootstrap 95% CIs and mean values for measurements in order to examine the effect size of a treatment. The method I want to use is called LnRR or Logarithmic Response Ratio (1, 2, 3). It's calculated simply by Log(Response to treatment / Response to control). If the 95% CIs are not overlapping with 0, there is more than 95% probability for an effect naturally. Negative LnRR means that treatment has a negative effect.

The bootstrapping function in boot package is kind of confusing and I am struggling to calculate 95% CI's and mean values. I have tried following:

library(boot)
set.seed(2)
dat <- data.frame(treatment = rnorm(10, 1.2, 0.4), control = rnorm(10, 1.5, 0.3))

boot(dat, function(x) log(x[,1]/x[,2]), R = 999) # Because LnRR = log(dat[,1]/dat[,2])

I am clearly doing something wrong. How can I bootstrap confidence intervals (boot.ci) for this type of function? I am sure that the answer is here, but for some reason, I just can't understand how to do this.

Was it helpful?

Solution

I agree that the boot synatax is a little confusing, at first. The issue is that you need to write a function that takes both your data, AND a vector i which contains the indices to subsample. Let's rewrite your function explicitly to make it clearer:

yourFun <- function(x, i) {
  xSub <- x[i, ] #resample x
  LnRR <- log(xSub[, 1])/xSub[ ,2]
  return(mean(LnRR))
}

Then call boot in more-or-less the same way that you did:

b <- boot(dat, yourFun, R=999)
plot(b) #always worth looking at

#Calculate ci's
boot.ci(b)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top