【发布时间】:2015-01-11 15:48:54
【问题描述】:
我正在对一些数据进行测试:
wilcox_test(y ~ x, distribution="exact", conf.int=TRUE)
# Exact Wilcoxon Mann-Whitney Rank Sum Test
#
# data: y by x (1, 2)
# Z = 1.8732, p-value = 0.06106
# alternative hypothesis: true mu is not equal to 0
# 95 percent confidence interval:
# 0 2
# sample estimates:
# difference in location
# 1
difference in location 下显示的数字是 Hodges-Lehmann 估计量。我想将它分配给一个变量以进行进一步计算。但我不知道:
如何获取“位置差异”的值?
我查看了str(wilcox_test(y ~ x, distribution="exact", conf.int=TRUE)),这给了我:
Formal class 'ScalarIndependenceTestConfint' [package "coin"] with 7 slots
..@ confint :function (level)
..@ conf.level : num 0.95
..@ nullvalue : num 0
..@ distribution:Formal class 'ExactNullDistribution' [package "coin"] with 7 slots
.. .. ..@ q :function (p)
.. .. ..@ d :function (x)
.. .. ..@ support :function ()
.. .. ..@ parameters: list()
.. .. ..@ pvalue :function (q)
.. .. ..@ p :function (q)
.. .. ..@ name : chr "exact distribution (via Streitberg-Roehmel algorithm)"
..@ statistic :Formal class 'ScalarIndependenceTestStatistic' [package "coin"] with 14 slots
.. .. ..@ alternative : chr "two.sided"
.. .. ..@ teststatistic : Named num 1.87
.. .. .. ..- attr(*, "names")= chr "1"
.. .. ..@ standardizedlinearstatistic: Named num 1.87
.. .. .. ..- attr(*, "names")= chr "1"
.. .. ..@ linearstatistic : num 4246
.. .. ..@ expectation : Named num 3875
.. .. .. ..- attr(*, "names")= chr "1"
.. .. ..@ covariance :Formal class 'Variance' [package "coin"] with 1 slot
.. .. .. .. ..@ variance: Named num 39334
.. .. .. .. .. ..- attr(*, "names")= chr "1"
.. .. ..@ xtrans : num [1:124, 1] 1 1 1 1 1 1 1 1 1 1 ...
.. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. ..$ : chr [1:124] "1" "2" "3" "4" ...
.. .. .. .. ..$ : chr "1"
.. .. .. ..- attr(*, "assign")= int 1
.. .. ..@ ytrans : num [1:124, 1] 114.5 93.5 9 50 114.5 ...
.. .. .. ..- attr(*, "assign")= int 1
.. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. ..$ : NULL
.. .. .. .. ..$ : chr ""
.. .. ..@ xtrafo :function (data, numeric_trafo = id_trafo, factor_trafo = f_trafo, ordered_trafo = of_trafo,
surv_trafo = logrank_trafo, var_trafo = NULL, block = NULL)
.. .. ..@ ytrafo :function (data)
.. .. ..@ x :'data.frame': 124 obs. of 1 variable:
.. .. .. ..$ x: Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
.. .. ..@ y :'data.frame': 124 obs. of 1 variable:
.. .. .. ..$ y: num [1:124] 7 5 0 2 7 1 0 9 1 7 ...
.. .. ..@ block : Factor w/ 1 level "0": 1 1 1 1 1 1 1 1 1 1 ...
.. .. ..@ weights : num [1:124] 1 1 1 1 1 1 1 1 1 1 ...
..@ estimates : list()
..@ method : chr "Wilcoxon Mann-Whitney Rank Sum Test"
但wilcox_test(...)@estimates 只返回:
list()
显示为空。
那么结果中difference in location 下列出的1 存储在哪里???
补充说明:
这行得通:
hle <- wilcox.test(x, y, paired = TRUE, correct = FALSE, conf.int = TRUE)$estimate
但这是一个不同的测试,不适合我的数据。
【问题讨论】:
-
试试
fit <- wilcox_test(y ~ x, distribution="exact", conf.int=TRUE); as.numeric(confint(fit)$estimate) -
@DavidArenburg 不错!这样可行!!!谢谢:-)