Created
January 8, 2013 15:40
-
-
Save jknowles/4484754 to your computer and use it in GitHub Desktop.
A shiny app to demonstrate the relationship between field goal kicking and distance for two NFL kickers. Useful for demonstrating some statistical properties.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| library(scales) | |
| # obs | |
| # length | |
| dat<-data.frame(dist=c("all","under20","twenties","thirties","forties","over50"), | |
| att=c(266,6,79,74,85,22), | |
| made=c(230,6,76,67,66,15)) | |
| dat$per<-dat$made/dat$att | |
| dat$distprob<-dat$att/266 | |
| dat2<-data.frame(dist=c("all","under20","twenties","thirties","forties","over50"), | |
| att=c(585,10,127,163,169,87), | |
| made=c(481,10,124,152,124,50)) | |
| dat2$per<-dat$made/dat$att | |
| dat2$distprob<-dat$att/585 | |
| shinyServer(function(input,output){ | |
| groupInput<-reactive(function(){ | |
| switch(input$length, | |
| "all" = "all", | |
| "under20" = "under20", | |
| "twenties" = "twenties", | |
| "thirties" = "thirties", | |
| "forties" = "forties", | |
| "over50" = "over50") | |
| }) | |
| trialInput<-reactive(function(){ | |
| prob<-dat$per[dat$dist==groupInput()] | |
| reps<-input$obs | |
| trials<-rbinom(1000,reps,prob) | |
| }) | |
| trialInput2<-reactive(function(){ | |
| prob<-dat2$per[dat2$dist==groupInput()] | |
| reps<-input$obs | |
| trials<-rbinom(1000,reps,prob) | |
| }) | |
| output$simkicks<-reactivePlot(function(){ | |
| trials<-trialInput() | |
| reps<-input$obs | |
| p<-qplot(trials,binwidth=1)+theme_dpi()+xlim(c((input$obs*.85)-30,input$obs+10)) | |
| print(p) | |
| }) | |
| output$simkicks2<-reactivePlot(function(){ | |
| trials<-trialInput2() | |
| reps<-input$obs | |
| p<-qplot(trials,binwidth=1)+theme_dpi()+xlim(c((input$obs*.85)-30,input$obs+10)) | |
| print(p) | |
| }) | |
| output$summary <- reactiveTable(function() { | |
| dat | |
| }) | |
| output$summary2 <- reactiveTable(function() { | |
| dat2 | |
| }) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| library(ggplot2) | |
| library(eeptools) | |
| library(reshape) | |
| shinyUI(pageWithSidebar( | |
| # Title | |
| headerPanel("Field Goal Kicking"), | |
| sidebarPanel( | |
| sliderInput("obs","Number of tries:", | |
| min=20,max=200,value=100,step=20), | |
| selectInput("length", "Length in yards:", | |
| list("all" = "all", | |
| "0-19" = "under20", | |
| "20-29" = "twenties", | |
| "30-39" = "thirties", | |
| "40-49" = "forties", | |
| "50+" = "over50"))), | |
| mainPanel( | |
| plotOutput("simkicks"), | |
| plotOutput("simkicks2"), | |
| tableOutput("summary"), | |
| tableOutput("summary2") | |
| ) | |
| )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment