##Part1 Section2: The unit of observation is each person/respondant of the survey. I used the information of the different categories that are specific to respondents of the survey and their characteristics.
library (tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library (ggridges)
load (file = "ATUS_PS3.RData")
glimpse(data)
## Rows: 210,586
## Columns: 29
## $ year <dbl> 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 20…
## $ region <fct> West, West, West, South, South, South, South, Midw…
## $ famincome <fct> "$50,000 to $74,999", NA, "$75,000 to $99,999", "$…
## $ hh_size <dbl> 3, 4, 2, 4, 4, 3, 3, 5, 5, 6, 3, 2, 3, 2, 3, 4, 2,…
## $ hh_child <dbl> 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,…
## $ age <dbl> 60, 41, 26, 36, 51, 32, 44, 21, 33, 39, 26, 33, 42…
## $ gender <fct> Male, Female, Female, Female, Male, Female, Female…
## $ educ <fct> Grad School Grad, Some College, Some College, HS G…
## $ race <fct> Black, White, White, Black, White, White, White, W…
## $ work <fct> Works, Works, Works, Does not Work, Works, Works, …
## $ school <fct> Not Student, Not Student, Not Student, Not Student…
## $ ACT_WORK <dbl> 0.000000, 0.000000, 0.000000, 2.000000, 8.333333, …
## $ ACT_EDUC <dbl> 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.…
## $ ACT_GAMING <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000…
## $ ACT_FOOD <dbl> 0.08333333, 1.50000000, 1.25000000, 0.41666667, 1.…
## $ ACT_PHONE <dbl> 0.00000000, 0.00000000, 1.00000000, 0.00000000, 0.…
## $ ACT_SOCIAL <dbl> 5.416667, 9.833333, 5.666667, 4.416667, 1.000000, …
## $ ACT_TV_VIDEO_STREAM <dbl> 5.416667, 1.000000, 2.000000, 4.416667, 1.000000, …
## $ ACT_SPORTS <dbl> 3.333333, 0.000000, 0.000000, 0.000000, 1.000000, …
## $ ACT_TRAVEL <dbl> 0.0000000, 0.3333333, 0.1666667, 0.0000000, 1.3000…
## $ ACT_VOL <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, …
## $ ACT_RELIG <dbl> 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.…
## $ ACT_PURCH <dbl> 0.00000000, 0.00000000, 1.00000000, 0.00000000, 0.…
## $ ACT_PCARE <dbl> 15.166667, 11.333333, 10.666667, 12.583333, 7.6666…
## $ ACT_HHACT <dbl> 0.0000000, 0.0000000, 4.2500000, 4.5000000, 0.9166…
## $ ACT_HHSERV <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ ACT_GOVSERV <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ ACT_CAREHH <dbl> 0.00000000, 1.00000000, 0.00000000, 0.08333333, 2.…
## $ ACT_CARENHH <dbl> 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.…
View()
##Part2
exdata <- data %>%
filter (age >= 15 & age <= 64) %>%
mutate(ACT_ANYGAMING = if_else(ACT_GAMING > 0, 1, 0))
glimpse (exdata)
## Rows: 168,675
## Columns: 30
## $ year <dbl> 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 20…
## $ region <fct> West, West, West, South, South, South, South, Midw…
## $ famincome <fct> "$50,000 to $74,999", NA, "$75,000 to $99,999", "$…
## $ hh_size <dbl> 3, 4, 2, 4, 4, 3, 3, 5, 5, 6, 3, 2, 3, 2, 3, 4, 2,…
## $ hh_child <dbl> 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,…
## $ age <dbl> 60, 41, 26, 36, 51, 32, 44, 21, 33, 39, 26, 33, 42…
## $ gender <fct> Male, Female, Female, Female, Male, Female, Female…
## $ educ <fct> Grad School Grad, Some College, Some College, HS G…
## $ race <fct> Black, White, White, Black, White, White, White, W…
## $ work <fct> Works, Works, Works, Does not Work, Works, Works, …
## $ school <fct> Not Student, Not Student, Not Student, Not Student…
## $ ACT_WORK <dbl> 0.000000, 0.000000, 0.000000, 2.000000, 8.333333, …
## $ ACT_EDUC <dbl> 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.…
## $ ACT_GAMING <dbl> 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000…
## $ ACT_FOOD <dbl> 0.08333333, 1.50000000, 1.25000000, 0.41666667, 1.…
## $ ACT_PHONE <dbl> 0.00000000, 0.00000000, 1.00000000, 0.00000000, 0.…
## $ ACT_SOCIAL <dbl> 5.416667, 9.833333, 5.666667, 4.416667, 1.000000, …
## $ ACT_TV_VIDEO_STREAM <dbl> 5.416667, 1.000000, 2.000000, 4.416667, 1.000000, …
## $ ACT_SPORTS <dbl> 3.333333, 0.000000, 0.000000, 0.000000, 1.000000, …
## $ ACT_TRAVEL <dbl> 0.0000000, 0.3333333, 0.1666667, 0.0000000, 1.3000…
## $ ACT_VOL <dbl> 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, …
## $ ACT_RELIG <dbl> 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.…
## $ ACT_PURCH <dbl> 0.00000000, 0.00000000, 1.00000000, 0.00000000, 0.…
## $ ACT_PCARE <dbl> 15.166667, 11.333333, 10.666667, 12.583333, 7.6666…
## $ ACT_HHACT <dbl> 0.0000000, 0.0000000, 4.2500000, 4.5000000, 0.9166…
## $ ACT_HHSERV <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ ACT_GOVSERV <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
## $ ACT_CAREHH <dbl> 0.00000000, 1.00000000, 0.00000000, 0.08333333, 2.…
## $ ACT_CARENHH <dbl> 0.00000000, 0.00000000, 0.00000000, 0.00000000, 0.…
## $ ACT_ANYGAMING <dbl> 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1,…
##Part3 c: ANYGAMING_mean means the average likelihood the person does any gaming for each specific age.
plotdata1 <- exdata %>%
group_by (age, gender) %>%
mutate (ANYGAMING_mean = mean(ACT_ANYGAMING))
ggplot(plotdata1, aes(x = age, y = ANYGAMING_mean, color = gender)) + geom_point() + geom_line() + labs (x = "Age", y = "Proportion of Gaming Individuals", title = "Proportion of Gaming Individuals by Age for Americans")
##Part4
exdata2 <- exdata %>%
mutate (period = case_when (year %in% seq (2003, 2005) ~ "03-05",
year %in% seq (2006, 2008) ~ "06-08",
year %in% seq (2009, 2011) ~ "09-11",
year %in% seq (2012, 2014) ~ "12-14",
year %in% seq (2015, 2017) ~ "15-17",
year %in% seq (2018, 2019) ~ "18-19")) %>%
mutate (agegroup = case_when(age %in% seq (15, 30) ~ "Young", age %in% seq (31, 64) ~ "Old")) %>%
mutate (period = as.factor(period)) %>%
mutate (agegroup = as.factor(agegroup))
plotdata2 <- exdata2 %>%
group_by (period, agegroup, gender) %>%
mutate (ANYGAMING_mean = mean(ACT_ANYGAMING))
ggplot (plotdata2,
aes(x = period, y = ANYGAMING_mean,
shape = agegroup, color = gender,
group = interaction(agegroup, gender))) +
geom_line() +
geom_point() +
labs (x = "Time Period", y = "Proportion of gamers", title = "Proportion of gamers vs. Time Period")
##Part5
plotdata3 <- exdata2 %>%
filter (ACT_ANYGAMING == 1) %>%
mutate (ACT_GAMING_wk = (ACT_GAMING * 7))
ggplot (plotdata3,
aes(x = ACT_GAMING_wk, y = gender, fill = gender)) + stat_density_ridges (geom = "density_ridges_gradient", scale = 3, quantiles = c(0.25, 0.5, 0.75)) +
scale_fill_brewer (palette = "Set3") + theme_minimal() + labs (x = "Amount of Time Gaming Per Week", y = "Gender", title = "Amoung of Time Gaming Per Week by Gender")
## Picking joint bandwidth of 1.43
##Part6
plotdata4 <- exdata2 %>%
filter (age %in% 15, 30 & !is.na(famincome)) %>%
group_by (famincome, gender, period) %>%
summarize (ACT_ANYGAMING = mean(ACT_ANYGAMING))
## `summarise()` has grouped output by 'famincome', 'gender'. You can override
## using the `.groups` argument.
ggplot(plotdata4, aes(x = ACT_ANYGAMING, y = famincome, fill = gender)) + geom_col() + facet_wrap (~period) + labs(x = "Count of Gamers", y = "Family Income", title = "Family Income by Count of Gamers by Time Period")
##Part7 Plot 1 shows the proportion of gaming individuals is highest before 20 years old. For males, it has a sharp decline between 10-40 years of age and for females, it remains even between 25-40 years of age. Both genders increase proportion of games from 50-60 years of age. Overall, there are significantly more male gamers than female gamers from 10-40 years old. Plot 2 shows that there are significantly more young male gamers than other demographics in all time periods. Then, the demographics are young females, old females, then old males in descending order make up the lesser proportions of gamers. Plot 3 indicates that for both males and females, the majority spend around 12 hours per week gaming. This gradually decreases for both with more hours per week. Plot 4 shows the distribution of gamers based on family incomes, divided by time period. Males, at all income levels make up a larger share of gamers, however, more females begin gaming in the later periods. Other results are inconclusive.