Author: Wong, Hing Yee Yashelyn


1 Research question

1.1 Are there differences in the number of purchases on web for married and single customers?
1.2 Variables to be collected: Married customers, single customers, number of web purchase
mydata <- read.table("./FoodAppBusiness.csv", header=TRUE, sep=",", dec=".")

head(mydata[c(-10:-12)], )
##   MonthlyIncome ActiveSinceDays Age Married Single NoOfDaysSinceLastPurchase
## 1         58138            2822  63       0      1                        58
## 2         46344            2272  66       0      1                        38
## 3         71613            2471  55       1      0                        26
## 4         26646            2298  36       1      0                        26
## 5         58293            2320  39       1      0                        94
## 6         62513            2452  53       1      0                        16
##   NoOfWebPurchase NoOfStorePurchase NoOfWebVisitsMonth
## 1               8                 4                  7
## 2               1                 2                  5
## 3               8                10                  4
## 4               2                 4                  6
## 5               5                 6                  5
## 6               6                10                  6

2 Data

2.1 Definition of variables:

MonthlyIncome - the observed customers’ income per month

ActiveSinceDays - the observed customers’ active number of days since using the app

Age - the age of the observed customers

Married - the customer’s marital status being married, where 0 stands for No and 1 stands for Yes

Single - the customer’s marital status being single, where 0 stands for No and 1 stands for Yes

NoOfDaysSinceLastPurchased - the number of days since the last purchase from the web or store

NoOfWebPurchase - number of times the customer purchase from the web

NoOfStorePurchase - number of times the customer purchase from the store

NoOfWebVisitsMonth - number of times the customer visited the web

2.2 Unit of observation and sample size: 2205
2.3 Source of the data set: Kaggle - https://www.kaggle.com/datasets/ybifoundation/food-app-business
mydata$MarriedF <- factor(mydata$Married, levels = c(0,1), labels = c("No", "Yes"))
mydata$SingleF <- factor(mydata$Single, levels = c(0,1), labels = c("No", "Yes"))
summary(mydata[c(-2,-4:-6,-9:-12)], )
##  MonthlyIncome         Age       NoOfWebPurchase  NoOfStorePurchase MarriedF  
##  Min.   :  1730   Min.   :24.0   Min.   : 0.000   Min.   : 0.000    No : 783  
##  1st Qu.: 35196   1st Qu.:43.0   1st Qu.: 2.000   1st Qu.: 3.000    Yes:1422  
##  Median : 51287   Median :50.0   Median : 4.000   Median : 5.000              
##  Mean   : 51622   Mean   :51.1   Mean   : 4.101   Mean   : 5.824              
##  3rd Qu.: 68281   3rd Qu.:61.0   3rd Qu.: 6.000   3rd Qu.: 8.000              
##  Max.   :113734   Max.   :80.0   Max.   :27.000   Max.   :13.000              
##  SingleF   
##  No :1422  
##  Yes: 783  
##            
##            
##            
## 
2.4 Basic descriptive statistics - estimate a few parameters (e.g., functions summary, describe, etc.) and explanation

Min. of MonthlyIncome: the least monthly income of the observed customers is 1730

Median of Age: 50% or less of the observed customers are 50 years old

Max. of NoOfWebPurchase; the most number of web purchase is 27 times

Mean of NoOfStorePurchase: the average number of store purchase is 5.824 times

MarriedF and SingleF: 1422 of the observed customers are married and 783 of the observed customers are single

3 Analysis

3.1 Independent t-test will be used because the hypothes is about the difference between two population arithmetic means (married and single customers) and sample size is large.
3.2 Assumptions: the variables are numerical, there is normal distribution and equal variances in both groups single and married customers, the data is from two independent population.
3.3 Statistical test based on the results of the assumption evaluation and its interpretation:
library(psych)
describeBy(mydata$NoOfWebPurchase, mydata$MarriedF)
## 
##  Descriptive statistics by group 
## group: No
##    vars   n mean   sd median trimmed  mad min max range skew kurtosis  se
## X1    1 783 4.08 2.82      4    3.78 2.97   0  27    27  1.6     7.18 0.1
## ------------------------------------------------------------ 
## group: Yes
##    vars    n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 1422 4.11 2.69      4    3.86 2.97   0  25    25 0.94     1.98 0.07

The results for Single and Married customers regarding Number of Web Purchase are similar.

library(ggplot2)
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
Married_no <- ggplot(mydata[mydata$MarriedF == "No", ], aes(x = NoOfWebPurchase)) + theme_linedraw() + geom_histogram() + ggtitle("Single")

Married_yes <- ggplot(mydata[mydata$MarriedF == "Yes", ], aes(x = NoOfWebPurchase)) + theme_linedraw() + geom_histogram() + ggtitle("Married")

install.packages("ggpubr", repos = "https://cloud.r-project.org/", dependencies = TRUE)
## Installing package into 'C:/Users/user/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'ggpubr' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\user\AppData\Local\Temp\RtmpiQrUzf\downloaded_packages
library(ggpubr)
ggarrange(Married_no, Married_yes, ncol = 2, nrow = 1)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

The graphs for Single and Married are right-skewed, therefore Wilcoxon rank sum test will be used.

library(rstatix)
## 
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
## 
##     filter
mydata %>%
  group_by(MarriedF) %>%
  shapiro_test(NoOfWebPurchase)
## # A tibble: 2 × 4
##   MarriedF variable        statistic        p
##   <fct>    <chr>               <dbl>    <dbl>
## 1 No       NoOfWebPurchase     0.885 1.13e-23
## 2 Yes      NoOfWebPurchase     0.920 9.69e-27

H0: NoOfWebPurchase is normally distributed for Singled.

H1: NoOfWebPurchase is not normally distributed for Singled.

We reject H0 at p<0.001.

H0: NoOfWebPurchase is normally distributed for Married.

H1: NoOfWebPurchase is not normally distributed for Married.

We reject H0 at p<0.001.

wilcox.test(mydata$NoOfWebPurchase ~ mydata$MarriedF,
            paired = FALSE,
            correct = FALSE,
            exact = FALSE,
            alternative = "two.sided")
## 
##  Wilcoxon rank sum test
## 
## data:  mydata$NoOfWebPurchase by mydata$MarriedF
## W = 549996, p-value = 0.636
## alternative hypothesis: true location shift is not equal to 0
wilcox.test(mydata$NoOfWebPurchase ~ mydata$SingleF,
            paired = FALSE,
            correct = FALSE,
            exact = FALSE,
            alternative = "two.sided")
## 
##  Wilcoxon rank sum test
## 
## data:  mydata$NoOfWebPurchase by mydata$SingleF
## W = 563431, p-value = 0.636
## alternative hypothesis: true location shift is not equal to 0

H0: locations of distribution of web purchase are the same for Single and Married customers.

H1: locations of distribution of web purchases are not the same for Single and Married customers.

We cannot reject H0.

3.4 Calculation of the effect size and its interpretation:
install.packages('effectsize', repos = "https://cloud.r-project.org/", dependencies = TRUE)
## Installing package into 'C:/Users/user/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'effectsize' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\user\AppData\Local\Temp\RtmpiQrUzf\downloaded_packages
library(effectsize)
## 
## 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(mydata$NoOfWebPurchase ~ mydata$MarriedF,
                        paired = FALSE,
                        correct = FALSE,
                        exact = FALSE,
                        alternative = "two.sided"))
## r (rank biserial) |        95% CI
## ---------------------------------
## -0.01             | [-0.06, 0.04]
interpret_rank_biserial(0.01)
## [1] "tiny"
## (Rules: funder2019)

4 Conclusion

Based on the sample data, it cannot prove that there are differences in the number of web purchases between Married and Single customers (p>0.05). Single and Married customers have similar number of purchases on web. The difference in distribution is tiny (r = 0.01). ___________________________________________

*Source to deal with error “trying to use CRAN without mirror”: https://stackoverflow.com/questions/62357732/installation-issues-of-ggpubr