我正在尝试使用statsmodels
创建ANOVA并出现错误
variable value
0 x-y-20 -0.070000 1 x-y-20 0.090000 2 x-y-20 0.080000 3 xyy-20 -0.030000
代码
melt_t['variable'].replace({'x-y-20':'set-a','x-y-40':'set-b','x-y-60':'set-c'}, inplace=True)
results = ols('value ~ Q(variable)', data=melt_t).fit()
results.summary()
错误
PatsyError: Error evaluating factor: TypeError: 'Series' objects are mutable, thus they cannot be hashed
value ~ Q(variable)
^^^^^^^^^^^
任何建议将不胜感激!
谢谢
答案 0 :(得分:0)
我不确定您实际上 Q()
转换是什么,但是如果您确实需要/想要使用它,似乎您已经省略了{{1}周围的引号}:
variable
给予(摘录):
data = {'variable': {0: 'x-y-20', 1: 'x-y-40', 2: 'x-y-60', 3: 'x-y-20'},
'value': {0: -0.07, 1: 0.09, 2: 0.08, 3: -0.03}}
df = pd.DataFrame(data)
df['variable'].replace({'x-y-20':'set-a','x-y-40':'set-b','x-y-60':'set-c'}, inplace=True)
results = smf.ols('value ~ Q("variable")', data=df).fit()
results.summary()
(我使用 coef std err t P>|t| [0.025 0.975]
------------------------------------------------------------------------------------------
Intercept -0.0500 0.020 -2.500 0.242 -0.304 0.204
Q("variable")[T.set-b] 0.1400 0.035 4.041 0.154 -0.300 0.580
Q("variable")[T.set-c] 0.1300 0.035 3.753 0.166 -0.310 0.570
而不使用'value ~ variable'
来获得同一张表。)