Team A:
Average runs scored per game: 5.588
Average runs against per game: 4.375
The standard deviation of runs scored per game: 3.001
Team B:
Average runs scored per game: 5.390
Average runs against per game: 4.732
The standard deviation of runs scored per game: 3.358
We would like you to write a script in R that uses the Monte-Carlo simulation to estimate the probability of each team winning the baseball game.
I tried the following way. Am I right?
set.seed(1)
xbar1<-sqrt(5.588*4.732)
xbar2<-sqrt(5.390*4.375)
sd1=3.001
sd2=3.358
sim=10000
A<-c()
for(i in 1:sim){
A[i]<- qnorm(runif(1), xbar1, sd1)
A
}
B<-c()
for(i in 1:sim){
B[i]<- qnorm(runif(1), xbar2, sd2)
B
}
average.score<-cbind(A, B)
prob.A<-mean(apply(average.score, 1, function(x) as.numeric(x[1]>x[2])))
prob.B<-mean(apply(average.score, 1, function(x) as.numeric(x[1]<x[2])))
cbind(prob.A, prob.B)