我不是R.Anyway的高级用户我只想对两个数据集进行Wilcox测试:
library(coin)
GroupA = c(2,4,3,1,2,3,3,2,3,1)
GroupB = c(3,5,4,2,4,3,5,5,3,2)
g = factor(c(rep("GroupA", length(GroupA)), rep("GroupB", length(GroupB))))
v = c(GroupA, GroupB)
ss = wilcox_test(v ~ g, distribution="exact")
我想要的是获得Z值并计算效果大小。 ss是一个S4对象,当我打印它时,我看到它报告了一个Z值,但我在ss @statistic中找不到它。 唯一具有我期望值的插槽是“测试统计”,但即使这是我测试时的测试的z值:
slot(ss, 'teststatistic')
我收到错误:
no slot of name "teststatistic" for this object of class "ScalarIndependenceTest"
任何人都可以给我一个提示吗?谢谢
答案 0 :(得分:1)
S4类的print
等效项是show
方法,可以使用getMethod
进行检查。在这种情况下,
ss
#
# Exact Wilcoxon-Mann-Whitney Test
#
#data: v by g (GroupA, GroupB)
#Z = -2.1095, p-value = 0.0385
#alternative hypothesis: true mu is not equal to 0
getMethod("show","ScalarIndependenceTest")
#Method Definition:
#
# function (object)
# {
# distname <- switch(class(object@distribution), AsymptNullDistribution = "Asymptotic",
# ApproxNullDistribution = "Approximative", ExactNullDistribution = "Exact")
# RET <- list(statistic = setNames(object@statistic@teststatistic,
# nm = "Z"), p.value = object@distribution@pvalue(object@statistic@teststatistic),
# alternative = object@statistic@alternative, data.name = varnames(object@statistic),
# method = paste(distname, object@method))
#...
#...
# }
ss@statistic@teststatistic
# GroupA
#-2.109531
ss@distribution@pvalue(ss@statistic@teststatistic)
#[1] 0.03850484