Guest User

Untitled

a guest
Jul 17th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. \documentclass[]{article}
  2.  
  3. \usepackage{setspace,relsize,comment,Sweave}
  4.  
  5. \setlength{\oddsidemargin}{0.35cm}
  6. \setlength{\evensidemargin}{0.35cm}
  7. \setlength{\textwidth}{16.2cm}
  8. \setlength{\topmargin}{-1cm}
  9. \setlength{\headsep}{0cm}
  10. \setlength{\textheight}{23.4cm}
  11.  
  12. \SweaveOpts{prefix.string=graphics/}
  13.  
  14. \title{Biostat -- Fantasy Football 2010}
  15. \author{Tatsuki Koyama and Will Gray}
  16.  
  17. \begin{document}
  18.  
  19. \maketitle
  20.  
  21. <<echo=f>>=
  22. library(VICCBiostat)
  23. source('func.r')
  24.  
  25. how.many.to.display <- 20 # for miscellaneous informtion.
  26.  
  27. ## Data ##
  28. sco <- as.matrix(read.csv('points.csv'))
  29. sch <- as.matrix(read.csv('schedule.csv'))
  30. div <- as.matrix(read.csv('divisions.csv'))[1,]
  31. ord <- order(colnames(sco))
  32.  
  33. gd <- gamesData(sco, sch, div)
  34. st <- standings(gd, div)
  35.  
  36. gd <- gd[,!(colnames(gd) %in% 'divg')]
  37. sco <- sco[,ord]
  38. sch <- sch[,ord]
  39. @
  40.  
  41. \section*{Week 1 to Week 13}
  42. \subsection*{Standings}
  43. <<echo=f>>=
  44. st
  45. @
  46.  
  47. \newpage
  48. \subsection*{By Points}
  49. <<echo=f>>=
  50. order2(st, c('pts'), decreasing=c(TRUE))
  51. @
  52.  
  53. \subsection*{By Expected Wins}
  54. <<echo=f>>=
  55. order2(st, c('e.wins','pts'), decreasing=c(TRUE,TRUE))
  56. @
  57.  
  58. \newpage
  59. \subsection*{By Luck}
  60. <<echo=f>>=
  61. order2(st, c('luck','pts'), decreasing=c(TRUE,TRUE))
  62. @
  63.  
  64. \subsection*{By Imaginary Defense}
  65. <<echo=f>>=
  66. order2(st, c('opp.pts','pts'), decreasing=c(FALSE,TRUE))
  67. @
  68.  
  69. <<echo=f>>=
  70. h <- how.many.to.display
  71. wins <- gd[gd$worl == 'Win',]
  72. loss <- gd[gd$worl == 'Loss',]
  73. @
  74.  
  75. \newpage
  76. \section*{Miscellaneous Information}
  77. \subsection*{The highest points}
  78. <<echo=f>>=
  79. data.frame(gd[with(gd, order(pts, decreasing=TRUE)),][1:h, ], row.names=1:h)
  80. @
  81.  
  82. \subsection*{The lowest points}
  83. <<echo=f>>=
  84. data.frame(gd[with(gd, order(pts, decreasing=FALSE)),][1:h, ], row.names=1:h)
  85. @
  86.  
  87. \newpage
  88. \subsection*{The lowest points to win a game}
  89. <<echo=f>>=
  90. data.frame(wins[with(wins, order(pts, decreasing=FALSE)),][1:h, ], row.names=1:h)
  91. @
  92.  
  93. \subsection*{The highest points to lose a game}
  94. <<echo=f>>=
  95. data.frame(loss[with(loss, order(pts, decreasing=TRUE)),][1:h, ], row.names=1:h)
  96. @
  97.  
  98. \newpage
  99. \subsection*{The lowest rank to win a game}
  100. <<echo=f>>=
  101. data.frame(wins[with(wins, order(rank, decreasing=TRUE)),][1:h, ], row.names=1:h)
  102. @
  103.  
  104. \subsection*{The highest rank to lose a game}
  105. <<echo=f>>=
  106. data.frame(loss[with(loss, order(rank, decreasing=FALSE)),][1:h, ], row.names=1:h)
  107. @
  108.  
  109. \newpage
  110. \subsection*{The most lopsided games by points}
  111. <<echo=f>>=
  112. data.frame(wins[with(wins, order(diff.pts, decreasing=TRUE)),][1:h, ], row.names=1:h)
  113. @
  114.  
  115. \subsection*{The closest games by points}
  116. <<echo=f>>=
  117. data.frame(wins[with(wins, order(diff.pts, decreasing=FALSE)),][1:h, ], row.names=1:h)
  118. @
  119.  
  120. \newpage
  121. \subsection*{The most lopsided games by ratio}
  122. <<echo=f>>=
  123. data.frame(wins[with(wins, order(-ratio, decreasing=FALSE)),][1:h, ], row.names=1:h)
  124. @
  125.  
  126. \subsection*{The closest games by ratio}
  127. <<echo=f>>=
  128. data.frame(wins[with(wins, order(-ratio, decreasing=TRUE)),][1:h, ], row.names=1:h)
  129. @
  130.  
  131. \begin{center}
  132. <<echo=f, fig=t, height=12, width=8>>=
  133. plotExpectedWins(sco)
  134. @
  135.  
  136. \subsection*{}
  137. <<echo=f, fig=t, height=12, width=10>>=
  138. plotWinsDistribution(sco)
  139. @
  140.  
  141. \subsection*{}
  142. <<echo=f, fig=t, height=12, width=8>>=
  143. tplot(gd$pts ~ gd$team, type="db", jit=.2, dist=1.2, col=c(Loss=2,Tie=4,Win=1)[as.character(gd$worl)], las=2, pch=20, cex=.8, panel.first=quote({
  144. abline(h=median(gd$pts, na.rm=TRUE), lty=3, col=gray(.75))
  145. abline(h=quantile(gd$pts, .25, na.rm=TRUE), lty=3, col=gray(.75))
  146. abline(h=quantile(gd$pts, .75, na.rm=TRUE), lty=3, col=gray(.75))
  147. }), main="Points Scored")
  148. @
  149.  
  150. \subsection*{}
  151. <<echo=f, fig=t, height=12, width=8>>=
  152. tplot(gd$opp.pts ~ gd$team, type="db", jit=.2, dist=1.2, col=c(Loss=2,Tie=4,Win=1)[as.character(gd$worl)], las=2, pch=20, cex=.8, panel.first=quote({
  153. abline(h=median(gd$opp.pts, na.rm=TRUE), lty=3, col=gray(.75))
  154. abline(h=quantile(gd$opp.pts, .25, na.rm=TRUE), lty=3, col=gray(.75))
  155. abline(h=quantile(gd$opp.pts, .75, na.rm=TRUE), lty=3, col=gray(.75))
  156. }), main="Points Against")
  157. @
  158.  
  159. \subsection*{}
  160. <<echo=f, results=tex>>=
  161. for (team in colnames(sco)) {
  162. postscript(paste("graphics/-",team,".eps",sep=""), width=8, height=8, paper="special", horizontal=FALSE)
  163. rrt2(gd, team)
  164. dev.off()
  165. pdf(paste("graphics/-",team,".pdf",sep=""), width=8, height=8, version="1.1", encoding="default")
  166. rrt2(gd, team)
  167. dev.off()
  168. cat("\\includegraphics{graphics/-",team,"}\n", sep="")
  169. }
  170. @
  171. \end{center}
  172.  
  173. <<echo=f, fig=f>>=
  174. save(sco, sch, div, gd, st, wins, loss, file=paste('data.Rdata', sep=''))
  175. @
  176. \end{document}
Add Comment
Please, Sign In to add comment