In [6]:
N = 10
theta_0 = 0.5
x = sp.stats.bernoulli(theta_0).rvs(N)
In [7]:
x
Out[7]:
In [8]:
n = np.count_nonzero(x)
In [9]:
n
Out[9]:
In [12]:
sp.stats.binom_test(n,N)
Out[12]:
In [30]:
rv = sp.stats.binom(N, theta_0)
In [37]:
rv.pmf(10)
Out[37]:
In [38]:
1 - rv.cdf(6)
Out[38]:
In [41]:
rv.sf(6)
Out[41]:
In [64]:
rv.sf(6) + rv.cdf(3)
Out[64]:
In [71]:
a = rv.pmf(0) +rv.pmf(1)+rv.pmf(2)+rv.pmf(3)
In [72]:
b = rv.pmf(7)+rv.pmf(8)+rv.pmf(9)+rv.pmf(10)
In [75]:
rv.cdf(3) + rv.sf(6)
Out[75]:
In [73]:
a + b
Out[73]:
In [81]:
N = 10
theta_0 = 0.1
rv = sp.stats.bernoulli(theta_0)
In [102]:
a = rv.rvs(10)
a
Out[102]:
In [97]:
In [100]:
rv1.pmf(2)
Out[100]:
In [101]:
Out[101]:
In [110]:
sp.stats.binom_test(1,N)
Out[110]:
In [120]:
N = 100
theta_0 = 0.35
x = sp.stats.bernoulli(theta_0).rvs(N)
In [121]:
x
Out[121]:
In [122]:
n = np.count_nonzero(x)
In [123]:
n
Out[123]:
In [125]:
sp.stats.binom_test(n, N)
Out[125]:
In [130]:
N = 60
K = 6
theta_0 = np.ones(K)/K
In [131]:
theta_0
Out[131]:
In [132]:
x = np.random.choice(K, N, p=theta_0)
In [133]:
x
Out[133]:
In [134]:
n = np.bincount(x, minlength = K)
In [135]:
n
Out[135]:
In [136]:
sp.stats.chisquare(n)
Out[136]:
In [137]:
# 확률이 fair 하지 않은 주사위를 던져보자
N = 100
K = 6
theta_0 = np.array([0.1, 0.1, 0.1, 0.1, 0.1, 0.5])
x = np.random.choice(K,N, p=theta_0)
In [138]:
n = n
Out[138]:
In [147]:
# 카이 제곱 분산 검정
N = 101
mu_0 = 0
sigma_0 = 1.1
np.random.seed(0)
x = sp.stats.norm(mu_0, sigma_0).rvs(N)
sns.distplot(x, kde=False, fit=sp.stats.norm)
plt.show()
x.std()
Out[147]:
In [145]:
def chi2var_test(x, sigma2=1):
v = x.var(ddof=1)
t = (len(x) - 1)*v/sigma2
return t, sp.stats.chi2(df=len(x)-1).sf(np.abs(t))
In [148]:
chi2var_test(x)
Out[148]:
In [ ]: