Skip to content

❗ This is a read-only mirror of the CRAN R package repository. wilcoxmed — Computes Values for the 1-Sample Wilcoxon Sign Rank Test for Medians

cran/wilcoxmed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wilcoxmed

The Implementation of the 1-Sample Wilcoxon Signed Rank Hypothesis Test for medians - allows breaking of ties, computation of the Wilcoxon Test Statistic with normal approximations.

We refer to the Wilcoxon Sign Ranked hypothesis test for medians for the one-sample problem.

Given that X1, X2, …, Xn ∼ F. Assume that F is unknown except that it is continuous and symmetric. We wish to test H0 : m = m0 against H1 : m > m0 at the significance level α

Let Ri = (signed rank of Xi − m0) The test statistic is ∑Ri , or equivalently W = ∑Ri/2 + n(n + 1)/4

We reject H0 iff p-value = P(W ≥ wobs|H0) < α

For this problem, there could be ties in the data, however the algorithm is able to break the ties by assigning the average absolute rank to each tied value. The exact distribution of W is taken from Bickel and Doksum (1973).

The normal approximations to W can be found via the following theorem:

Theorem: If X1, X2, …, Xn ∼ F, F is continuous, then as n → ∞, we have:

W ∼ N(n(n + 1)/4n(n + 1)(2n + 1)/24)

Example

Given some data: X ∈ {3, 4, 7, 10, 12, 1, 9, 2, 15}: We wish to test H0 : m = 5 against H1 : m > 5 at the significance level α = 0.05 without using normal approximation:

vec = c(3, 4, 7, 10, 4, 12, 1, 9, 2, 15)

res = wilcoxmed::Wilcox.m.test(dat = vec, m_h0 = 5, alternative = 'greater',
                               normal_approx = F)
#> 
#>                      1-Sample Median Wilcoxon Sign-Rank Test 
#>  
#>                                     Ties Broken = 3 
#>  
#>            Null hypothesis H_0: m = 5      Alternative Hypothesis H_1: m > 5 
#>  
#>            Test Statistic W = 37      p-value =  0.1875      alpha = 0.05 
#>  
#>                          Test Result: Do not Reject H_0 
#> 

If we want to apply the normal approximation(Z-test), with the same hypotheses:

res = wilcoxmed::Wilcox.m.test(dat = vec, m_h0 = 5, alternative = 'greater',
                               normal_approx = T)
#> 
#>             1-Sample Median Wilcoxon Sign-Rank Test - Normal Approximation 
#>  
#>                                     Ties Broken = 3 
#>  
#>            Null hypothesis H_0: m = 5      Alternative Hypothesis H_1: m > 5 
#>  
#>            Test Statistic Z = 0.9683297      p-value =  0.1664399      alpha = 0.05 
#>  
#>                          Test Result: Do not Reject H_0 
#> 

To find the exact probabilities of the Wilcoxon sign distribution:

To find P(W ≤ 3) for n = 5:

wilcoxmed::W_stat(n=5, test_stat = 3, side = 'leq')
#> [1] 0.15625

About

❗ This is a read-only mirror of the CRAN R package repository. wilcoxmed — Computes Values for the 1-Sample Wilcoxon Sign Rank Test for Medians

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages