Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
98 lines (79 sloc) 7.1 KB
library(shiny)
shinyUI(fluidPage(
headerPanel(h5("Baseball game wins probability calculator by Mark Malter")),
sidebarPanel(
textInput('vis.score','visitors score :',value=0),
textInput('home.score','home score:',value=0),
textInput('inning','inning:',value=1),
sliderInput('success','Base running success rate:', min=0.00, max=1.00,value=c(0.70), step=0.01),
br(),
br(),
radioButtons('half.inning','top or bottom:',c('top','bottom'),inline=TRUE),
br(),
radioButtons('outs','outs',c('0','1','2'),inline=TRUE),
br(),
radioButtons('first','runner on first?',c('no','yes'),inline=TRUE),
br(),
radioButtons('second','runner on second?',c('no','yes'),inline=TRUE),
br(),
radioButtons('third','runner on third?',c('no','yes'),inline=TRUE),
br(),
radioButtons('double.steal','single or double steal?',c('single','double'),inline=TRUE)
),
mainPanel(
tabsetPanel(type="tab",
tabPanel('Probability of winning game',tableOutput('odds'),
HTML("<div>
<p><b>For optimal viewing, you might need to narrow your window.</b></p>
This calculator allows you to view the probability of each team winning the game under any circumstance. As the game progresses,
enter each team's score, inning (including top or bottom), number of outs, and whether or not the bases are occupied. The calculator
runs 15,000 simulated games by using the probability distribution of runs scored in the remainder of the current half inning according to the
bases/outs state, and by using the probability distribution of home/visitors runs scored in each succeeding half inning. Because the runs values
are randomly generated according to the probability distributions, the calculated values will slightly change each time it is run
under any same game situation.
<br></br>The probability distributions
were calculated according to actual run production by runs/outs state, as well as for complete half innings,
from actual MLB game data on every game played in the 2011-2014 seasons, as
downloaded from retrosheets.<br></br>
Check the 'Steal Attempt', 'Sacrifice Bunt Attempt', or 'Tag From Third Attempt' tabs to view the probabilities when those situations arise. You will be able to view the
probability of winning before the event, the probability of winning with both a successful and unsuccessful play, and the expected probability
of winning, given the user entered 'success rate'.<br></br>
Feel free to provide feedback to malter61@gmail.com <br></br>Mark
<br></br><br></br>check out my Baseball Stats runs created app at <a href= 'http://malter61.shinyapps.io/BaseballStats/'>Baseball Stats</a> </div>")),
tabPanel('Steal Attempt',tableOutput('steal'),
HTML("<div>As long as one of the following stolen base opportunities is possible: runner on first base or second base,
runners on first and second, or runners on first and third (to simplify matters, we assume a runner on third will never attempt to steal home),
this table shows the probabilities of winning the game based on no attempt (start state), a successful stolen base, an unsuccessful stolen base, and the
expected end state, according to the user entered 'success rate'.<br></br>
<b>Play with the 'baserunning success rate' to see how the 'expected end state' changes.</b><br></br>
With runners on first and second, the user has the option of checking either the 'single steal' or double steal' button.
It is assumed that in unsuccessful double steal situations, the lead runner is out at third and the trailing runner is safe at second.<br></br><br></br>
Feel free to provide feedback to malter61@gmail.com <br></br>Mark
<br></br><br></br>check out my Baseball Stats runs created app at <a href= 'http://malter61.shinyapps.io/BaseballStats/'>Baseball Stats</a> </div>")),
tabPanel('Sacrifice Bunt Attempt',tableOutput('sac'),
HTML("<div>As long as one of the following sacrifice bunt opportunities is possible: less than two outs and runner on first base or second base,
or runners on first and second, (to simplify matters, we assume there will be no sacrifice bunt attempts with a runner on third base),
this table shows the probabilities of winning the game based on no attempt (start state), a successful sacrifice bunt, an unsuccessful sacrifice bunt,
and the expected end state, according to the user entered 'success rate'.<br></br>
<b>Play with the 'baserunning success rate' to see how the 'expected end state' changes.</b><br></br>
It is assumed that with a successful sacrifice bunt, any baserunners advance one base and the batter is out at first;
while in unsuccessful bunt situations, the lead runner is out, any trailing runner advances one base, and the batter is safe at first.
<br></br><br></br>
Feel free to provide feedback to malter61@gmail.com <br></br>Mark
<br></br><br></br>check out my Baseball Stats runs created app at <a href= 'http://malter61.shinyapps.io/BaseballStats/'>Baseball Stats</a> </div>")),
tabPanel('Tag From Third Attempt',
HTML("<div><b>We are assuming a catch was just made by an outfielder, so a tag will take place only if there are one or two outs
and a runner on third base.</b></div>"),
tableOutput('tag'),
HTML("<div>As long as there is a runner on third base with one out or two outs (after a catch was just made),
this table shows the probabilities of winning the game based on no attempt (start state), a successful tag play with the runner scoring from third base,
an unsuccessful tag play with the runner being thrown out at the plate, and the expected end state, according to the user entered 'success rate'.
To simplify matters, we assume that any trailing baserunners will not attempt to advance on the throw home.<br></br>
<b>Play with the 'baserunning success rate' to see how the 'expected end state' changes. </b><p></p><p>The tag play should be attempted any time the expected end state
is larger than the start state, for the given 'baserunning success rate'. The threshold success rate can be taken as the minimum value where the end state
is greater than the start state. Notice how for any situation, the threshold is much lower when there are two outs than when there is one out.</p>
<p>Feel free to provide feedback to malter61@gmail.com <br></br>Mark</p>
<br></br><p>check out my Baseball Stats runs created app at <a href= 'http://malter61.shinyapps.io/BaseballStats/'>Baseball Stats</a> </div>"))
)
)
))