Description Usage Arguments Details Value Note See Also Examples
In the one sample case, test if the median of the random variable is equal to 0. In the paired two sample case, test if the median of the difference between the two random variables is equal to 0.
1 | mediantest(x, y = NULL, alternative = "two.sided", paired = FALSE)
|
x, y |
two continuous variables. |
alternative |
indicates the alternative hypothesis and must be one of "two.sided", "greater" or "less". |
paired |
a logical value. If it equals TRUE, you must provide values for |
The null hypothesis for the one sample median test is: H0 Med(X)=0 where Med represents the median.
The alternative is specified by the alternative
argument: "greater
" means that Med(X)>0 and "less
"
means that Med(X)<0. The null hypothesis for the paired median test is: H0 Med(X-Y)=0. Both tests are asymptotically
calibrated in the sense that the rejection probability under the null hypothesis is asymptotically equal to the level of the test. The
test is based on the asymptotic law of the empirical median and uses a kernel estimator to estimate the density of X
(in the one sample case)
or of X-Y
in the two sample case at 0.
Returns the result of the test with its corresponding p-value and the value of the test statistic.
The paired median test can be implemented by providing the variables x
and y
or by just providing
one vector equal to the difference between x
and y
.
cortest
, indeptest
, vartest
, wilcoxtest
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #Simulations
n=100
M=1000 #number of replications
res1=res2=rep(NA,M)
testone=function(n){
D=rchisq(n,df=4)-qchisq(df=4, p=0.5)
list(test1=mediantest(D)$p.value,test2=binom.test(sum(D>0),n)$p.value)
} #test2 is the sign test.
for (i in 1:M)
{
result=testone(n)
res1[i]=result$test1
res2[i]=result$test2
}
mean(res1<0.05) #0.048
mean(res2<0.05) # 0.04
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.