Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. require(boot)
  2. # relative yield takes a matrix or dataframe and finds the ratio
  3. # of the means: treatmentMean/controlMean.
  4. # data structure:
  5. # first column is strata, control = 1 and treatment = 2
  6. # second column is response, or the data to be bootstrapped
  7. rel.yield <- function(D,i) {
  8. trt <- D[i,1]
  9. resp <- D[i,2]
  10. mean(resp[trt==2]) / mean(resp[trt==1])
  11. }
  12.  
  13. # some data that has a true rel.yield of 10
  14. sub.pop <- matrix(data = c(rep(1,15),rep(2,15),rnorm(15,2,1),rnorm(15,20,1)),
  15. nrow = 30, ncol = 2, dimnames = list((1:30),c('trt','resp')))
  16.  
  17. # with strata specified
  18. b <- boot(sub.pop, rel.yield, R = 1000, strata = sub.pop[,1])
  19. #without strata specified
  20. c <- boot(sub.pop, rel.yield, R = 1000)
  21.  
  22. # note the distributions of t* are similar
  23. par(mfrow=c(1,2))
  24. hist(b$t)
  25. abline(v=mean(b$t))
  26. hist(c$t)
  27. abline(v=mean(c$t))
  28.  
  29. # and the CI estimates are also similar
  30. boot.ci(b)
  31. boot.ci(c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement