Non_parametric hypothesis test

Assumes the data is not normally distributed

load teh libraries

library(tidyverse)
library(openxlsx)
library(dplyr)
excel_work1 <- "C:/R 2025 Data Science/descriptive data.xlsx"
sales_data <- read.xlsx(excel_work1, sheet = "retail sales data")
student_data <- read.xlsx(excel_work1, sheet = "StudentsPerformance")

Wilcoxon Signed-Ranked Test (Non parametric one sample t-test)

Question: Is the typical (median) price sig diff from 100

  • Ho: The typical score is 100
  • HA: The typical score is 100
wilcox.test(sales_data$Price, mu = 100)
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  sales_data$Price
## V = 54, p-value = 0.7546
## alternative hypothesis: true location is not equal to 100

Mann-whitney U-Test (Non parametric two sample t-test)

Question: do male and female Differ in price

  • Ho: On average(median) there is no difference b/w genders concerning price
  • Ha: On average(median) there is a diff b/w genders concerning price
wilcox.test(Price ~ Customer.Gender, data = sales_data)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  Price by Customer.Gender
## W = 19.5, p-value = 0.3532
## alternative hypothesis: true location shift is not equal to 0

Wilcoxon Signed Test (Non parametric t test)

wilcox.test(student_data$reading.score, student_data$writing.score, paired = TRUE)
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  student_data$reading.score and student_data$writing.score
## V = 269903, p-value = 3.821e-14
## alternative hypothesis: true location shift is not equal to 0

kRUSKAL WALLIS TEST (NON Parametric T-Test)

QUESTION: Is there any difference in price between product categories

  • Ho: There is no difference in price between product categories
  • Ha: At least on group is different
kruskal.test(Price ~ Product.Category, data = sales_data)
## 
##  Kruskal-Wallis rank sum test
## 
## data:  Price by Product.Category
## Kruskal-Wallis chi-squared = 9.3551, df = 2, p-value = 0.009302

A post hoc test for non parametric: dunns test

library(FSA)
dunnTest(Price ~ Product.Category, data = sales_data, method = "bonferroni")
##               Comparison         Z    P.unadj       P.adj
## 1 Clothing - Electronics -1.737071 0.08237469 0.247124061
## 2        Clothing - Toys  1.311666 0.18963297 0.568898911
## 3     Electronics - Toys  3.048736 0.00229806 0.006894181