运行scipy.ttest_1samp进行t检验

时间:2019-02-09 10:06:59

标签: python-3.x statistics

我想使用python 3.7进行t检验。我有以下数据:

date,return
2014-11-30,0.011635519414351009
2014-12-31,0.021954092308170955
2015-01-31,0.04088726605224263
2015-02-28,-0.0025112428290965105
2015-03-31,0.01725861669076579
2015-04-30,0.04169672034614155
2015-05-31,0.033973104078552634
2015-06-30,0.011808567427224085
2015-07-31,-0.034296712711723694
2015-08-31,-0.018000336527001545

我创建了以下示例:

import pandas as pd
import numpy as np
import scipy.stats as stats

def analyze_returns(net_returns):
    """    
    Parameters
    ----------
    net_returns : Pandas Series
        A Pandas Series for each date

    Returns
    -------
    t_value
        t-statistic from t-test
    p_value
        Corresponding p-value
    """
    m = np.mean(net_returns)   
    # null_hypothesis = 0.0

    t_value, p_value = stats.ttest_1samp(net_returns, m) / 2

    return t_value, p_value

def test_run(filename='./data/net_returns.csv'):
    """Test run analyze_returns() with net strategy returns from a file."""
    net_returns = pd.Series.from_csv(filename, header=0)
    t, p = analyze_returns(net_returns)
    print("t-statistic: {:.3f}\np-value: {:.6f}".format(t, p))


if __name__ == '__main__':
    test_run()

运行stats.ttest_1samp(net_returns, m) / 2时,出现以下错误:

    <ipython-input-3-12a76e5e6042> in analyze_returns(net_returns)
     26     # null_hypothesis = 0.0
     27 
---> 28     t_value, p_value = stats.ttest_1samp(net_returns, m) / 2

任何暗示我做错了吗?

0 个答案:

没有答案
相关问题