One-sample Median Test using R


Still the same variable hwy and testing whether the median significantly differs from 25.  The code is pretty simple.

Sign test first (you need to install BSDA package to run the sign test):

> library(BSDA)
> SIGN.test(mpg$hwy, md = 25)
One-sample Sign-Test

data: mpg$hwy
s = 101, p-value = 0.2796
alternative hypothesis: true median is not equal to 25
95 percent confidence interval:
 23 25
sample estimates:
median of x 

Lower Achieved CI 0.9422 23 25
Interpolated CI 0.9500 23 25
Upper Achieved CI 0.9575 23 25


Then Wilcoxon signed rank test:

> wilcox.test(mpg$hwy, mu=25)
Wilcoxon singed rank test with continuity correction

data: mpg$hwy
V = 8223.5, p-value = 4.535e-05
alternative hypothesis: true location is not equal to 25



See Also:

Do the same test in SAS







Leave a Reply

Your email address will not be published. Required fields are marked *