Last active
June 15, 2017 07:49
-
-
Save lapis-zero09/c8b57e0b5a7031eba2d6bfe9fb89124c to your computer and use it in GitHub Desktop.
サンプルサイズの異なるt検定[python]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.stats import ttest_ind_from_stats | |
from scipy.special import stdtr | |
abar = a.mean() | |
avar = a.var(ddof=1) | |
na = a.size | |
adof = na - 1 | |
bbar = b.mean() | |
bvar = b.var(ddof=1) | |
nb = b.size | |
bdof = nb - 1 | |
# Use scipy.stats.ttest_ind_from_stats. | |
t2, p2 = ttest_ind_from_stats(abar, np.sqrt(avar), na, | |
bbar, np.sqrt(bvar), nb, | |
equal_var=False) | |
print("ttest_ind_from_stats: t = %g p = %g" % (t2, p2)) | |
# Use formula | |
tf = (abar - bbar) / np.sqrt(avar/na + bvar/nb) | |
dof = (avar/na + bvar/nb)**2 / (avar**2/(na**2*adof) + bvar**2/(nb**2*bdof)) | |
pf = 2*stdtr(dof, -np.abs(tf)) | |
print("formula: t = %g p = %g" % (tf, pf)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment