[R] extracting results from wilcox_test (package::coin)
Achim Zeileis
Achim.Zeileis at uibk.ac.at
Wed Feb 24 21:38:46 CET 2010
On Wed, 24 Feb 2010, chipmaney wrote:
> Recently, I ran a series of Kruskal-Wallace tests [kruskal.test()] using by()
> to group by site Output is a list:
>
>> Herb.KW
> Herb.df$ID: 10-1
>
> Kruskal-Wallis rank sum test
>
> data: Indicator_Rating by Year
> Kruskal-Wallis chi-squared = 15.24, df = 7, p-value = 0.03302
>
> -----------------------------------------------------------------------------------------------------
> Herb.df$ID: 18-1
>
> Kruskal-Wallis rank sum test
>
> data: Indicator_Rating by Year
> Kruskal-Wallis chi-squared = 13.56, df = 7, p-value = 0.05963
>
> -----------------------------------------------------------------------------------------------------
> Herb.df$ID: 18-10
>
> Kruskal-Wallis rank sum test
>
> data: Indicator_Rating by Year
> Kruskal-Wallis chi-squared = 16.65, df = 5, p-value = 0.005213
>
> ------------------------------------------------------------------------------------------------------
>
> I used the following code to extract a vector of p.values for each list
> element:
>
>> sapply(Herb.KW, '[[', 'p.value')
> 10-1 18-1 18-10 18-11 18-12 18-13 18-2
> 18-3 18-4 18-5 18-6
> 3.302e-02 5.963e-02 5.213e-03 1.321e-09 4.483e-04 2.823e-02 2.893e-03
> 2.535e-02 5.701e-03
> 3-1 37-15 37-16 37-17 37-20 37-21 37-23
> 37-24 37-25 37-26
> 3.552e-18 9.189e-01 4.051e-03 2.122e-09 1.325e-01 2.128e-03 4.543e-01
> 9.940e-02 1.748e-02
>
> I then used wilcoxon_test for post-hoc analysis, which also returns a LIST
> with sites as elements. However, when I try to extract a pvalue from the
> list elements, I get the following message:
The test functions in "coin" do not return "htest" objects like
kruskal.test() but have their own S4 class. But there is an extractor
function pvalue() which can be easily employed:
R> wt <- wilcox_test(extra ~ group, data = sleep, distribution = "exact")
R> pvalue(wt)
[1] 0.06581654
Similarly, you can extract both the standardized statistic as well as the
underlying linear statistic (aka rank sum) via statistic():
R> statistic(wt)
1
-1.854118
R> statistic(wt, "linear")
1 80.5
Thus, your code line should just be
sapply(Herb.Wilcox, pvalue)
instead of
>> sapply(Herb.Wilcox, '[[', 'p.value')
For more implementation details, see:
http://www.jstatsoft.org/v28/i08/
(as pointed out in citation("coin")).
Best,
Z
> Error in FUN(X[[1L]], ...) : object of type 'S4' is not subsettable
>
> First, how do I determine what the "values" (e.g., statistic, pvalue) of the
> model output are, because the reference manual does not say (unlike for
> kruskal.test)...is the value object named "p.value" or "pvalue" or
> "p-value"??? Is the statistic named "statistic" or "Z.statistic" or
> "U.statistic"????
>
> Second, why isn't this object not subsettable even though class=list? how do
> i get around this problem and extract the statistic and p-value for each
> element in the list?
>
>
> --
> View this message in context: http://n4.nabble.com/extracting-results-from-wilcox-test-package-coin-tp1567956p1567956.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list