Homework 2 Rok Rojc

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
Variable Interpretation:
  • Genres: Shooter (31 titles) and Sports (68 titles)
  • Publishers: Electronic Arts (65 titles) and Activision (34 titles)

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.

Research Question: is there a correlation between global sales and USA sales?

Assumptions:
  • Both variables are numeric. This assumption is met.
  • Errors are normally distributed. We assume this assumption is met, since we have big enough sample.
  • Linear relationship between the variables.
H0: There is no correlation between USASales and GlobalSales.
H1: There is correlation between USASales and GlobalSales.
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:

  • The scatterplot shows a strong positive correlation between USASales and GlobalSales. As US sales figures go up, global sales tend to increase correspondingly, indicating that success in the US market is a good predictor of worldwide sales.
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 found a high correlation (0.9) between USASales and GlobalSales, both for Pearson coefficients. This indicates a strong linear relationship and rank-order consistency between USA sales and global sales of video games. To check whether the correlation is statistically significant we look at population correlation coefficient:
  • p-value = 0
  • H0: Rho = 0
  • H1: Rho ≠ 0

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:

  • I found a high correlation (0.87) between USASales and GlobalSales, for Spearman’s coefficients. This indicates a strong linear relationship and rank-order consistency between USA sales and global sales of video games. I did Spearman as a robustness check. (p<0,001).

Research Question: is there an association between game publishers and game genre?

H0: There is no association between Genre and Publisher.
H1: There is an association between Genre and Publisher.

Assumptions:

  • observations are independent - met
  • all expected frequencies are greater than 5 - met
  • if the contingency table is more than 2x2, only 20% of expected frequencies can be between 1 and 5, but this will reduce the power the test - met
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:

  • Based on the sample data, I can reject the null hypothesis at p-value < 0.001 and claim that there is an association between the publisher and genre. Then I checked if there are differences between observed and expected observations.

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:

  • 44.65 Electronic Arts video games to be in Sports genre
  • 23.35 Activision games to be Sports genre
  • 20.35 Electronic Arts video games to be in Shooter genre
  • 10.65 Activison video games to be in Shooter genre

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:

  • There is less than expected number of games in category Electronic Arts and Shooter. It had an effect, because the value is -2.07 and I can state that with 95% certainty (alpha=5%). There is more than expected games in category activision/shooter with 2.87 and I can state that with 99% certainty (alpha=1%). I can’t say that the differences in genre sports is statistically significant for either Electronic Arts or Activision.
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:

  • Out of 99 observed video games, there is 54.5 % of them that are classified in Sports genre and were published by Electronic Arts.
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:

  • Out of all video games classified in the Shooter genre, 58.8 % were published by Activision.
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:

  • Out of all video games that were published by Activision, 64.5 % of them were classified in the Shooter genre.
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:

  • The Cramer’s V value was 0.42, which is interpreted as a ’ very large’ effect size according to Funder’s 2019 rules. This suggests a substantial association between game genre and publisher in this sample.
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:

  • I did the Fisher’s Exact Test as an additional robustness check and it also indicated a significant association between game genre and publisher (p-value < 3.358e-05), further supporting the findings from the Chi-square test for this sample.

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.