Shlomi Avraham
Shlomi Avraham

Reputation: 1

how to pull value from wilcoxsign test in R

how can i pull the z ?

Asymptotic Wilcoxon-Pratt Signed-Rank Test

data:  y by x (pos, neg) 
     stratified by block
Z = 2.5113, p-value = 0.01203
alternative hypothesis: true mu is not equal to 0

Upvotes: 0

Views: 1341

Answers (3)

xan
xan

Reputation: 119

Just to add to @BenBolker response, as soon as you find out what you want to extract, after using the wilcoxsign_test() function and assuming the test results are stored in w, you can use:

# Z value
statistic(w)
# p value
pvalue(w)

Upvotes: 0

Ben Bolker
Ben Bolker

Reputation: 226182

The wilcoxsign_test() function is from the coin package (this is useful information for people answering).

Most R functions work the way that @ChrisRuehlemann suggests, but wilcoxsign_test() is an exception; it's stored as an S4 class, which makes things a little more obscure. You have to dig down with some combination of str() and slotNames(), and access individual elements via @

library(coin)
w <- wilcoxsign_test(mpg~vs,data=mtcars)
slotNames(w)
## [1] "parameter"    "nullvalue"    "distribution" "statistic"    
## "estimates"   
## [6] "method"       "call" 
w@statistic@teststatistic
## [1] 4.937168

Upvotes: 2

Chris Ruehlemann
Chris Ruehlemann

Reputation: 21400

The usual approach is to store the test as an object and extract the value of interest from there. For example, using the wilcox.test:

test <- wilcox.test(rnorm(100), dnorm(1000))

test

    Wilcoxon rank sum test with continuity correction

data:  rnorm(100) and dnorm(1000)
W = 54, p-value = 0.9044
alternative hypothesis: true location shift is not equal to 0

Just type the name of your test object, add $and run your cursor over it to see the options for what you can extract, for example:

test$statistic
 W 
54 

Upvotes: 0

Related Questions