#===================================================== # Simulation of the probability distribution of batting # average. #===================================================== #----------------------------------------------------- # 1. Simulate n trials m times, with prob p of success # on each trial. Store counts of successes in hits. # Calculate proportion of successes and store in batave. #----------------------------------------------------- m=100 n=30 p=.26 hits=rbinom(m,n,p) batave=hits/n #----------------------------------------------------- # 2. Plot histogram of hits. #----------------------------------------------------- bounds=seq(-.5,n+.5,1) hist(hits,breaks=bounds,freq=FALSE,xlab="batting average", ylab="density",main="Distribution of Hits") #----------------------------------------------------- # 3. Plot histogram of batave. #----------------------------------------------------- windows() bounds=bounds/30 hist(batave,breaks=bounds,freq=FALSE,xlab="batting average", ylab="density",main="Distribution of Batting Average")