How to extract value from one S4 class

筅森魡賤 提交于 2019-12-11 04:27:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!