DEPENDENT T-TEST & WILCOXON SIGN RANK

Used to test if there is a difference between Before scores and After scores (comparing the means).

NULL HYPOTHESIS (H0)

There is no difference in average sales before and after the campaign.

ALTERNATE HYPOTHESIS (H1)

Sales increased after the campaign.

IMPORT EXCEL FILE

Purpose

Import your Excel dataset into R to conduct analyses.

INSTALL REQUIRED PACKAGE

install.packages(“readxl”)

LOAD THE PACKAGE

Always reload the package you want to use.

library(readxl)

IMPORT EXCEL FILE INTO R STUDIO

A6R4 <- read_excel("/Users/alfred/Desktop/A6R4.xlsx")

CALCULATE THE DIFFERENCE SCORES

Calculate the difference between the Before scores versus the after scores.

Before <- A6R4$PreCampaignSales
After <- A6R4$PostCampaignSales

Differences <- After - Before

HISTOGRAM

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

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

QUESTIONS

Q1) Is the histograms symmetrical, positively skewed, or negatively skewed?

- The histogram of the difference scores appeared slightly positively skewed (longer tail to the right), which suggests that a few stores experienced larger-than-typical increases in sales.

Q2) Did the histogram look too flat, too tall, or did it have a proper bell curve?

- The histogram did not form a perfect bell curve; it looked somewhat flat and irregular, indicating that the distribution of difference scores deviates from normality.

SHAPIRO-WILK TEST

Check the normality for the difference between the groups.

CONDUCT SHAPIRO-WILK TEST

shapiro.test(Differences)
## 
##  Shapiro-Wilk normality test
## 
## data:  Differences
## W = 0.94747, p-value = 0.01186

QUESTIONS

Q1) Was the data normally distributed or abnormally distributed?

- The Shapiro-Wilk test returned p = 0.01186, which is less than 0.05. This means the data was NOT normally distributed. Therefore, we use the Wilcoxon Sign Rank test instead of the Dependent t-test.

BOXPLOT

Check for any outliers impacting the mean.

CREATE THE BOXPLOT

boxplot(Before, After,
        names = c("Before", "After"),
        main = "Boxplot of Before and After Scores",
        col = c("lightblue", "lightgreen"))

QUESTIONS

Q1) Were there any dots outside of the boxplots? These dots represent participants with extreme scores.

- Yes, there were a few dots outside the boxplots, which indicate the presence of outliers.

Q2) If there are outliers, are they are changing the mean so much that the mean no longer accurately represents the average score?

- The outliers appear to have some influence, but combined with the Shapiro-Wilk test result,the bigger issue is that the data is not normally distributed.

Q3) Make a decision. If the outliers are extreme, you will need to switch to a Wilcoxon Sign Rank.

If there are not outliers, or the outliers are not extreme, continue with Dependent t-test.

-Since the data is abnormally distributed (p < .05 from Shapiro-Wilk), and outliers are present, the correct test is the Wilcoxon Sign Rank test.

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

If results were statistically significant (p < .05), continue to effect size section below.

If results were NOT statistically significant (p > .05), skip to reporting section below.

NOTE

Getting results that are not statistically significant does NOT mean you switch to Wilcoxon Sign Rank.

The Wilcoxon Sign Rank test is only for abnormally distributed data — not based on outcome significance.

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”)

LOAD THE PACKAGE

Always reload the package you want to use.

library(rstatix)
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
## 
##     filter

CALCULATE RANK BISERIAL CORRELATION (EFFECT SIZE)

install.packages(‘coin’)

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

Q1) What is the size of the effect?

± 0.00 to 0.09 = small

± 0.10 to 0.29 = moderate

± 0.30 to 0.49 = large

± 0.50 to 1.00 = very large

- The Wilcoxon signed-rank test rank biserial correlation = 0.261. Therefore, the effect size of 0.261 indicates a moderate effect.

Q2) Which group had the higher average score?

Mean Before = 25154.53

Mean After = 26873.45

Since the After mean is higher than the Before mean, the After group (PostCampaignSales) had the higher average score.