Wilcoxon Signed-Rank Test in Statistics Using R
Experiment: Wilcoxon Signed-Rank Test in Statistics Using R
1. Experiment Title
Hypothesis Testing Using the Wilcoxon Signed-Rank Test in R
2. Aim
To study and perform the Wilcoxon Signed-Rank Test using R to determine whether there is a significant difference between two related samples when the assumptions of the paired t-test are not satisfied.
3. Objectives
After completing this experiment, students should be able to:
- Understand the purpose of the Wilcoxon Signed-Rank Test.
- Identify situations where the test is appropriate.
- Formulate null and alternative hypotheses.
- Calculate signed ranks manually.
- Perform the Wilcoxon Signed-Rank Test using R.
- Interpret the test statistic and p-value.
- Make a statistical decision based on the test result.
4. Theory
4.1 What is the Wilcoxon Signed-Rank Test?
The Wilcoxon Signed-Rank Test is a non-parametric statistical test used to compare two related or paired samples.
It is commonly used as an alternative to the paired t-test when:
- The data are not normally distributed.
- The sample size is small.
- The differences between paired observations cannot reasonably be assumed to be normally distributed.
- The data can be ranked.
Examples
The test can be used to compare:
- Student marks before and after a training program.
- Patient measurements before and after a treatment.
- Employee productivity before and after training.
- Machine performance before and after maintenance.
The relationship between the two tests can be summarized as:
| Situation | Appropriate Test |
|---|---|
| Two related samples, normality assumption satisfied | Paired t-test |
| Two related samples, normality assumption not satisfied | Wilcoxon Signed-Rank Test |
4.2 Hypotheses
For a two-sided Wilcoxon Signed-Rank Test:
Null Hypothesis
The median difference between the paired observations is zero.
There is no significant change between the two measurements.
Alternative Hypothesis
The median difference between the paired observations is not zero.
There is a significant difference between the two measurements.
5. Problem Statement
A teacher wants to determine whether a special training program improves student test scores.
The marks of 10 students are recorded before and after attending the training program.
| Student | Before Training | After Training |
|---|---|---|
| 1 | 45 | 50 |
| 2 | 50 | 55 |
| 3 | 48 | 52 |
| 4 | 60 | 65 |
| 5 | 55 | 58 |
| 6 | 52 | 57 |
| 7 | 58 | 63 |
| 8 | 47 | 51 |
| 9 | 62 | 67 |
| 10 | 54 | 60 |
Using a significance level of:
determine whether there is a significant difference between the student marks before and after the training program.
6. Manual Calculation
Step 1: Calculate the Differences
Calculate:
| Student | Before | After | Difference |
|---|---|---|---|
| 1 | 45 | 50 | +5 |
| 2 | 50 | 55 | +5 |
| 3 | 48 | 52 | +4 |
| 4 | 60 | 65 | +5 |
| 5 | 55 | 58 | +3 |
| 6 | 52 | 57 | +5 |
| 7 | 58 | 63 | +5 |
| 8 | 47 | 51 | +4 |
| 9 | 62 | 67 | +5 |
| 10 | 54 | 60 | +6 |
Step 2: Remove Zero Differences
Any pair with:
is removed from the calculation.
In this example, there are no zero differences.
Step 3: Calculate Absolute Differences
Calculate:
and rank them from smallest to largest.
Because some differences are equal, average ranks are assigned to tied values.
| Student | Difference | | Rank | Sign |
1 +5 5 6.5 +
2 +5 5 6.5 +
3 +4 4 2.5 +
4 +5 5 7 +
5 +3 3 1 +
6 +5 5 6.5 +
7 +5 5 6.5 +
8 +4 4 2.5 +
9 +5 5 7 +
10 +6 6 10 +
Step 4: Calculate the Sum of Positive and Negative Ranks
Let:
All differences are positive.
Therefore:
and:
7. R Program
# Wilcoxon Signed-Rank Test # Marks before training before <- c(45, 50, 48, 60, 55, 52, 58, 47, 62, 54) # Marks after training after <- c(50, 55, 52, 65, 58, 57, 63, 51, 67, 60) # Display the data data <- data.frame( Student = 1:10, Before = before, After = after ) print(data) # Perform Wilcoxon Signed-Rank Test result <- wilcox.test(after, before, paired = TRUE, alternative = "two.sided", conf.level = 0.95) # Display test result print(result) # Significance level alpha <- 0.05 # Decision based on p-value if (result$p.value < alpha) { cat("\nDecision: Reject the Null Hypothesis\n") cat("Conclusion: There is a significant difference between the scores before and after training.\n") } else { cat("\nDecision: Fail to Reject the Null Hypothesis\n") cat("Conclusion: There is not enough evidence to conclude that the scores differ significantly.\n") }
8. Explanation of the R Function
The main R function used is:
wilcox.test()
For paired data:
wilcox.test(after, before, paired = TRUE)
Important Arguments
| Argument | Meaning |
|---|---|
after | Measurements after the treatment |
before | Measurements before the treatment |
paired = TRUE | Specifies that observations are paired |
alternative = "two.sided" | Tests for any significant difference |
conf.level = 0.95 | Uses a 95% confidence level |
9. Expected Output
Student Before After
1 1 45 50
2 2 50 55
3 3 48 52
4 4 60 65
5 5 55 58
6 6 52 57
7 7 58 63
8 8 47 51
9 9 62 67
10 10 54 60
Wilcoxon signed rank exact test
data: after and before
V = 55, p-value = 0.001953
alternative hypothesis: true location shift is not equal to 0
Decision: Reject the Null Hypothesis
Conclusion: There is a significant difference between the scores before and after training.10. Interpretation
The Wilcoxon Signed-Rank Test examines whether the median difference between the paired observations is significantly different from zero.
The decision is based on the p-value:
| Condition | Decision |
|---|---|
| p-value < 0.05 | Reject |
| p-value ≥ 0.05 | Fail to reject |
In this example, all students show an increase in their marks after training. The Wilcoxon test helps determine whether this improvement is statistically significant.
11. Result
Thus, the Wilcoxon Signed-Rank Test was performed using R to compare two related samples. The differences between paired observations were ranked according to their absolute values, and the signed ranks were used to test whether the median difference was significantly different from zero. The result was interpreted using the p-value at a 5% significance level.
Comments
Post a Comment