_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › Python-T-test

Contents

1 one-sample
2 two-sample
3 paired two-sample


1 one-sample #

覈(蠏)襯 螻 蟆曙 sample 蠏螻 覈(蠏) 螳讌/るジ讌襯 蟆
  • 蠏覓願: 覈 螳.
  • 襴所: 覈 るゴ.
import numpy as np
import scipy as sp

#random number
N = 100
mu = 100
sd = 10
np.random.seed(0)
x = np.random.normal(mu, sd, N)

#histogram
import seaborn as sns
sns.distplot(x, kde=False, fit=sp.stats.norm)
plt.show()

#t-test: 1-sample
sp.stats.ttest_1samp(x, popmean=100) #覈 蠏 100企朱 蟆 螻  蟆曙

蟆郁骸
t_test_1_sample.png

2 two-sample #

sample 覿一 螳 蟆曙
#two-sample t-test: 覿一 螳 蟆曙
import numpy as np
import scipy as sp

np.random.seed(0)
x1 = np.random.normal(100, 10, 100)
x2 = np.random.normal(97, 10, 100)

sns.distplot(x1, kde=False, fit=sp.stats.norm)
sns.distplot(x2, kde=False, fit=sp.stats.norm)
plt.show()

sp.stats.ttest_ind(x1, x2, equal_var=True)

蟆郁骸
t_test_two_sample_01.png

sample 覿一 るジ 蟆曙
#two-sample t-test: 覿一 るジ 蟆曙
import numpy as np
import scipy as sp

np.random.seed(0)
x1 = np.random.normal(100, 10, 100)
x2 = np.random.normal(97, 5, 100)

sns.distplot(x1, kde=False, fit=sp.stats.norm)
sns.distplot(x2, kde=False, fit=sp.stats.norm)
plt.show()

sp.stats.ttest_ind(x1, x2, equal_var=False)

蟆郁骸
t_test_two_sample_01.png

3 paired two-sample #

#two-sample t-test: 覲
import numpy as np
import scipy as sp

np.random.seed(0)
x1 = np.random.normal(100, 10, 100)
x2 = np.random.normal(97, 10, 100)

sns.distplot(x1, kde=False, fit=sp.stats.norm)
sns.distplot(x2, kde=False, fit=sp.stats.norm)
plt.show()

sp.stats.ttest_rel(x1, x2)

蟆郁骸
t_test_two_sample_01.png
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:52

襭朱 螳 讌ъ襷 襭螳 讌覃 蠏 譴 螳 れ 襴 .