Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require(boot)
- # relative yield takes a matrix or dataframe and finds the ratio
- # of the means: treatmentMean/controlMean.
- # data structure:
- # first column is strata, control = 1 and treatment = 2
- # second column is response, or the data to be bootstrapped
- rel.yield <- function(D,i) {
- trt <- D[i,1]
- resp <- D[i,2]
- mean(resp[trt==2]) / mean(resp[trt==1])
- }
- # some data that has a true rel.yield of 10
- sub.pop <- matrix(data = c(rep(1,15),rep(2,15),rnorm(15,2,1),rnorm(15,20,1)),
- nrow = 30, ncol = 2, dimnames = list((1:30),c('trt','resp')))
- # with strata specified
- b <- boot(sub.pop, rel.yield, R = 1000, strata = sub.pop[,1])
- #without strata specified
- c <- boot(sub.pop, rel.yield, R = 1000)
- # note the distributions of t* are similar
- par(mfrow=c(1,2))
- hist(b$t)
- abline(v=mean(b$t))
- hist(c$t)
- abline(v=mean(c$t))
- # and the CI estimates are also similar
- boot.ci(b)
- boot.ci(c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement