Reputation: 325
Suppose
data11 <- c(0.5388417, 0.7263466, 0.3612457, 0.2495263, 0.1780413)
data22 <- c(0.674262245, 0.659560230, 0.001548212, 0.501228052, 0.802885484)
d=as.data.frame(cbind(dat=c(data11,data22),level=c(rep(1,length(data11)),rep(2,length(data22)))))
then, I use the function oneway_test to get tje p-value
library(coin)
oneway_test(d$dat~as.factor(d$level))
I get:
Asymptotic Two-Sample Fisher-Pitman Permutation Test
data: d$dat by as.factor(d$level) (1, 2)
Z = -0.70257, p-value = 0.4823
alternative hypothesis: true mu is not equal to 0
But, how can I save the value of P-value? . Try to do this: d$p.value
. I do not get it
Thanks
Upvotes: 3
Views: 304
Reputation: 9705
Check the documentation of the coin package. You can use the pvalue function to return the pvalue:
results <- oneway_test(d$dat~as.factor(d$level))
pval <- pvalue(results)
Upvotes: 2
Reputation: 8377
I guess this is not straighforward because the printed result (p-value) is not contained in the returned object of the function oneway_test
but is printed as a side effect. You might use some regex as a workaround:
output <- oneway_test(d$dat~as.factor(d$level))
FindPValue = function(output){
temp <- capture.output(output)
return(as.numeric(gsub(".*p-value = ", "", temp[5])))
}
FindPValue(output)
#### [1] 0.4823
Thanks to Adam Quek for the advice with capture.output
Upvotes: 1