weixin_37836199
头像不是本人
2017-04-05 01:53

在python进行方差分析时,残差的自由度总是为0????

  • python
  • 数据分析
  • numpy
 #coding:utf8
from scipy import stats
import pandas as pd
import numpy as np
from statsmodels.formula.api import ols
from statsmodels.stats.anova import anova_lm
from statsmodels.stats.multicomp import pairwise_tukeyhsd
import matplotlib.pyplot as plt


path = r"E:\python code\zuoye\2facter-avaon.csv"
#path = r"E:\python code\zuoye\ToothGrowth.csv"
df = pd.read_csv(path,header=None,names=['data','month','time'] ) 
formula = 'data~C(time) + C(month) + C(time):C(month)'
anova_results = anova_lm(ols(formula,df).fit())
print(anova_results)

运行结果

数据集为

 1,4574.82,Jan,8
2,32136.71,Jan,9
3,73890.49,Jan,10
4,61498.92,Jan,11
5,38142.71,Jan,12
6,45988.9,Jan,13
7,66276.1,Jan,14
8,82821.365,Jan,15
9,81560.06,Jan,16
10,78350.47,Jan,17
11,80930.74,Jan,18
12,95226.79,Jan,19
13,75982.9,Jan,20
14,14012.17,Jan,21
15,4574.82,Feb,8
16,32136.71,Feb,9
17,73890.49,Feb,10
18,61498.92,Feb,11
19,38142.71,Feb,12
20,45988.9,Feb,13
21,66276.1,Feb,14
22,82821.365,Feb,15
23,81560.06,Feb,16
24,78350.47,Feb,17
25,80930.74,Feb,18
26,95226.79,Feb,19
27,75982.9,Feb,20
28,14012.17,Feb,21

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答