I need this coded in R:
I have a program that simulates a fair dice. The program rolls a fair coin 100 times and counts the number of 1's. The simulation is repeated 10^5 times and stored the outcomes in x and a histogram is plotted.
I need to now draw a bell curve showing normal/gaussian distribution over the histogram.
Code I have:
dice <- function(n) { sample(c(1:6),n,replace = TRUE) } x<-dice(100) x<-numeric(10^5) for(n in 1:10^5){ x[n]<-sum(dice(100)==1) } hist(x, main="100 Fair Rolls", xlab="Rolls", ylab="Probability", xlim=c(0,30), breaks=-1:1000+1, prob=TRUE)
Get Answers For Free
Most questions answered within 1 hours.