Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Bootstrapping code Chris Davis

By: a guest on Jul 1st, 2013  |  syntax: R  |  size: 1.23 KB  |  views: 93  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #define your vectors, for cbind statement
  2.  
  3. datawOBA=  cbind(PA,AB,HR,x1B,x2B,x3B,SF,BB,IBB,HBP)
  4. wOBAsample=c()
  5. ALLHR=c()
  6. ALLAB=c()
  7. ALLPA=c()
  8. ALLx1B=c()
  9. ALLx2B=c()
  10. ALLx3B=c()
  11. ALLBB=c()
  12. ALLIBB=c()
  13. ALLHBP=c()
  14. ALLSF=c()
  15. ALLwOBA=c()
  16. ALLoWAR=c()
  17. for(i in 1:1000){                                                          
  18. bootstrapsample=sample(1:nrow(data),size=630,replace=T)      
  19. databootstrap=data[bootstrapsample,]
  20. totals=colSums(databootstrap)
  21. PAproj=totals[1]
  22. ABproj=totals[2]
  23. HRproj=totals[3]
  24. x1Bproj=totals[4]
  25. x2Bproj=totals[5]
  26. x3Bproj=totals[6]
  27. SFproj=totals[7]
  28. BBproj=totals[8]
  29. IBBproj=totals[9]
  30. HBPproj=totals[10]
  31. wOBAproj= (0.688* totals[8]+ 0.719* totals[10]+ 0.883* totals[4]+ 1.261* totals[5]+ 1.602* totals[6]+
  32. 2.078* totals[3])/ (totals[2]+ totals[8]+ totals[7]+ totals[10] - totals[9])
  33. ALLwOBA[i]=wOBAproj
  34. WARproj= (((wOBAproj- 0.313)/1.261)*totals[1] +-2.4 -12.5 + 0.5 + 20/600*totals[1])/10
  35. ALLPA[i]=PAproj
  36. ALLAB[i]=ABproj
  37. ALLHR[i]=HRproj
  38. ALLx1B[i]=x1Bproj
  39. ALLx2B[i]=x2Bproj
  40. ALLx3B[i]=x3Bproj
  41. ALLBB[i]=BBproj
  42. ALLSF[i]=SFproj
  43. ALLIBB[i]=IBBproj
  44. ALLHBP[i]=HBPproj
  45. ALLoWAR[i]=WARproj}
  46.  
  47.  
  48. cbind(PA[x],AB[x],HR[x],x1B[x],x2B[x],x3B[x],BB[x],IBB[x],SF[x], HBP[x], wOBA[x], oWAR[x])
  49.  
  50. #define x
clone this paste RAW Paste Data