I decided to analyse data on sales of video games between Global and USA Sales. I found the dataset for my analysis on Kaggle.com (https://www.kaggle.com/datasets/ghassenkhaled/video-games-data). I decided to analyse data on video games from genres Shooter and Sports from publishers Electronic Arts and Activision.
#install.packages("readxl")
library(readxl)
mydata <- read_xlsx("~/Desktop/MVA/GamesCorrelationDS .xlsx")
colnames(mydata) <- c("Game","Genre", "Publisher", "USASales" , "EUSales","JPSales", "OtherSales","GlobalSales")
library(tidyr)
mydata <- drop_na(mydata)
#Random sample of 100 units
set.seed(1)
mydata <- mydata[sample(nrow(mydata), 100), ]
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
mydata <- mydata %>%
filter(!USASales >= 3.5 )
mydata$Genre <- factor(mydata$Genre,
levels = c("Shooter", "Sports"),
labels =c("Shooter", "Sports"))
mydata$Publisher <- factor(mydata$Publisher,
levels = c("Electronic Arts", "Activision"),
labels =c("Electronic Arts", "Activision"))
mydata$GlobalSales <- as.numeric(mydata$GlobalSales)
mydata$USASales <- as.numeric(mydata$USASales)
mydata$JPSales <- as.numeric(mydata$JPSales)
mydata$OtherSales <- as.numeric(mydata$OtherSales)
mydata$EUSales <- as.numeric(mydata$EUSales) #changing data to numeric values
head(mydata)
## # A tibble: 6 × 8
## Game Genre Publisher USASales EUSales JPSales OtherSales GlobalSales
## <chr> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 History Civil… Shoo… Activisi… 0.12 0 0 0.01 0.13
## 2 NHL 2002 Spor… Electron… 0.2 0.06 0 0.01 0.27
## 3 FIFA 2000 Spor… Electron… 0.22 1.47 0.04 0.14 1.87
## 4 James Bond 00… Shoo… Activisi… 0.05 0.01 0 0 0.06
## 5 Tony Hawk's U… Spor… Activisi… 0.35 0.13 0 0.01 0.49
## 6 NHL 14 Spor… Electron… 0.4 0.09 0 0.05 0.54
Description of variables:
summary(mydata[ , -1])
## Genre Publisher USASales EUSales
## Shooter:31 Electronic Arts:65 Min. :0.0000 Min. :0.0000
## Sports :68 Activision :34 1st Qu.:0.1200 1st Qu.:0.0100
## Median :0.2600 Median :0.0600
## Mean :0.4665 Mean :0.2281
## 3rd Qu.:0.4800 3rd Qu.:0.2050
## Max. :3.3600 Max. :2.2600
## JPSales OtherSales GlobalSales
## Min. :0.00000 Min. :0.00 Min. :0.0200
## 1st Qu.:0.00000 1st Qu.:0.01 1st Qu.:0.1650
## Median :0.00000 Median :0.03 Median :0.4500
## Mean :0.01131 Mean :0.09 Mean :0.7957
## 3rd Qu.:0.00000 3rd Qu.:0.08 3rd Qu.:0.8200
## Max. :0.28000 Max. :1.03 Max. :6.6800
USA Sales:
Sales vary from a minimum of 0.00 to a maximum of 3.36 units, with a median of 0.26 units, indicating a majority of games have low to modest sales, but some outliers achieve high sales.
The mean sales are 0.4665 units, slightly higher than the median, suggesting a right-skewed distribution with few titles driving higher average sales.
Global Sales:
Global sales range from 0.02 to 6.68 units, showing a broader range than US sales, which underscores the global market’s potential for high-performing titles.
The median global sales are 0.45 units, with a mean of 0.7957 units, again indicating a right-skewed distribution where a few titles achieve exceptionally high sales globally.
library(psych)
describeBy(mydata[ , c(-1, -2, -3, -5, -6, -7)])
## Warning in describeBy(mydata[, c(-1, -2, -3, -5, -6, -7)]): no grouping
## variable requested
## vars n mean sd median trimmed mad min max range skew kurtosis
## USASales 1 99 0.47 0.63 0.26 0.33 0.25 0.00 3.36 3.36 2.69 7.73
## GlobalSales 2 99 0.80 1.11 0.45 0.55 0.44 0.02 6.68 6.66 2.86 9.21
## se
## USASales 0.06
## GlobalSales 0.11
USASales:
Average Sales: 0.47 units, indicating the central tendency for sales within the US.
Variability: Standard deviation of 0.63 units, showing a moderate spread around the average.
Distribution: Right-skewed, meaning a majority of games sell less, with a few outliers selling much more.
GlobalSales:
Average Sales: 0.80 units, suggesting global sales are generally higher than US sales.
Variability: Standard deviation of 1.11 units, indicating a wider spread of sales globally.
Distribution: right-skewed, with pronounced effects of high-selling outliers on the average.
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:psych':
##
## logit
## The following object is masked from 'package:dplyr':
##
## recode
scatterplot(mydata$USASales, mydata$GlobalSales,
smooth = FALSE,
xlim = c(0, 3.36),
ylim = c(0.02, 6.680),
main = "Relationship between Global Sales and USA Sales",
xlab = " USA Sales",
ylab = "Global Sales")
#install.packages("car")
library(car)
scatterplotMatrix (mydata [ ,c (-1,-2, -3, -5, -6, -7)], smooth=FALSE)
Scatter Plot interpretation:
cor(mydata$USASales, mydata$GlobalSales,
method = "pearson",
use = "complete.obs")
## [1] 0.9034788
#install.packages("Hmisc")
library(Hmisc)
##
## Attaching package: 'Hmisc'
## The following object is masked from 'package:psych':
##
## describe
## The following objects are masked from 'package:dplyr':
##
## src, summarize
## The following objects are masked from 'package:base':
##
## format.pval, units
rcorr(as.matrix(mydata[ , c(-1, -2, -3, -5, -6 , -7)]),
type = "pearson")
## USASales GlobalSales
## USASales 1.0 0.9
## GlobalSales 0.9 1.0
##
## n= 99
##
##
## P
## USASales GlobalSales
## USASales 0
## GlobalSales 0
Correlation Analysis (Pearson) interpretation:
I rejected H0 at p-value < 0.001 I can conclude that there is a statistically significant correlation between USA and Global sales.
H0: Population correlation coefficient of USASales and GlobalSales is equal to 0.
H1: Population correlation coefficient of USASales and GlobalSales is not equal to 0.
cor(mydata$USASales, mydata$GlobalSales,
method = "spearman",
use = "complete.obs")
## [1] 0.8747587
library(Hmisc)
rcorr(as.matrix(mydata[ , c(-1, -2, -3, -5, -6 , -7)]),
type = "spearman") #robustness check
## USASales GlobalSales
## USASales 1.00 0.87
## GlobalSales 0.87 1.00
##
## n= 99
##
##
## P
## USASales GlobalSales
## USASales 0
## GlobalSales 0
Correlation Analysis (Spearman) interpretation:
Assumptions:
results <- chisq.test(mydata$Publisher, mydata$Genre,
correct = TRUE)
results
##
## Pearson's Chi-squared test with Yates' continuity correction
##
## data: mydata$Publisher and mydata$Genre
## X-squared = 16.326, df = 1, p-value = 5.333e-05
Interpretation:
H0: There is no association between Genre and Publisher.
H1: There is an association between Genre and Publisher.
addmargins(results$observed)
## mydata$Genre
## mydata$Publisher Shooter Sports Sum
## Electronic Arts 11 54 65
## Activision 20 14 34
## Sum 31 68 99
round(results$expected, 2)
## mydata$Genre
## mydata$Publisher Shooter Sports
## Electronic Arts 20.35 44.65
## Activision 10.65 23.35
Interpretation:
From the Chi-Square test we can see that observed frequencies are different from expected ones. If publisher and genre of a video game are not correlated, I would expect:
To check the direction of the relationship and if the differences between observed and expected observations are statistically significant, I will also check standardized residuals.
round(results$res, 2)
## mydata$Genre
## mydata$Publisher Shooter Sports
## Electronic Arts -2.07 1.40
## Activision 2.87 -1.94
Interpretation:
addmargins(round(prop.table(results$observed),3))
## mydata$Genre
## mydata$Publisher Shooter Sports Sum
## Electronic Arts 0.111 0.545 0.656
## Activision 0.202 0.141 0.343
## Sum 0.313 0.686 0.999
Interpretation:
addmargins(round(prop.table(results$observed,1),3),2)
## mydata$Genre
## mydata$Publisher Shooter Sports Sum
## Electronic Arts 0.169 0.831 1.000
## Activision 0.588 0.412 1.000
Interpretation:
addmargins(round(prop.table(results$observed,2),3), 1)
## mydata$Genre
## mydata$Publisher Shooter Sports
## Electronic Arts 0.355 0.794
## Activision 0.645 0.206
## Sum 1.000 1.000
Interpretation:
library(effectsize)
##
## Attaching package: 'effectsize'
## The following object is masked from 'package:psych':
##
## phi
effectsize:: cramers_v(mydata$Genre, mydata$Publisher)
## Cramer's V (adj.) | 95% CI
## --------------------------------
## 0.42 | [0.24, 1.00]
##
## - One-sided CIs: upper bound fixed at [1.00].
interpret_cramers_v(0.42)
## [1] "very large"
## (Rules: funder2019)
Cramer’s V Interpretation:
fisher.test(mydata$Genre, mydata$Publisher) #robustness check
##
## Fisher's Exact Test for Count Data
##
## data: mydata$Genre and mydata$Publisher
## p-value = 3.358e-05
## alternative hypothesis: true odds ratio is not equal to 1
## 95 percent confidence interval:
## 0.04983585 0.40242675
## sample estimates:
## odds ratio
## 0.146074
Fisher’s Exact Test Interpretation:
Conclusion:
In conclusion hese results highlight significant relationships between the variables in my dataset, especially the strong correlation between USA sales and global sales and the significant association between game genres and publishers.