Author: Milagros Ines Rodriguez Ventura
Do customers who own the supermarket’s member card spend more than customers who buy without member card?
Customer type: type of customers, recorded by Members for customers using member card and Normal for without member card
Total: total price of the purchase, including tax
data <- read.table("./supermarket_sales.csv", header=TRUE, sep=",")
head(data)
## Invoice.ID Branch City Customer.type Gender Product.line
## 1 750-67-8428 A Yangon Member Female Health and beauty
## 2 226-31-3081 C Naypyitaw Normal Female Electronic accessories
## 3 631-41-3108 A Yangon Normal Male Home and lifestyle
## 4 123-19-1176 A Yangon Member Male Health and beauty
## 5 373-73-7910 A Yangon Normal Male Sports and travel
## 6 699-14-3026 C Naypyitaw Normal Male Electronic accessories
## Unit.price Quantity Tax.5. Total Date Time Payment cogs
## 1 74.69 7 26.1415 548.9715 1/5/2019 13:08 Ewallet 522.83
## 2 15.28 5 3.8200 80.2200 3/8/2019 10:29 Cash 76.40
## 3 46.33 7 16.2155 340.5255 3/3/2019 13:23 Credit card 324.31
## 4 58.22 8 23.2880 489.0480 1/27/2019 20:33 Ewallet 465.76
## 5 86.31 7 30.2085 634.3785 2/8/2019 10:37 Ewallet 604.17
## 6 85.39 7 29.8865 627.6165 3/25/2019 18:30 Ewallet 597.73
## gross.margin.percentage gross.income Rating
## 1 4.761905 26.1415 9.1
## 2 4.761905 3.8200 9.6
## 3 4.761905 16.2155 7.4
## 4 4.761905 23.2880 8.4
## 5 4.761905 30.2085 5.3
## 6 4.761905 29.8865 4.1
Unit of observation: each unit of observation represents a purchase made by either a member client or a normal client
Sample size: 1000 observations
https://www.kaggle.com/datasets/lovishbansal123/sales-of-a-supermarket
library(psych)
## Warning: package 'psych' was built under R version 4.3.3
describeBy(data$Total, data$Customer.type)
##
## Descriptive statistics by group
## group: Member
## vars n mean sd median trimmed mad min max range skew
## X1 1 501 327.79 247.99 266.03 299.64 251.8 10.68 1042.65 1031.97 0.84
## kurtosis se
## X1 -0.22 11.08
## ------------------------------------------------------------
## group: Normal
## vars n mean sd median trimmed mad min max range skew
## X1 1 499 318.12 243.9 237.43 288.7 217.29 12.69 1039.29 1026.6 0.94
## kurtosis se
## X1 0.04 10.92
We can say that both samples (member and normal) are balanced as regards numbers of samples. Furthermore, the mean of the total amount spent by members is higher than of those who are not members of the supermarket.
As regards the median, we can say that, for member clients, 50% of them spend 266.03 or less, and the remaining 50% spend more than 266.03. On the other hand, 50% of normal clients spend 237.43 or less and the other 50% spend more than 237.43.
summary(data)
## Invoice.ID Branch City Customer.type
## Length:1000 Length:1000 Length:1000 Length:1000
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
## Gender Product.line Unit.price Quantity
## Length:1000 Length:1000 Min. :10.08 Min. : 1.00
## Class :character Class :character 1st Qu.:32.88 1st Qu.: 3.00
## Mode :character Mode :character Median :55.23 Median : 5.00
## Mean :55.67 Mean : 5.51
## 3rd Qu.:77.94 3rd Qu.: 8.00
## Max. :99.96 Max. :10.00
## Tax.5. Total Date Time
## Min. : 0.5085 Min. : 10.68 Length:1000 Length:1000
## 1st Qu.: 5.9249 1st Qu.: 124.42 Class :character Class :character
## Median :12.0880 Median : 253.85 Mode :character Mode :character
## Mean :15.3794 Mean : 322.97
## 3rd Qu.:22.4453 3rd Qu.: 471.35
## Max. :49.6500 Max. :1042.65
## Payment cogs gross.margin.percentage gross.income
## Length:1000 Min. : 10.17 Min. :4.762 Min. : 0.5085
## Class :character 1st Qu.:118.50 1st Qu.:4.762 1st Qu.: 5.9249
## Mode :character Median :241.76 Median :4.762 Median :12.0880
## Mean :307.59 Mean :4.762 Mean :15.3794
## 3rd Qu.:448.90 3rd Qu.:4.762 3rd Qu.:22.4453
## Max. :993.00 Max. :4.762 Max. :49.6500
## Rating
## Min. : 4.000
## 1st Qu.: 5.500
## Median : 7.000
## Mean : 6.973
## 3rd Qu.: 8.500
## Max. :10.000
With the summary function we can see the max and min value of each variable in the dataset, the mean (average), the median (value that is in the middle) and the 1st and 3rd quartile (the value below which 25% of the data falls and the value below which 75% of the data falls, respectively)
I will use an independent samples t-test because I have two different populations (i.e. two different groups of units) of which I’m going to compare their total amount spent mean. Each unit is measured once.
Assumptions
class(data$Total)
## [1] "numeric"
#install.packages("ggpubr")
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
Member <- ggplot(data[data$Customer.type == "Member", ], aes(x = Total)) +
theme_linedraw() +
geom_histogram() +
ggtitle("Member")
Normal <- ggplot(data[data$Customer.type == "Normal", ], aes(x = Total)) +
theme_linedraw() +
geom_histogram() +
ggtitle("Normal")
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 4.3.3
ggarrange(Member, Normal,
ncol = 2, nrow = 1)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
By looking at the histograms I would say that none of the both distributions are normal because of their skewness, but I will perform two Shapiro-Wilk tests to corroborate it.
library(rstatix)
## Warning: package 'rstatix' was built under R version 4.3.3
##
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
##
## filter
data %>%
group_by(Customer.type) %>%
shapiro_test(Total)
## # A tibble: 2 × 4
## Customer.type variable statistic p
## <chr> <chr> <dbl> <dbl>
## 1 Member Total 0.912 2.02e-16
## 2 Normal Total 0.904 3.49e-17
For both of them, I reject \(H_0\) at \(p-value\) < 0.001. This means that none of the attributes are normally distributed and, therefore, the second assumption is violated and I will need to run a non-parametric alternative test.
As we have independent samples, we will need the Wilcoxon rank sum test.
wilcox.test(data$Total ~ data$Customer.type,
paired = FALSE,
correct = FALSE,
exact = FALSE,
alternative = "two.sided")
##
## Wilcoxon rank sum test
##
## data: data$Total by data$Customer.type
## W = 127453, p-value = 0.5911
## alternative hypothesis: true location shift is not equal to 0
We can’t reject \(H_0\) at \(p\) = 0.5911 > \(\alpha\) = 0.05
#install.packages("effectsize")
library(effectsize)
## Warning: package 'effectsize' was built under R version 4.3.3
##
## Attaching package: 'effectsize'
## The following objects are masked from 'package:rstatix':
##
## cohens_d, eta_squared
## The following object is masked from 'package:psych':
##
## phi
effectsize(wilcox.test(data$Total ~ data$Customer.type,
paired = FALSE,
correct = FALSE,
exact = FALSE,
alternative = "two.sided"))
## r (rank biserial) | 95% CI
## ---------------------------------
## 0.02 | [-0.05, 0.09]
interpret_rank_biserial(0.02)
## [1] "tiny"
## (Rules: funder2019)
Based on the sample data, we find that Normal and Member clients don’t differ in terms of amount spent at the supermarket (\(p\) = 0.5911). The difference in the distributions of the amount spent between the two groups is tiny (\(r\) = 0.02)
Based on the results of the statistical test I can’t conclude that clients who own the membership card spend more than those who don’t own it (i.e normal clients)