2)/3)/4)
videoGameData <- read.table("./Video_Games.csv", header=TRUE, sep=",", dec=".")
head(videoGameData)
## Platform Release.Year Genre Publisher Global.Sales
## 1 Wii 2006 Sports Nintendo 82.53
## 2 Wii 2009 Sports Nintendo 32.77
## 3 Wii 2007 Sports Nintendo 22.70
## 4 Wii 2009 Sports Nintendo 21.79
## 5 PS3 2013 Action Take-Two Interactive 21.04
## 6 PS2 2004 Action Take-Two Interactive 20.81
tail(videoGameData)
## Platform Release.Year Genre Publisher Global.Sales
## 7098 GBA 2004 Action Atari 0.61
## 7099 GC 2001 Sports Electronic Arts 0.61
## 7100 GBA 2001 Adventure Activision 0.61
## 7101 N64 1999 Sports Electronic Arts 0.61
## 7102 Wii 2010 Sports Activision 0.61
## 7103 GBA 2003 Sports Activision 0.60
The data shows global sales of various video games across the Sports, Action and Adventure genres. The unit of observation is the sale of a video game. The sample size is 7103 which is very large. The variables of the data are as follows:
Platform –> this indicates what platform/console the video game was released on. Some platforms include Wii, PS2, PS3, N64, etc.
Release Year –> this indicates what year the video game was released.
Genre –> this indicates what genre the video game falls under.
Publisher –> this indicates which company published the game.
Global Sales –> this value indicates the total sales across the world for the video game. A specific unit of measurement was not given but we can assume the value is in millions of units sold as that is what video games are measured by usually.
The source of the data is from kaggle.com but its original source came from a journal article where they studied the effects of storytelling in video game ratings and sales: (https://zenodo.org/records/2454579#.Y9Y2c9JBwUE). Various columns in the data were removed from the CSV file in order to focus solely on the global sales.
a)/b)
library(psych)
describeBy(x = videoGameData$Global.Sales, group = videoGameData$Genre)
##
## Descriptive statistics by group
## group: Action
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 3409 0.52 1.14 0.19 0.29 0.22 0.01 21.04 21.03 7.92 98.63 0.02
## ------------------------------------------------------------
## group: Adventure
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 1314 0.18 0.51 0.05 0.09 0.06 0.01 11.18 11.17 11.11 190.6 0.01
## ------------------------------------------------------------
## group: Sports
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 2380 0.57 2.07 0.23 0.33 0.25 0.01 82.53 82.52 28.82 1064.08 0.04
From the describeBy function we can see that the average sales are different by genre but this does not mean we can reject the null hypothesis.
Now, tests need to be run to see if the variable is normally distributed within each group and if there is homoscedacity
library(rstatix)
##
## Attaching package: 'rstatix'
## The following object is masked from 'package:stats':
##
## filter
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
videoGameData %>%
group_by(Genre) %>%
shapiro_test(Global.Sales)
## # A tibble: 3 × 4
## Genre variable statistic p
## <chr> <chr> <dbl> <dbl>
## 1 Action Global.Sales 0.401 7.54e-75
## 2 Adventure Global.Sales 0.301 5.42e-57
## 3 Sports Global.Sales 0.154 1.76e-73
library(car)
## Loading required package: carData
##
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
##
## recode
## The following object is masked from 'package:psych':
##
## logit
videoGameData$Genre <- as.factor(videoGameData$Genre) #Done to remove warning message that was being received about Genre being coerced to factor
leveneTest(videoGameData$Global.Sales, group = videoGameData$Genre)
## Levene's Test for Homogeneity of Variance (center = median)
## Df F value Pr(>F)
## group 2 22.892 1.23e-10 ***
## 7100
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
The Shapiro Test was performed to test the normality of the variable within each group outputs very small p-values for each group. The null hypthosis of this test is that the variable is normally distributed; because the p-values are incredibly small, we can reject the null hypothesis and conclude the Global Sales within each Genre are not normally distributed.
The Levene Test was performed to test the homoscedasticity of the Global Sales variable, or, to see if the variance of Global Sales is the same within each Genre. The null hypothesis of the Levene Test is that the variable is homoscedastic; because the output was a very small p-value, we can reject the null hypothesis and conclude the variable is not homoscedastic.
Because of the output of these tests, we can not perform a parametric test and must perform a non-perametric test. For this case, we will use Kruskal-Wallis Rank Sum Test
kruskal.test(Global.Sales ~ Genre, data = videoGameData)
##
## Kruskal-Wallis rank sum test
##
## data: Global.Sales by Genre
## Kruskal-Wallis chi-squared = 692.67, df = 2, p-value < 2.2e-16
From this Kruskal-Wallis test, it outputs a very small p-value, which provides strong evidence that we can reject the null hypothesis (the average of global sales amongst each genre is the same). Therefore, we can conclude that global sales of a video game are impacted by its genre. A test can now be conducted to determine the effect size.
kruskal_effsize(Global.Sales ~ Genre, data=videoGameData)
## # A tibble: 1 × 5
## .y. n effsize method magnitude
## * <chr> <int> <dbl> <chr> <ord>
## 1 Global.Sales 7103 0.0973 eta2[H] moderate
From this test, a moderate effect size is outputted but a bonferroni adjustment should be performed since we are comparing global sales across multiple genres
library(rstatix)
genres_nonpar <- wilcox_test(Global.Sales ~ Genre,
paired=FALSE,
p.adjust.method = "bonferroni",
data = videoGameData)
genres_nonpar
## # A tibble: 3 × 9
## .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif
## * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
## 1 Global.S… Action Adven… 3409 1314 3180182 2.97e-111 8.91e-111 ****
## 2 Global.S… Action Sports 3409 2380 3734344. 2.56e- 7 7.68e- 7 ****
## 3 Global.S… Adven… Sports 1314 2380 773886 4.66e-143 1.40e-142 ****
A Post-Hoc test is also conductd to gain deeper insights into differences amongst the genres.
pwc <- videoGameData %>%
wilcox_test(Global.Sales ~ Genre,
paired = FALSE,
p.adjust.method = "bonferroni")
krushkal_results <- kruskal_test(Global.Sales ~ Genre,
data = videoGameData)
library(rstatix)
pwc <- pwc %>%
add_y_position(fun = "max", step.increase = 0.25)
library(ggpubr)
## Loading required package: ggplot2
##
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
##
## %+%, alpha
ggboxplot(videoGameData, x = "Genre", y = "Global.Sales", add = "point", ylim=c(0,15)) +
stat_pvalue_manual(pwc, hide.ns = FALSE) +
stat_summary(fun = median, geom = "point", shape = 16, size = 4,
aes(group=Genre), color="darkred",
position = position_dodge(width=0.8)) +
stat_summary(fun = median, color = "darkred",
position = position_dodge(width=0.8),
geom="text", vjust = -0.5, hjust = -1,
aes(label = round(after_stat(y), digits = 2), group = Genre))+
labs(subtitle = get_test_label(krushkal_results, detailed = TRUE),
caption = get_pwc_label(pwc))
d)
In conclusion, the global sales of video games differs for at least one of the groups (x^2 = 692.67, p<0.0001), the effect size was moderate (n^2 = 0.097). Post-Hoc test reveals strong differences in the Adventure genre and slight differences between the Action and Sports genre.