我正在尝试解决
的问题我有 11 个月的绩效数据:
Month Branded Non-Branded Shopping Grand Total
0 2/1/2015 1330 334 161 1825
1 3/1/2015 1344 293 197 1834
2 4/1/2015 899 181 190 1270
3 5/1/2015 939 208 154 1301
4 6/1/2015 1119 238 179 1536
5 7/1/2015 859 238 170 1267
6 8/1/2015 996 340 183 1519
7 9/1/2015 1138 381 172 1691
8 10/1/2015 1093 395 176 1664
9 11/1/2015 1491 426 199 2116
10 12/1/2015 1539 530 156 2225
假设现在是 2016 年 2 月 1 日,我问"1 月份的结果与过去 11 个月的统计结果不同吗?
Month Branded Non-Branded Shopping Grand Total
11 1/1/2016 1064 408 106 1578
我遇到了一个博客...
我偶然发现了iaingallagher的博客。我将在这里复制(以防博客关闭)。
1 样本 t 检验
当我们想要将样本均值与 人口平均值(我们已经知道)。普通的英国男人是 身高175.3厘米。一项调查记录了10名英国男性的身高,我们想知道样本的平均值是否与 人口平均值。
# 1-sample t-test
from scipy import stats
one_sample_data = [177.3, 182.7, 169.6, 176.3, 180.3, 179.4, 178.5, 177.2, 181.8, 176.5]
one_sample = stats.ttest_1samp(one_sample_data, 175.3)
print "The t-statistic is %.3f and the p-value is %.3f." % one_sample
结果:
The t-statistic is 2.296 and the p-value is 0.047.
最后,对于我的问题...
在iaingallagher的例子中,他知道总体平均值,并正在比较样本(one_sample_data
)。 在我的示例中,我想查看1/1/2016
是否与前 11 个月在统计上有所不同。 所以就我而言,前 11 个月是一个数组(而不是单个总体平均值),我的样本是一个数据点(而不是数组)......所以这有点倒退。
问题
如果我专注于Shopping
列数据:
即使我的样本(第一个参数)是以前结果的列表,并且我将其与不是总体平均值而是一个样本的popmean
进行比较,scipy.stats.
ttest_1samp ([161,197,190,154,179,170,183,172,176,199,156], 106)
会产生有效的结果。
如果这不是正确的统计函数,关于在此假设检验情况下使用什么有什么建议吗?
如果您只对"Shopping"
列感兴趣,请尝试创建一个仅包含"Shopping"
列中的数据的.xlsx或.csv文件。
通过这种方式,您可以导入此数据并利用 pandas 对每列单独执行相同的 T 检验。
import pandas as pd
from scipy import stats
data = pd.read_excel("datafile.xlxs")
one_sample_data = data["Shopping"]
one_sample = stats.ttest_1samp(one_sample_data, 175.3)