问题
Probably a naive question:
>library("coin")
> b <-independence_test(c(23,56,18) ~ c(1,3,2),teststat = "quad")
> b
Asymptotic General Independence Test
data: c(23, 56, 18) by c(1, 3, 2)
chi-squared = 1.2772, df = 1, p-value = 0.2584
I tried to find a place to extract this pValue (0.2584) but failed. Please help. Thanks in advance.
回答1:
It was hard to guess but I always look on the S4 class structure with str
function and then I wound out that there is test statictic and pvalue
function available in the object. I was looking for print
function for this object as
calling b
is equivalent to call print(b)
but I couldn't find
class(b)
coin:::print.QuadTypeIndependenceTest
By the way the final answer is
b <-independence_test(c(23,56,18) ~ c(1,3,2),teststat = "quad")
b
str(b)
b@distribution@pvalue(b@statistic@teststatistic)
Also it might help to read the vignette first https://cran.r-project.org/web/packages/coin/vignettes/coin_implementation.pdf
来源:https://stackoverflow.com/questions/32639460/how-to-extract-value-from-one-s4-class