This is a simple post showing the basic knowledge of statistics, the consistency.

For Bernoulli distribution, $ Y \sim B(n,p) $, $ \hat{p}=Y/n $ is a consistent estimator of $ p $, because:

for any positive number $ \epsilon $.

Here is the simulation to show the estimator is consitent.

123456789

# set parametersn<-1000;p<-0.5;# n Bernoulli trailsobs<-rbinom(n,1,p)# estimate p on different number of trials.phat<-cumsum(obs)/cumsum(rep(1,n))# the convergence plotplot(phat, type="l", xlab="Trails")abline(h=p)

1234567891011121314

# then, 100 repetitions# set parametersn<-1000;p<-0.5;B<-100;# n*B Bernoulli trailsobs<-rbinom(n*B,1,p)# convert n*B observations to a n*B matrixobs_mat<-matrix(obs, nrow=n, ncol=B)# a function to estimate p on different number of trialsest_p<-function(x,n)cumsum(x)/cumsum(rep(1,n))# estimate p on different number of trials for each repetitionphat_mat<-apply(obs_mat,2, est_p, n=n)# the convergence plot with 100 repetitionsmatplot(phat_mat,type="l",lty=1,xlab="Trials",ylab="phat")