Advertisement
Guest User

Bootstrapping code Chris Davis

a guest
Jul 1st, 2013
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.23 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement