STATA
Write code to simulate 5000 of these experiments (each with n = 50 flips of the biased coin, taking p = 0.3). Calculate your estimate of p for each repetition and calculate your estimate of the variance of your estimate for each repetition. Compare the average of your 5000 variance estimates to the empirical variance of the 5000 estimates of p.
solution:
R code:
x=matrix(0,nrow=5000,ncol=50)
p_hat=1:5000
var_hat=1:5000
for(i in 1:5000)
{
for(j in 1:50)
{
x[i,j]=rbinom(1,1,0.3)
}
p_hat[i]=mean(x[i,])
var_hat[i]=var(x[i,])
}
mean(var_hat) # average of 5000 variance estimates
var(p_hat) # empirical variance of 5000 estimates of p
Out put:
mean(var_hat)
[1] 0.210412
> var(p_hat)
[1] 0.004267701
Here we observe that average of 5000 variance estimates>empirical variance of 5000 estimates of p.
please give me thumb up
Get Answers For Free
Most questions answered within 1 hours.