Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manipulating the value of p-value of output in R

Tags:

r

p-value

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

like image 625
albert Avatar asked Dec 05 '25 09:12

albert


2 Answers

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)
like image 58
thc Avatar answered Dec 07 '25 16:12

thc


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

like image 44
agenis Avatar answered Dec 07 '25 15:12

agenis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!