library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0      ✔ purrr   1.0.1 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.3.0      ✔ stringr 1.5.0 
## ✔ readr   2.1.3      ✔ forcats 1.0.0
## Warning: package 'tidyr' was built under R version 4.2.3
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(ggplot2)
library(dplyr)
library(readr)
library(forcats)

df <- read_csv("C:/Users/hp/Downloads/GamingStudy_data.csv (1).zip")
## Rows: 13464 Columns: 55
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): GADE, Game, Platform, earnings, whyplay, League, Gender, Work, Deg...
## dbl (38): S. No., Timestamp, GAD1, GAD2, GAD3, GAD4, GAD5, GAD6, GAD7, SWL1,...
## lgl  (1): highestleague
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(df)

#Data cleaning
clean_totals <- df %>%
  drop_na(Hours) %>% #dropping NA values
  filter(Hours < 112 ) %>% #limiting the number of hours per week to be realistic
  drop_na(SPIN_T) #dropping NA values
#Descriptive analysis
clean_totals %>%
  count(Game)
## # A tibble: 11 × 2
##    Game                    n
##    <chr>               <int>
##  1 Counter Strike        298
##  2 Destiny                18
##  3 Diablo 3               83
##  4 Guild Wars 2           36
##  5 Hearthstone            95
##  6 Heroes of the Storm    40
##  7 League of Legends   10745
##  8 Other                 964
##  9 Skyrim                 23
## 10 Starcraft 2           325
## 11 World of Warcraft     149
clean_totals %>%
  count(Reference)
## # A tibble: 5 × 2
##   Reference          n
##   <chr>          <int>
## 1 CrowdFlower        3
## 2 Other             60
## 3 Reddit         12652
## 4 TeamLiquid.net    50
## 5 <NA>              11
ggplot(clean_totals)+
  geom_density(mapping=aes(x=Hours),fill ='orange',alpha = .1)+
  labs(title='Hours Played Per Week', subtitle='Collected by Marian Sauter and Dejan Draschkow')

ggplot(clean_totals)+
  geom_density(mapping=aes(x=SPIN_T),fill ='green',alpha = .1)+
  labs(title='Social Phobia Distribution Among Video Game Players', subtitle='Collected by Marian Sauter and Dejan Draschkow')

ggplot(clean_totals)+
  geom_density(mapping=aes(x=GAD_T),fill ='blue',alpha = .1)+
  labs(title='Generalized Anxiety Distribution Among Video Game Players', subtitle='Collected by Marian Sauter and Dejan Draschkow')

ggplot(clean_totals)+
  geom_density(mapping=aes(x=SWL_T),fill ='yellow',alpha = .1)+
  labs(title='Satisfaction with Life Distribution Among Video Game Players', subtitle='Collected by Marian Sauter and Dejan Draschkow')

#Focusing on low satisfaction with life responses (<9)
low_swl <- clean_totals %>%
  filter(SWL_T <= 9) %>%
  group_by(Playstyle) %>%
  summarize(n=n(), avg_hrs = mean(Hours),avg_swl = mean(SWL_T)) %>%
  filter(n > 1)
low_swl
## # A tibble: 4 × 4
##   Playstyle                                                    n avg_hrs avg_swl
##   <chr>                                                    <int>   <dbl>   <dbl>
## 1 Multiplayer - online - with online acquaintances or tea…   258    28.9    7.43
## 2 Multiplayer - online - with real life friends              283    24.7    7.44
## 3 Multiplayer - online - with strangers                      436    27.5    7.11
## 4 Singleplayer                                                94    22.5    7.05
ggplot(low_swl)+
  geom_bar(mapping=aes(x="", y=n, fill=Playstyle),stat='identity', width=1, color="white") +
  coord_polar('y', start=0) +
  labs(title='Playstyles of "low satisfaction with life" respondents', subtitle='Classified as a score of < 9')+
  theme_void() # remove background, grid, numeric labels

#Correlation analysis
#Grouped by video game title
game_score <- clean_totals %>%
  group_by(Game) %>%
  summarise(n=n(),generalized_anxiety_score=mean(GAD_T), satisfaction_with_life_score=mean(SWL_T), social_phobia_score=mean(SPIN_T)) %>%
  mutate_if(is.numeric, round, digits=2)

game_score
## # A tibble: 11 × 5
##    Game                    n generalized_anxiety_score satisfaction_wi…¹ socia…²
##    <chr>               <dbl>                     <dbl>             <dbl>   <dbl>
##  1 Counter Strike        298                      5.14              18.5    19.6
##  2 Destiny                18                      3.39              21.6    17.4
##  3 Diablo 3               83                      5.95              18.5    24.3
##  4 Guild Wars 2           36                      4.33              20.4    20.2
##  5 Hearthstone            95                      5.85              20.2    19.2
##  6 Heroes of the Storm    40                      5.42              18.8    21.8
##  7 League of Legends   10745                      5.19              19.8    19.8
##  8 Other                 964                      5.41              19.5    20.6
##  9 Skyrim                 23                      5.09              21.8    23.6
## 10 Starcraft 2           325                      4.63              21.2    18.2
## 11 World of Warcraft     149                      5.13              19.2    21.1
## # … with abbreviated variable names ¹​satisfaction_with_life_score,
## #   ²​social_phobia_score
ggplot(game_score)+
  geom_col(aes(x=reorder(Game,-social_phobia_score),y=social_phobia_score, fill=-social_phobia_score))+
  labs(title='Average Social Phobia Score Per Video Game', subtitle='Collected by Marian Sauter and Dejan Draschkow', x='Game Title', y = 'Social Phobia Score')+
  guides(x =  guide_axis(angle = 45))

ggplot(game_score)+
  geom_col(aes(x=reorder(Game,-satisfaction_with_life_score),y=satisfaction_with_life_score, fill=satisfaction_with_life_score))+
  labs(title='Average Satisfaction With Life Per Video Game', subtitle='Collected by Marian Sauter and Dejan Draschkow', x='Game Title', y = 'Satisfaction With Life')+
  guides(x =  guide_axis(angle = 45))

ggplot(game_score)+
  geom_col(aes(x=reorder(Game,-generalized_anxiety_score),y=generalized_anxiety_score, fill=-generalized_anxiety_score))+
  labs(title='Average Generalized Anxiety Per Video Game', subtitle='Collected by Marian Sauter and Dejan Draschkow', x='Game Title', y = 'Generalized Anxiety Score')+
  guides(x =  guide_axis(angle = 45))

#Exploring hours played per week
ggplot(data=clean_totals)+
  geom_smooth(mapping=aes(y = SPIN_T,x = Hours), color='orange')+
  #geom_count(mapping=aes(y = SPIN_T,x = Hours),alpha=0)+
  labs(title='Hours per week & social phobia score',subtitle='Collected by Marian Sauter and Dejan Draschkow')
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

#facet_wrap(.~ Game)

ggplot(data=clean_totals)+
  geom_smooth(mapping=aes(x = Hours,y = GAD_T), color='orange', method = 'gam')+
  #geom_count(mapping=aes(x = GAD_T,y = Hours, color=Hours),alpha=0)+
  labs(title='Hours per week & Generalized Anxiety Disorder',subtitle='Collected by Marian Sauter and Dejan Draschkow')
## `geom_smooth()` using formula = 'y ~ s(x, bs = "cs")'

# facet_wrap(.~ Game)

ggplot(data=clean_totals)+
  geom_smooth(mapping=aes(x = Hours,y = SWL_T), color='orange',method = 'gam')+
  #geom_count(mapping=aes(x = SWL_T,y = Hours, color=Hours),alpha=0)+
  labs(title='Hours per week & satisfaction with life score',subtitle='Collected by Marian Sauter and Dejan Draschkow')
## `geom_smooth()` using formula = 'y ~ s(x, bs = "cs")'

#facet_wrap(.~ Game)

#Exploring location
local <- clean_totals %>%
  group_by(Residence) %>%
  summarise(n=n(),generalized_anxiety_score=mean(GAD_T), satisfaction_with_life_score=mean(SWL_T), social_phobia_score=mean(SPIN_T), hours=mean(Hours)) %>%
  mutate_if(is.numeric, round, digits=2) %>%
  filter(n > 80) %>%
  filter(Residence != 'Unknown')

local
## # A tibble: 22 × 6
##    Residence     n generalized_anxiety_score satisfaction_with_l…¹ socia…² hours
##    <chr>     <dbl>                     <dbl>                 <dbl>   <dbl> <dbl>
##  1 Argentina   102                      4.74                  19.5    18.2  24.1
##  2 Australia   231                      5.09                  19.1    20.2  25.2
##  3 Austria     139                      4.16                  21.7    18.3  22.6
##  4 Belgium     186                      5.16                  19.9    21.3  21.2
##  5 Brazil      245                      5.8                   19.1    23.1  23.6
##  6 Canada      948                      5.18                  19.8    20.3  20.4
##  7 Denmark     241                      4.04                  21.7    16.2  21.2
##  8 Finland     170                      4.73                  20.5    18.0  24.9
##  9 France      371                      4.58                  19.9    19.1  21.4
## 10 Germany    1326                      4.83                  20.1    18.8  21.8
## # … with 12 more rows, and abbreviated variable names
## #   ¹​satisfaction_with_life_score, ²​social_phobia_score
ggplot(local)+
  geom_col(aes(x=reorder(Residence,-generalized_anxiety_score),y=generalized_anxiety_score, fill=-generalized_anxiety_score))+
  labs(title='Average General Anxiety Score Per Residence', subtitle='Collected by Marian Sauter and Dejan Draschkow', x='Residence', y = 'Social Phobia Score')+
  guides(x =  guide_axis(angle = 45))

ggplot(local)+
  geom_col(aes(x=reorder(Residence,-satisfaction_with_life_score),y=satisfaction_with_life_score, fill=satisfaction_with_life_score))+
  labs(title='Average Satisfaction with Life Per Residence', subtitle='Collected by Marian Sauter and Dejan Draschkow', x='Residence', y = 'Average Satisfaction with Life')+
  guides(x =  guide_axis(angle = 45))

ggplot(local)+
  geom_col(aes(x=reorder(Residence,-social_phobia_score),y=social_phobia_score, fill=-social_phobia_score))+
  labs(title='Average Social Phobia Score Per Residence', subtitle='Collected by Marian Sauter and Dejan Draschkow', x='Residence', y = 'Average Social Phobia Score')+
  guides(x =  guide_axis(angle = 45))

ggplot(local)+
  geom_col(aes(x=reorder(Residence,-hours),y=hours, fill=-hours))+
  labs(title='Average Hours Played Each Week Per Residence', subtitle='Collected by Marian Sauter and Dejan Draschkow', x='Residence', y = 'Hours')+
  guides(x =  guide_axis(angle = 45))

#Continuing to explore score breakdowns in different groups
whyplay <- clean_totals %>%
  group_by(whyplay) %>%
  summarise(n=n(),generalized_anxiety_score=mean(GAD_T), satisfaction_with_life_score=mean(SWL_T), social_phobia_score=mean(SPIN_T)) %>%
  mutate_if(is.numeric, round, digits=2) %>%
  filter(n > 35)
#filter(Residence != 'Unknown')

whyplay[order(whyplay$n),]
## # A tibble: 4 × 5
##   whyplay        n generalized_anxiety_score satisfaction_with_life_sc…¹ socia…²
##   <chr>      <dbl>                     <dbl>                       <dbl>   <dbl>
## 1 relaxing     619                      6.31                        18.9    20.6
## 2 winning     1963                      6.16                        18.3    22.1
## 3 improving   4672                      5.25                        19.6    19.5
## 4 having fun  5060                      4.6                         20.7    19.1
## # … with abbreviated variable names ¹​satisfaction_with_life_score,
## #   ²​social_phobia_score
ggplot(whyplay)+
  geom_col(aes(x=reorder(whyplay,-generalized_anxiety_score),y=generalized_anxiety_score, fill=-generalized_anxiety_score))+
  labs(title='Average General Anxiety Score Per Response', subtitle='Collected by Marian Sauter and Dejan Draschkow', x='Reason for Playing', y = 'Social Phobia Score')+
  guides(x =  guide_axis(angle = 45))

ggplot(whyplay)+
  geom_col(aes(x=reorder(whyplay,-satisfaction_with_life_score),y=satisfaction_with_life_score, fill=satisfaction_with_life_score))+
  labs(title='Average Satisfaction with Life Per Response', subtitle='Collected by Marian Sauter and Dejan Draschkow', x='Reason for Playing', y = 'Average Satisfaction with Life')+
  guides(x =  guide_axis(angle = 45))

ggplot(whyplay)+
  geom_col(aes(x=reorder(whyplay,-social_phobia_score),y=social_phobia_score, fill=-social_phobia_score))+
  labs(title='Average Social Phobia Score Per Response', subtitle='Collected by Marian Sauter and Dejan Draschkow', x='Reason for Playing', y = 'Average Social Phobia Score')+
  guides(x =  guide_axis(angle = 45))