Based upon his season play, you estimate that if he comes to bat four times in a game the number of hits he will get has a distribution pX =
0 | 1 | 2 | 3 | 4 |
---|---|---|---|---|
.4 | .2 | .2 | .1 | .1 |
Assume that the player comes to bat four times in each game of the series.
Let X denote the number of hits that he gets in a series. Using the program NFoldConvolution, find the distribution of X for each of the possible series lengths: four-game, five-game, six-game, seven-game.
The convolve function in r will be useful in calculating the distribution throughout the series. We need to set type to open for a linear convolution of different lengths.
p_x <- c(0.4,0.2,0.2,0.1,0.1)
p_2 <- convolve(p_x,p_x, type = "open")
p_3 <- convolve(p_2, p_x, type = "open")
p_4 <- convolve(p_3, p_x, type = "open")
p4_mt <- t(matrix(c(c(0:16), p_4), ncol = 2))
p4_mt
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## [1,] 0e+00 1.0000 2.0000 3.0000 4.0000 5.0000 6.000 7.0000 8.0000 9.0000
## [2,] 4e-04 0.0014 0.0044 0.0101 0.0228 0.0398 0.066 0.0929 0.1252 0.1378
## [,11] [,12] [,13] [,14] [,15] [,16] [,17]
## [1,] 10.0000 11.0000 12.0000 13.0000 14.0000 15.000 16.0000
## [2,] 0.1452 0.1276 0.1056 0.0616 0.0368 0.016 0.0064
barplot(p4_mt[2,], names.arg = p4_mt[1,])
p_5 <- convolve(p_4, p_x, type = "open")
p5_mt <- t(matrix(c(c(0:20), p_5), ncol = 2))
p5_mt
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
## [1,] 0e+00 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000
## [2,] 4e-05 0.00018 0.00066 0.00181 0.00461 0.00972 0.01892 0.03245 0.05209
## [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17]
## [1,] 9.000 10.00000 11.00000 12.00 13.0000 14.00000 15.00000 16.00000
## [2,] 0.074 0.09832 0.11704 0.13 0.1264 0.11456 0.08976 0.06416
## [,18] [,19] [,20] [,21]
## [1,] 17.00000 18.0000 19.00000 20.00000
## [2,] 0.03584 0.0192 0.00768 0.00256
barplot(p5_mt[2,], names.arg = p5_mt[1,])
p_6 <- convolve(p_5, p_x, type = "open")
p6_mt <- t(matrix(c(c(0:24), p_6), ncol = 2))
p6_mt
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,] 0e+00 1.0e+00 2.0e+00 3.000000 4.000000 5.000000 6.000000 7.000000
## [2,] 4e-06 2.2e-05 9.2e-05 0.000291 0.000826 0.001999 0.004412 0.008727
## [,9] [,10] [,11] [,12] [,13] [,14] [,15]
## [1,] 8.000000 9.000000 10.000000 11.000000 12.000000 13.000000 14.000000
## [2,] 0.016026 0.026771 0.041708 0.059734 0.080004 0.098312 0.112832
## [,16] [,17] [,18] [,19] [,20] [,21] [,22]
## [1,] 15.000000 16.000000 17.000000 18.000000 19.000000 20.000000 21.000000
## [2,] 0.118528 0.115584 0.101424 0.082112 0.058592 0.037696 0.019968
## [,23] [,24] [,25]
## [1,] 22.000000 23.000000 24.000000
## [2,] 0.009728 0.003584 0.001024
barplot(p6_mt[2,], names.arg = p6_mt[1,])
p_7 <- convolve(p_6, p_x, type = "open")
p7_mt <- t(matrix(c(c(0:28), p_7), ncol = 2))
p7_mt
## [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## [1,] 0e+00 1.0e+00 2.00e+00 3.00e+00 4.0000000 5.0000000 6.0000000
## [2,] 4e-07 2.6e-06 1.22e-05 4.35e-05 0.0001361 0.0003679 0.0009013
## [,8] [,9] [,10] [,11] [,12] [,13]
## [1,] 7.0000000 8.0000000 9.0000000 10.0000000 11.0000000 12.00000
## [2,] 0.0019953 0.0040879 0.0077071 0.0135633 0.0221944 0.03408
## [,14] [,15] [,16] [,17] [,18] [,19]
## [1,] 13.0000000 14.0000000 15.0000000 16.0000000 17.0000000 18.0000000
## [2,] 0.0488284 0.0657452 0.0826928 0.0976416 0.1072976 0.1103088
## [,20] [,21] [,22] [,23] [,24] [,25]
## [1,] 19.0000000 20.0000000 21.0000000 22.000000 23.0000000 24.0000000
## [2,] 0.1048832 0.0925696 0.0744768 0.055072 0.0363008 0.0214784
## [,26] [,27] [,28] [,29]
## [1,] 25.000000 26.0000000 27.0000000 2.800e+01
## [2,] 0.010752 0.0048128 0.0016384 4.096e-04
barplot(p7_mt[2,], names.arg = p7_mt[1,])
Using one of the distribution found in part (a), find the probability that his batting average exceeds .400 in a four-game series. (The batting average is the number of hits divided by the number of times at bat.)
There are 20 at-bats for a 5 game series. He would need 8 or better hits to exceed a batting average of 0.400 for the series. We can simply sum the P_5 series above from 8 to 20 to get the odds of this batting average:
ba <- sum(p_5[9:21])
ba
## [1] 0.93161
This batter is very impressive to have a 93% probability to exceed 0.400.
Given the distribution pX , what is his long-term batting average?
To get this we simply take the expected value of \(p_x\), since \(p_x\) gives the probability for each number of hits in a 4 at-bat sequence.
season_ba <- function(p){
for(i in 1:length(p)){
E = (i-1)*p[i]
}
return(E)
}
season_ba(p_x)
## [1] 0.4