1.0k views
4 votes
How many times can a simulation be repeated?

User Song Bee
by
3.9k points

1 Answer

6 votes

Answer:

Step-by-step explanation:

A general idea is that you should repeat the simulation until the results converge. An easy but illustrative example of this is that we want to see if the R function rbinom is accurate in simulating a coin toss with a given probability. We will simulate one coin toss 10000 times, and plot the percentage of heads against the number of coin tosses:

set.seed(1)

n <- 10000

result <- NULL

percent <- NULL

for (i in 1:n) {

result[i] <- rbinom(1,1,0.5)

percent[i] <- sum(result)/i

}

plot(seq(1:10000),percent, type="l")

abline(0.5, 0, lty=2)

User Ajay Makwana
by
4.0k points