Wilcoxon signed-rank test

Introduction

Wilcoxon signed-rank test is a non-parametric test which is sometimes used instead of the paired Student’s t-test when assumptions regarding a normal distribution are not valid. It is a rank test, designed for analyzing repeated measures or paired observations by a paired comparison (a type of location test) to assess whether their population means differ. Whilst it does not ‘compare’ means or medians for a set of paired data, it ranks the results on A and ranks the results on B, then compares if Prob(A>B) > Prob(B>A).

Ties are when you have two observations with the same result. For example, in a 2-period cross-over study, you take the difference between result on Treatment A minus result on Treatment B and find that two or more subjects have the same difference.

Additionally, “0s” can cause some trouble as well. For example when the difference between result on Treatment A minus result on Treatment B equals 0.

Data

Analysis will be conducted on the example of anonymized data from 2-period, cross-over study comparing treatments A and B in patients with asthma and acute airway obstruction induced by repeated mannitol challenges.

Wilcoxon signed rank test was applied to analyse the time to return to baseline FEV1 post-mannitol challenge 2. Median difference, p value and 95% CI were provided using the Hodges-Lehmann estimate.

head(blood_p)
  patient  sex agegrp bp_before bp_after
1       1 Male  30-45   143.670  153.316
2       2 Male  30-45   163.082  170.576
3       3 Male  30-45   153.393  168.599
4       4 Male  30-45   153.082  142.358
5       5 Male  30-45   146.720  141.193
6       6 Male  30-45   150.668  147.204

Dataset without ties

Let’s consider a case where the dataset has no ties.

Available packages

In R Wilcoxon signed rank test can be performed using for example DOS (version 0.5.2) or stats (version 3.6.2) package.

stats

Function wilcox.test used for Wilcoxon Rank Sum and Signed Rank Tests will be applied. For more information about that function go here

We will focus on the below arguments: - alternative - paired - exact - correct - conf.int.

Examples

# Exact 
stats::wilcox.test(x = blood_p$bp_after, y = blood_p$bp_before, 
                                   paired = TRUE, 
                                   conf.int = TRUE, 
                                   conf.level = 0.9, 
                                   alterative = "two.sided", 
                                   exact = TRUE)

    Wilcoxon signed rank exact test

data:  blood_p$bp_after and blood_p$bp_before
V = 17251, p-value = 0.009379
alternative hypothesis: true location shift is not equal to 0
90 percent confidence interval:
 1.5045 5.9945
sample estimates:
(pseudo)median 
       3.68875 
# No exact & continuity correction
stats::wilcox.test(x = blood_p$bp_after, y = blood_p$bp_before, 
                                   paired = TRUE, 
                                   conf.int = TRUE, 
                                   conf.level = 0.9, 
                                   alterative = "two.sided", 
                                   exact = FALSE, 
                                   correct = TRUE)

    Wilcoxon signed rank test with continuity correction

data:  blood_p$bp_after and blood_p$bp_before
V = 17251, p-value = 0.009548
alternative hypothesis: true location shift is not equal to 0
90 percent confidence interval:
 1.504565 5.994467
sample estimates:
(pseudo)median 
      3.688796 
# No exact & No continuity correction
stats::wilcox.test(x = blood_p$bp_after, y = blood_p$bp_before, 
                                     paired = TRUE, 
                                     conf.int = TRUE, 
                                     conf.level = 0.9, 
                                     alterative = "two.sided" , 
                                     exact = FALSE, 
                                     correct = FALSE)

    Wilcoxon signed rank test

data:  blood_p$bp_after and blood_p$bp_before
V = 17251, p-value = 0.009535
alternative hypothesis: true location shift is not equal to 0
90 percent confidence interval:
 1.504991 5.993011
sample estimates:
(pseudo)median 
      3.688796 

Important notes on stats:wilcox.test

  • By default an exact p-value is computed if the samples size is less than 50 and there are no ties. Otherwise, a normal approximation is used.
  • If exact p-values are available, an exact confidence interval is obtained by the algorithm described in Bauer (1972), and the Hodges-Lehmann estimator is employed. Otherwise, the returned confidence interval and point estimate are based on normal approximations.
  • If non-exact p-value is calculated, continuity correction in the normal approximation for the p-value can be applied with correct argument.
  • Statistic V is provided, which is a test statistic based on Sprent (1993) algorithm

DOS2

Function senWilcox used for Sensitivity Analysis for Wilcoxon’s Signed-rank Statistic will be applied. For more information about that function go here

Examples

DOS2::senWilcox(blood_p$bp_after - blood_p$bp_before, 
                   gamma = 1, 
                   conf.int = TRUE, 
                   alpha = 0.1, 
                   alternative = "twosided")
$pval
[1] 0.009534732

$estimate
     low     high 
3.688796 3.688796 

$ci
    low    high 
1.50494 5.99305 

Important notes on DOS2:senWilcox

  • Gamma >= 1 is the value of the sensitivity parameter. If gamma=1, then you are assuming ignorable treatment assignment or equivalently no unmeasured confounding - that is the considered scenario in our example, sensitivity analysis is not performed.
  • Only p value, estimate and CI are provided

Coin package - coming soon!