WILCOXON SIGN RANK TEST

This analysis is for RESEARCH SCENARIO 4 from assignment 6. It tests to compare sales Score before and after the campaign.

Hypotheses

  • H0 (Null Hypothesis): There is no improvement in sales after the campaign.
  • H1 (Alternate Hypothesis): There is a measurable improvement in sales.

Result paragraph

A Wilcoxon Signed-Rank Test was conducted to compare sales before and after the campaign among 60 stores. Median sales were higher after the campaign (Md = 24624) than before (Md = 25086), V = 640, p = 0.04. These results indicate that the campaign enhanced sales. The effect size was r = 0.26, indicating a moderate effect.

R code and Analysis

CHECK NORMAL DISTRIBUTION

IMPORT EXCEL FILE Import your Excel dataset into R to conduct analyses.

# INSTALL REQUIRED PACKAGE

# install.packages("readxl")

# LOAD THE PACKAGE

library(readxl)

# IMPORT EXCEL FILE INTO R STUDIO

dataset <- read_excel("//apporto.com/dfs/SLU/Users/minhoku_slu/Downloads/A6R4.xlsx")

CALCULATE THE DIFFERENCE SCORES Purpose: Calculate the difference between the Before scores versus the after scores.

# RENAME THE VARIABLES

Before <- dataset$PreCampaignSales
After <- dataset$PostCampaignSales

Differences <- After - Before

HISTOGRAM Create a histogram for difference scores to visually check skewness and kurtosis.

# CREATE THE HISTOGRAMS

hist(Differences,
     main = "Histogram of Difference Scores",
     xlab = "Value",
     ylab = "Frequency",
     col = "blue",
     border = "black",
     breaks = 20)

  • QUESTION 1: Is the histograms symmetrical, positively skewed, or negatively skewed?

  • ANSWER: The histogram is positively skewed.

  • QUESTION 2: Did the histogram look too flat, too tall, or did it have a proper bell curve?

  • ANSWER: The histogram have a look too flat.

SHAPIRO-WILK TEST Check the normality for the difference between the groups.

shapiro.test(Differences)
## 
##  Shapiro-Wilk normality test
## 
## data:  Differences
## W = 0.94747, p-value = 0.01186
  • QUESTION 1: Was the data normally distributed or abnormally distributed?

  • ANSWER:The data was abnormally distributed.(p<0.05)

BOXPLOT Check for any outliers impacting the mean.

boxplot(Differences,
        main = "Distribution of Score Differences (After - Before)",
        ylab = "Difference in Scores",
        col = "blue",
        border = "darkblue")

  • QUESTION 1: How many dots are in your boxplot?

      1. No dots.
      1. One or two dots.
      1. Many dots. # ANSWER:B
  • QUESTION 2: Where are the dots in your boxplot?

      1. There are no dots.
      1. Very close to the whiskers (lines of the boxplot).
      1. Far from the whiskers (lines of the boxplot).
  • ANSWER:C

  • QUESTION 3: Based on the dots and there location, is the data normal?

  • ANSWER: The data is not normal.

DESCRIPTIVE STATISTICS Calculate the mean, median, SD, and sample size for each group.

# DESCRIPTIVES FOR BEFORE SCORES

mean(Before, na.rm = TRUE)
## [1] 25154.53
median(Before, na.rm = TRUE)
## [1] 24624
sd(Before, na.rm = TRUE)
## [1] 12184.4
length(Before)
## [1] 60
# DESCRIPTIVES FOR AFTER SCORES

mean(After, na.rm = TRUE)
## [1] 26873.45
median(After, na.rm = TRUE)
## [1] 25086
sd(After, na.rm = TRUE)
## [1] 14434.37
length(After)
## [1] 60

WILCOXON SIGN RANK TEST

wilcox.test(Before, After, paired = TRUE)
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  Before and After
## V = 640, p-value = 0.0433
## alternative hypothesis: true location shift is not equal to 0

DETERMINE STATISTICAL SIGNIFICANCE * p = 0.04

EFFECT SIZE FOR WILCOXON SIGN RANK TEST Purpose: Determine how big of a difference there was between the group means.

# INSTALL REQUIRED PACKAGE

# install.packages("rstatix")
# install.packages('coin')

# LOAD THE PACKAGE


library(rstatix)
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
## 
##     filter
library(coin)
## Loading required package: survival
## 
## Attaching package: 'coin'
## The following objects are masked from 'package:rstatix':
## 
##     chisq_test, friedman_test, kruskal_test, sign_test, wilcox_test
# CALCULATE RANK BISERIAL CORRELATION (EFFECT SIZE)

df_long <- data.frame(
 id = rep(1:length(Before), 2),
 time = rep(c("Before", "After"), each = length(Before)),
 score = c(Before, After)
)
wilcox_effsize(df_long, score ~ time, paired = TRUE)
## # A tibble: 1 × 7
##   .y.   group1 group2 effsize    n1    n2 magnitude
## * <chr> <chr>  <chr>    <dbl> <int> <int> <ord>    
## 1 score After  Before   0.261    60    60 small

QUESTIONS

  • QUESTION 1: What is the size of the effect?

  • YOUR ANSWER: A Rank Biserial Correlation of 0.26 indicates the difference between the group averages was moderate.

  • QUESTION 2: Which group had the higher average score?

  • YOUR ANSWER: After group has higher score.