[英]R: independence test: access the p-value
我读过有关使用$p.value
chisq.test
从chisq.test
和使用类似调用从二项式测试中获取p值的信息。 然而,这并不为工作independence_test
从coin
包。
> i1 = independence_test(Response ~ Type)
> i1
Asymptotic General Independence Test
data: Response by Type (A, B, C)
maxT = 0.95091, p-value = 0.9265
alternative hypothesis: two.sided
> i1$p.value
Error in i1$p.value : $ operator not defined for this S4 class
> names(i1)
NULL
也无法为其编制索引:
> i1[1]
Error in i1[1] : object of type 'S4' is not subsettable
> i1[[1]]
Error in i1[[1]] : this S4 class is not subsettable
如何访问p值?
似乎coin
提供了一种特殊的功能来从测试功能返回的对象中检索p值:
> result <- independence_test(c(1,2,3) ~ c(4,5,6))
> pvalue(result)
[1] 0.1572992
>
KA Buhr给出了正确的答案。 这是我正在写作的过程; 希望它会添加一些有用的信息:
当您打印i1
,它将打印一个p值。 因此,打印方法必须知道如何找到它。
这是一个S4函数,因此它使用show()
进行打印。 若要查看show(i1)
时发生的情况,请使用
trace(show, browser, signature = class(i1))
然后打印i1
,您将看到类似以下内容:
debug: {
distname <- switch(class(object@distribution), AsymptNullDistribution = "Asymptotic",
ApproxNullDistribution = "Approximative", ExactNullDistribution = "Exact")
RET <- list(statistic = setNames(object@statistic@teststatistic,
nm = "chi-squared"), p.value = object@distribution@pvalue(object@statistic@teststatistic),
data.name = varnames(object@statistic), method = paste(distname,
object@method))
if (length(object@distribution@parameters) == 1 && names(object@distribution@parameters) ==
"df")
RET$parameter <- setNames(object@distribution@parameters[[1]],
nm = "df")
if (length(object@estimates) > 0)
RET <- c(RET, object@estimates)
class(RET) <- "htest"
print(RET)
invisible(RET)
}
从中您可以看到获取p值的另一种方法,使用
object@distribution@pvalue(object@statistic@teststatistic)
(除了用i1
替换object
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.