Scipy Stats ttest_1samp 用于比较之前的性能和样本的假设测试。

问题描述 投票:1回答:1

我正在努力解决的问题

我有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日 我想问 "一月份的结果和过去11个月的结果是否有统计学上的不同?"

       Month  Branded  Non-Branded  Shopping  Grand Total
11  1/1/2016     1064          408       106         1578

我遇到了一个博客...

我遇到了 iaingallagher的博客。我将在此转载(以防博客宕机)。

1个样本的T检验

当我们想将样本平均值与人口平均值(我们已经知道)进行比较时,就会用到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 列数据。

Will scipy.stats.ttest_1samp([161,197,190,154,179,170,183,172,176,199,156], 106) 产生一个有效的结果,即使我的样本(第一个参数)是一个以前的结果列表,而且我把它与一个 popmean 那不是人口平均值,而是一个样本。

如果这不是正确的统计函数,请问有什么建议,这种假设检验的情况该怎么用?

python scipy statistics
1个回答
0
投票

如果您只对 "Shopping" 列,尝试创建一个.xlsx或.csv文件,其中只包含来自于 "Shopping"列。

这样你就可以导入这些数据,并利用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)
© www.soinside.com 2019 - 2024. All rights reserved.