• Home
  • About R Trix
  • Teaching Resources
  • RTricks Library
  • Interactive Apps
  • Training Network
RTFR landingdist

R Code for Discrete Probability Example 7

> prob <- rep(0, 20)

> for (i in 1:20) {

> ntrial <- i * 10

> trial <- sample(1:6, size = ntrial, replace = T)

> prob[i] <- length(trial[trial == 4])/ntrial

> }

> plot((1:20) * 10, prob, type = "o", xlab = "Number of Trials",

> ylab = "Probabilities", main = "Simulation of Rolling a Four")

> abline(1/6, 0, col = "red")