Where does the idea of simulation come from?

48 Views Asked by At

Suppose we want to simulate 3 tosses of a fair coin to find $P(X=1)$.

What my teacher has done in R is this,

  1. sample 3 tosses.
  2. replicate (1) $n$ times.
  3. count the number of heads $n_H$ in each of $n$ tosses. The result would be a list.
  4. count how many times 1 appear in the list.
  5. divide it by $n$.

My question is, where did he find this technique?


If you are interested, the following is the R source code sample:

n_toss = 3; # Number of Tosses  
n_trial = 10000; # Number of Trials  
mySamples <- replicate(n_trial, {mySamples<- sample(c(1,0), n_toss, replace = T, prob = c(0.5,0.5))})      
headCountList <- colSums(mySamples); # this indicates the number of heads  
     #         the headCount is 1, that is X==1.   
probOfCoinToss <- length(which(headCountList == 1))/n_trial;  
probOfCoinToss  
[1] 0.3767  
 EX<- sum(headCountList)/n_trial  
 EX  
[1] 1.5024  
1

There are 1 best solutions below

0
On

This is formally known as Monte Carlo sampling