使用 Spm1d 在 python 中嵌套方差分析.无法打印 f 统计量和 p 值 [英] Nested Anova in python with Spm1d. Can't print f statistics and p values
问题描述
我正在寻找一个简单的解决方案来在 python 中执行多因素方差分析.我所追求的是 2 因素嵌套方差分析,SPM1D python 模块是一种方法,但我遇到了问题.
但我似乎无法得到任何打印它的输出.
FFi.get_p_values
和
FFi.get_f_values
产生输出:
<绑定方法 SPMFiList.get_p_values SPM{F} 推理列表设计 : ANOVA2nestedn效果:2效果:一个 z=(1x101) 数组 df=(2, 6) h0reject=TrueB z=(1x101) 数组 df=(6, 36) h0reject=False
所以我不知道该怎么办.显然 FFi.plot 类可以访问 p_values(使用 plot_p_values)但 FFi.get_p_values 不能!!?有人可以帮忙吗?
干杯,K
获取 p 值的最简单方法是使用您提到的 get_p_values
方法,您只需要通过将 ()
添加到最后.
p = FFi.get_p_values()打印(页)
这产生:
([0.016584151119287904], [])
要查看 2+-way ANOVA 中每个效应的更多详细信息,包括 p 值,请使用 print
以及单独的 F 统计数据,如下所示:
print( FFi[0] )打印(FFi[1])
第一个打印语句将产生如下输出:
SPM{F} 推理字段SPM.effect : Main ASPM.z : (1x101) 原始测试统计字段SPM.df : (2, 6)SPM.fwhm : 11.79254SPM.resels : (1, 8.47993)推理:SPM.alpha : 0.050SPM.zstar : 24.30619SPM.h0reject : 真SPM.p_set:0.017SPM.p_cluster : (0.017)
您可以像这样检索集群的 p 值:
p = [F.p for F in FFi]
与调用 get_p_values
的结果相同.
请注意,在这种情况下,FFi[1]
没有 p 值,因为测试统计数据未能跨越 alpha
定义的阈值(请参阅主要 B" 上图中的面板).如果在这种情况下还需要报告 p 值,一种选择就是使用p > alpha".更精确的 p 值可通过参数获得,直到大约 p = 0.5,但使用参数方法时,比这更大的 p 值不是很准确,因此如果您需要所有情况下的 p 值,请考虑使用非参数版本:spm1d.stats.nonparam.anova2nested
.
I'm looking for a simple solution to perform multi-factor ANOVA analysis in python. A 2-factor nested ANOVA is what I'm after, and the SPM1D python module is one way to do that, however I am having an issue.
http://www.spm1d.org/doc/Stats1D/anova.html#two-way-nested-anova
for any of the nested approach examples, there is never any F-statistic or p_values printed, nor can I find any way to print them or send them to a variable.
To go through the motions of running one of their examples, where B is nested inside A, with Y observations:
import numpy as np
from matplotlib import pyplot
import spm1d
dataset = spm1d.data.uv1d.anova2nested.SPM1D_ANOVA2NESTED_3x3()
Y,A,B = dataset.get_data()
#(1) Conduct ANOVA:
alpha = 0.05
FF = spm1d.stats.anova2nested(Y, A, B, equal_var=True)
FFi = FF.inference(0.05)
print( FFi )
#(2) Plot results:
pyplot.close('all')
FFi.plot(plot_threshold_label=True, plot_p_values=True)
pyplot.show()
The only indication of statistical significance provided is whether the h0 hypothesis is rejected or not.
> print( FFi )
SPM{F} inference list
design : ANOVA2nested
nEffects : 2
Effects:
A z=(1x101) array df=(2, 6) h0reject=True
B z=(1x101) array df=(6, 36) h0reject=False
In reality, that should be enough. However, in science, scientists like to think of something as more or less significant, which is actually kind of crap... significance is binary. But that's how they think about it, so I have to play along in order to get work published.
The example code produces a matplotlib plot, and this DOES have the f statistic and p_values on it!
#(2) Plot results:
pyplot.close('all')
FFi.plot(plot_threshold_label=True, plot_p_values=True)
pyplot.show()
But I can't seem to get any output which prints it.
FFi.get_p_values
and
FFi.get_f_values
produce the output:
<bound method SPMFiList.get_p_values <kabammi edit -- or get_f_values> of SPM{F} inference list
design : ANOVA2nested
nEffects : 2
Effects:
A z=(1x101) array df=(2, 6) h0reject=True
B z=(1x101) array df=(6, 36) h0reject=False
So I don't know what to do. Clearly the FFi.plot class can access the p_values (with plot_p_values) but FFi.get_p_values cant!!? Can anyone lend a hand?
cheers, K
The easiest way to get the p values is to use the get_p_values
method that you mention, you just need to call the method by adding ()
to the end.
p = FFi.get_p_values()
print(p)
This yields:
([0.016584151119287904], [])
To see more detailed information for each effect in 2+-way ANOVA, including p values, use print
along with the individual F statistics like this:
print( FFi[0] )
print( FFi[1] )
The first print statement will produce output like this:
SPM{F} inference field
SPM.effect : Main A
SPM.z : (1x101) raw test stat field
SPM.df : (2, 6)
SPM.fwhm : 11.79254
SPM.resels : (1, 8.47993)
Inference:
SPM.alpha : 0.050
SPM.zstar : 24.30619
SPM.h0reject : True
SPM.p_set : 0.017
SPM.p_cluster : (0.017)
You can retrieve the clusters' p values like this:
p = [F.p for F in FFi]
which gives the same result as calling get_p_values
.
Note that there are no p values in this case for FFi[1]
because the test statistic fails to cross the alpha
-defined threshold (see the "Main B" panel in the figure above). If you need to report p values in this case as well, one option is simply to use "p > alpha". More precise p value are available parametrically up until about p = 0.5, but larger p values than that are not very accurate using parametric methods, so if you need p values for all cases consider using the nonparametric version: spm1d.stats.nonparam.anova2nested
.
这篇关于使用 Spm1d 在 python 中嵌套方差分析.无法打印 f 统计量和 p 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!