问题描述
我正在努力解决这个问题。我是来自 SPSS 背景的 Python 新手。基本上,一旦您完成了 Kruskal Wallis 检验并返回低 p 值,正确的程序是进行事后 Dunn 检验。我一直在努力计算数学,但我找到了这篇文章 (https://journals.sagepub.com/doi/pdf/10.1177/1536867X1501500117),我认为它已经说明了一切。
除了找出 P 值外,Python 似乎没有 Dunn 测试,但我希望有一个与您可以在 SPSS 中获得的成对比较测试类似的输出。这包括使用 Bonferroni 的 z-stat/检验统计量、标准差、标准差误差、p 值和调整后的 p 值。
现在我正在努力使测试统计正确,以便我可以完成其余的工作。我的数据是多个组,我已将其拆分为多个数据框。例如,我的数据如下所示:
df1 |因素 1 |因素 2 | | -------- | -------- | | 3.45 | 8.95 | | 5.69 | 2.35 | row_total=31 df2 |因素 1 |因素 2 | | -------- | -------- | | 5.45 | 7.95 | | 4.69 | 5.35 | row_total=75 等等等等
所以基本上我正在尝试测试 df1["Factor1"] 和 df2["Factor1]。 我目前拥有的是:
def dunn_test(df1,df2,colname):
##Equation is z= yi/oi
##Where yi is the mean rankings of the two groups
## oi is the standard deviation of yi
#Data Needed
x=df1[colname]
z=df2[colname]
grouped = pd.concat([x,z])
N =len(grouped)
#calculating the Mean Rank of the Two Groups
rank1= stats.rankdata(x)
rank2=stats.rankdata(z)
Wa = rank1.sum()/len(x)
Wb = rank2.sum()/len(z)
#yi
y= Wa-Wb
#standard deviation of yi
#tied Ranks
ranks= stats.rankdata(grouped)
tied=pd.DataFrame([Counter(ranks)]).T
tied= tied.reset_index()
tied = tied.rename(columns={"index":"ranks",0:'ties'})
count_ties = tied[tied.ties >=2].count()
#standard Deviaton formula
t= tied["ties"]
for tied in t:
e = t**3-t
e = [i for i in e if i != 0]
oi=((N*(N+1)/2) - sum(e)/12*(N-1))*(1/len(x) + 1/len(z))
zstat=y/oi
return zstat
它输出 0.0630。我遇到的问题是,当我通过 SPSS 运行相同的测试时,数字是 -51.422。我不确定我做对了,有正确的方程式或我打算做什么。
任何帮助将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)