#======================================================= # R program to simulate observations from a binomial # probability distribution and plot a histogram. #======================================================= n=10 # Number of trials. p=.45 # Probability of success. num.reps=30 # Number of replications. x.vec=rbinom(num.reps,n,p) # Vector of binomial random variables. bounds=(0:(n+1))-.5 # Boundaries for the histogram rectangles # are -.5, .5, 1.5, 2.5, ... etc. hist(x.vec,breaks=bounds,freq=FALSE,xlab="number of successes", ylab="density",main="")