n=6
p=0.2,0.6,0.8为p的数值
q(p)=0.1,0.7,0.2为p的概率
当p固定时,对二项分布X:
E(X | p) = np
E(X^2 | p) = Var(X^2 | p) + (E(X | p))^2 = np(1-p) + (np)^2 = np(1-p+np)
所以:
E(X) = E(E(X | p))
= Σ_{p} (np)*q(p)
= n Σ_{p} p*q(p)
= 6(0.2*0.1 + 0.6*0.7 + 0.8*0.2)
= 3.6
E(X^2) = E(E(X^2 | p))
= Σ_{p} (np(1-p+np))*q(p)
= n Σ_{p} p(1-p+np)*q(p)
= 6(0.2*(1-0.2+6*0.2)*0.1 + 0.6*(1-0.6+6*0.6)*0.7 + 0.8*(1-0.8+6*0.8)*0.2)
= 15.12
所以:
Var(X) = E(X^2) - (E(X))^2 = 15.12 - 3.6^2 = 2.16
协方差:
因为p增大时,E(X)也增大;p减小时,E(X)也减小,所以协方差是正数.
如果你不放心,也可以算出协方差:
Cov(X,p) = E(Xp) - E(X) E(p)
其中:E(Xp) = E(Xp | p) = Σ_{p} (E(X | p)*p)*q(p) = Σ_{p} (np^2)*q(p)
所以:
Cov(X,p) = Σ_{p} (np^2)*q(p) - (Σ_{p} (np)*q(p)) * (Σ_{p} p*q(p))
= n (Σ_{p} (p^2)*q(p) - (Σ_{p} p*q(p)) * (Σ_{p} p*q(p)))
= n Var(p)
> 0
或者直接算出协方差的值:
E(Xp) = 6(0.2^2*0.1 + 0.6^2*0.7 + 0.8^2*0.2) = 2.304
E(p) = 0.2*0.1 + 0.6*0.7 + 0.8*0.2 = 0.6
所以:Cov(X,p) = 2.304 - 3.6*0.6 = 0.144 > 0