0

I am trying to calculate the mean and the variance from sample has generated from Binomial distribution .with p=0.1, m=number of trials is 100, n =sample size is 100 and N=nc 10^5.My equation is why the mean and variance sometimes are equal . M=V. about 10% from the data. here is my code

nc=10^5
m=100
n=100
p=0.1
for(k in 1:nc){
  b[k,]=rbinom(n,m,p) 
  M=mean(b[k,])
  V=var(b[k,])
  if( M==V){ 
    print(M)
  }
}
Henry
  • 157,058
salma
  • 1
  • Welcome to MSE. It will be more likely that you will get an answer if you show us that you made an effort. – José Carlos Santos Mar 14 '18 at 18:40
  • Is this a math question or a programming question? – saulspatz Mar 14 '18 at 18:41
  • I am thinking that is because of the p is a very small . when I chaged the to p=0.3 insteand of 0.1. I did not get the M=V. which are the mean and variance. – salma Mar 14 '18 at 18:43
  • If you just had three values, they might for example be $12, 6, 9$. These have mean $9$ and sample ($\frac{1}{n-1}$) variance $9$ and those two values are equal. These things sometimes happen by chance. The population mean is $np$ and the population variance $np(1-p)$, which will anyway be close for small $p$ – Henry Mar 14 '18 at 18:44
  • p=0.1

    for(k in 1:nc){

      b[k,]=rbinom(n,m,p) 
       M=mean(b[k,])
     V=var(b[k,])
       if( M==V){           print(M)
        }
    

    } [1] 10.01 [1] 9.76 [1] 9.76 [1] 9.76 [1] 10.25 [1] 10.01 [1] 10.25 [1] 10.01 [1] 10 [1] 10 [1] 10 [1] 9.76 [1] 10 [1] 10 [1] 9.76 [1] 10.01 [1] 10 [1] 9.76

    – salma Mar 14 '18 at 18:47
  • Thank you all for your help. dear Henry, the M and V are not calculated by the formal of binomial distribution .M is a sample mean (the fist moment ) and V is sample varince too. – salma Mar 14 '18 at 18:49

0 Answers0