統計学実践ワークブック 第6章の演習問題の Python 実装メモです。
問6.1
(1)
from scipy.stats import norm
A_hensa = 50 + ((85-65)/10)*10
B_hensa = 50 + ((60-65)/10)*10
print(A_hensa, B_hensa)
(2)
prob = 1 - (1 - norm.cdf(2)) - norm.cdf(-0.5)
print(prob*100)
(3)
q_length = (norm.ppf(0.75)*10+65) - (norm.ppf(0.25)*10+65)
print(q_length
(4)
from scipy import integrate
import numpy as np
def avg_of_more_avg(x):
return x*2*norm.pdf(x)
print(integrate.quad(avg_of_more_avg, 0, np.inf))
問6.2
(1)
COV = (150**2-80**2-90**2)/2
print(COV)
RHO = COV/(80*90)
print(RHO)
(2)
2変量正規分布の期待値の算出
$E[X_2|X_1=x_1] = \mu_2+\rho\sigma_2\frac{x_1-\mu_1}{\sigma_1}$
exp_2 = 250+0.555*90*(335-305)/80
print(exp_2)
問6.3 式導出がメインのため略
問6.4
(1)
a_hensa = (10*(67-65)/4) + 50
b_hensa = (10*(82-85)/3) + 50
print(a_hensa, b_hensa)
(2)
1 - 0.6*norm.cdf((60-65)/4)-0.4*norm.cdf((60-85)/3)