7  Study 3: Genres and wellbeing

Note

TODOs:

The following to-dos are suggestions for how to improve the analysis in this notebook after data collection:

- Include iOS and android data.

- Potentially upgrade the data aggregation logic to merge Steam game sessions if they are consecutive and for the same game (can’t be done now because of how the titles are always generated to be different).

7.1 Load libraries and data

if (!require("pacman")) install.packages("pacman")
Loading required package: pacman
library(pacman)

p_load(knitr, tidyverse, dplyr, lme4, marginaleffects, interactions, data.table, readr, datawizard, kableExtra, R.utils, modelsummary, 
       multcomp, emmeans, car)

set.seed(8675309)

clean_string <- function(text) {
  text <- tolower(text)
  text <- gsub("[^a-z0-9 ]", "", text)
  text <- gsub("[ /]+", "_", text)
  text <- gsub("^_|_$", "", text)
  return(text)
}
panel <- fread("data/synthetic/data-synthetic-clean/synPanelClean.csv.gz") |> 
  mutate(
    start_date = case_when(
      wave == 1 ~ as.Date("2024-05-01"),
      wave == 2 ~ as.Date("2024-05-15"),
      wave == 3 ~ as.Date("2024-05-29"),
      wave == 4 ~ as.Date("2024-06-12"),
      wave == 5 ~ as.Date("2024-06-26"),
      wave == 6 ~ as.Date("2024-07-10")
    ),
    end_date = start_date + 13  # Each wave covers a 14-day period
  )

diary <- read_csv("data/synthetic/data-synthetic-clean/synDiaryClean.csv.gz")
Rows: 21000 Columns: 88
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (29): played24hr, socialGaming_4, socialGaming_5, socialGaming_6, socia...
dbl  (51): pid, day, bangs_1, bangs_2, bangs_3, bangs_4, bangs_5, bangs_6, l...
lgl   (6): missingDiary, displacedCoreDomain, playedLaterNintendo, playedLat...
dttm  (1): surveyCompletionTime
date  (1): date

ℹ 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.
intake <- read_csv("data/synthetic/data-synthetic-clean/synIntakeClean.csv.gz")
Rows: 2000 Columns: 82
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (54): region, gender, employment, employment_7_TEXT, eduLevel, neuroIden...
dbl (22): pid, age, weight, height#1_1_1, height#1_1_2, playProp_1, playProp...
lgl  (6): playProp_7, playsSwitch, playsXbox, playsSteam, iOSuser, androidUser

ℹ 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.
ninRaw <- read_csv("data/synthetic/data-synthetic-clean/synNintendoClean.csv.gz")
Rows: 19542 Columns: 10
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (3): titleID, genre, platform
dbl  (4): pid, day, session, duration
dttm (2): sessionStart, sessionEnd
date (1): date

ℹ 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.
xboxRaw <- read_csv("data/synthetic/data-synthetic-clean/synXboxClean.csv.gz") 
Rows: 42646 Columns: 10
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (3): titleID, genre, platform
dbl  (4): pid, day, session, duration
dttm (2): sessionStart, sessionEnd
date (1): date

ℹ 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.
steamRaw <- read_csv("data/synthetic/data-synthetic-clean/synSteamClean.csv.gz")
Rows: 65792 Columns: 12
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (3): genre, Name, platform
dbl  (6): pid, day, hour, persona, minutes, AppID
dttm (2): sessionStart, sessionEnd
date (1): date

ℹ 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.
iOSRaw <- read_csv("data/synthetic/data-synthetic-raw/syniOS.csv.gz")
Rows: 16836 Columns: 19
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr   (1): platform
dbl  (15): pid, week, Entertainment, Social, Information & Reading, Games, P...
lgl   (2): missing, dropout
date  (1): date

ℹ 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.
androidRaw <- read_csv("data/synthetic/data-synthetic-raw/synAndroid.csv.gz")
Rows: 1001307 Columns: 11
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (5): app, sessionStart, sessionEnd, category, platform
dbl  (5): pid, day, numDailyAppSessions, session, duration
date (1): date

ℹ 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.

7.2 Merge data

We also perform some simple preprocessing here:

- We create a start_date and end_date column in the panel data to represent the start and end of each wave.

- We separate the genre column in the Nintendo, Xbox, and Steam data into five separate columns.

- Xbox and Nintendo have roughly 4000 unique genres, which is too many to work with. We recode these into a smaller number of genres by separating the primary genres from the sub genres.

In contrast to Xbox and Nintendo data, Steam data is not session-level; rather, it is a total amount of time spent playing each game during the previous hour. So to calculate how much time each player spent playing each genre each day and create a variable for how many sessions, we need to recode the data to match the format of the other two datasets.

nin <- ninRaw |> 
  mutate(sessionEnd = sessionStart + minutes(round(duration)), .after = sessionStart) |> 
  separate(genre, into = c("genre1", "genre2", "genre3", "genre4", "genre5"), sep = ",", fill = "right")

xbox <- xboxRaw |> 
  mutate(sessionEnd = sessionStart + minutes(round(duration)), .after = sessionStart) |> 
  separate(genre, into = c("genre1", "genre2", "genre3", "genre4", "genre5"), sep = ",", fill = "right")

steam <- steamRaw |>
  rename(
    duration = minutes,
    titleID = Name,
  ) |> 
  mutate(sessionStart = date + hours(hour)) |> 
  separate(genre, into = c("genre1", "genre2", "genre3", "genre4", "genre5"), sep = ",", fill = "right") |> 
  group_by(pid, date) |>                    # Group by player ID and date
  mutate(session = row_number()) |>         # Create a sequential session number
  ungroup()       

telemetry <- bind_rows(nin, xbox, steam) |> 
  group_by(pid, genre1) |>
  mutate(previous_day_duration = lag(duration, 1)) |>
  ungroup()

7.3 Aggregate telemetry data

Aggregate playtime by genre within each wave for each participant, in wide format.

aggregated_playtime <- telemetry |>
  mutate(wave = case_when(
    date >= as.Date("2024-05-01") & date <= as.Date("2024-05-14") ~ 1,
    date >= as.Date("2024-05-15") & date <= as.Date("2024-05-28") ~ 2,
    date >= as.Date("2024-05-29") & date <= as.Date("2024-06-11") ~ 3,
    date >= as.Date("2024-06-12") & date <= as.Date("2024-06-25") ~ 4,
    date >= as.Date("2024-06-26") & date <= as.Date("2024-07-09") ~ 5,
    date >= as.Date("2024-07-10") & date <= as.Date("2024-07-23") ~ 6
  )) %>%
  mutate(across(starts_with("genre"), ~clean_string(.))) |> 
  group_by(pid, wave, genre1) |>
  filter(duration < 720) |> 
  summarise(time = sum(duration/14/60, na.rm = TRUE), .groups = "drop") |> # Calculate total time per genre as hours per day 
  pivot_wider(
    names_from = genre1, 
    values_from = time, 
    values_fill = 0, # Fill missing values with 0
    names_prefix = "time_"
  ) %>%
  mutate(
    total_time_all_genres = rowSums(dplyr::select(., starts_with("time_")), na.rm = TRUE), # Calculate total time as hours per day 
    across(starts_with("time_"), ~ . / total_time_all_genres, .names = "prop_{.col}"), # Calculate proportion of time for each genre
  )

# get the variable names
genre_vars <- aggregated_playtime |> 
  dplyr::select(starts_with("time_")) |> 
  colnames()

# demean
aggregated_playtime <- datawizard::demean(aggregated_playtime, 
                                          select = c(genre_vars, "total_time_all_genres"), 
                                          by = "pid") |> 
  left_join(panel, by = c("pid", "wave"))

7.4 Analysis

Data is analyzed using a multilevel model to account for the nested structure of the data, where repeated measurements (6 bi-weekly waves) are nested within participants. In this analysis, we examine the relationship between playtime and well-being, as well as how this relationship is moderated by genre. We test two hypotheses: H1. The overall effect of playtime on well-being H2. Genre moderates the relationship between playtime and well-being.

7.5 H1. The overall effect of playtime on wellbeing

To test the hypothesis that playtime is associated with well-being, we fit a random effects model with random intercepts and slopes for total playtime within and between genres. We then conduct an equivalence test to determine if the effect of playtime on well-being is within a predefined equivalence margin.

h1_total_time <- lmer(
  wemwbs ~ total_time_all_genres_within + total_time_all_genres_between + (1 + total_time_all_genres_within | pid), 
  data = aggregated_playtime
)
boundary (singular) fit: see help('isSingular')
# Custom formatting function for scientific notation
scientific_fmt <- function(x) {
  formatC(x, format = "e", digits = 3)}  # Show numbers in scientific notation with 3 significant digits

# Summarize the model using modelsummary
modelsummary(
  list(`Model H1` = h1_total_time),
  fmt = scientific_fmt,
  estimate  = "{estimate} [{conf.low}, {conf.high}]{stars}", 
  statistic = NULL
)
Model H1
(Intercept) 2.992e+00 [2.970e+00, 3.014e+00]***
total_time_all_genres_within -5.747e-03 [-3.739e-02, 2.590e-02]
total_time_all_genres_between 2.548e-03 [-1.706e-02, 2.215e-02]
SD (Intercept pid) 1.053e-02 [ NA, NA]
SD (total_time_all_genres_within pid) 2.828e-02 [ NA, NA]
Cor (Intercept~total_time_all_genres_within pid) -1.000e+00 [ NA, NA]
SD (Observations) 5.360e-01 [ NA, NA]
Num.Obs. 7411
R2 Marg. 0.000
AIC 11827.5
BIC 11875.9
RMSE 0.54

This equivalence test is a way to formally test if the within-person effect of total playtime is small enough to be considered equivalent to zero, within a predefined practical margin. If the test confirms equivalence, it strengthens the argument that the effect of playtime on the outcome is negligible or irrelevant.

7.5.1 Equivalence test

hypotheses(h1_total_time, "total_time_all_genres_within = 0", equivalence = c(-.06, .06))
Warning: For this model type, `marginaleffects` only takes into account the
uncertainty in fixed-effect parameters. This is often appropriate when
`re.form=NA`, but may be surprising to users who set `re.form=NULL` (default)
or to some other value. Call `options(marginaleffects_safe = FALSE)` to silence
this warning.

                     Hypothesis Estimate Std. Error      z Pr(>|z|)   S   2.5 %
 total_time_all_genres_within=0 -0.00575     0.0161 -0.356    0.722 0.5 -0.0374
 97.5 % p (NonSup) p (Equiv)
 0.0259     <0.001    <0.001

7.6 H2. Genres differ in how playtime relates to fluctuations in general mental wellbeing over a 2-week period (H2a, “within-person”) and to average wellbeing over the full study period (H2b, “between-person”).

Multilevel within-between linear regression whereby playtime per genre (within- and between-centered) during the previous 2 weeks predicts wellbeing (WEMWBS), with a random intercept and random slopes for within-person variables. Due to identifiability issues with the high number of coefficients, we will fix the correlation between random intercept and random slope to 0.

7.6.1 REWB model

For H2 and H3, we fit a single model with random slopes for each genre within and between genres. This model allows us to estimate the effect of each genre on well-being, while accounting for the nested structure of the data. We can then conduct pairwise comparisons to determine which genres have a significant effect on well-being.

Interpretations:

  • time_*_between: “Group-level effect”: People who play x + 1 units more of genre_* report higher/lower wemwbs scores
  • time_*_within: “Within-person effect”: During a period when people play x + 1 units more of genre_* they report higher/lower wemwbs scores
# get the variable names
genre_within_vars <- aggregated_playtime |>
  dplyr::select(ends_with(c("_within"))) |>
  dplyr::select(-total_time_all_genres_within) |> 
  colnames() |>
  sort()

genre_between_vars <- aggregated_playtime |>
  dplyr::select(ends_with(c("_between"))) |>
  dplyr::select(-total_time_all_genres_between) |> 
  colnames() |>
  sort()

genre_vars_demean <- c(genre_within_vars, genre_between_vars)

## rewb
fit_h2_rewb <- lmer(
  paste(
      "wemwbs ~", paste(genre_vars_demean, collapse = "+"),
      "+ (1 | pid)"
    ),
  aggregated_playtime
)
boundary (singular) fit: see help('isSingular')
# Summarize the model using modelsummary
modelsummary(
  list(`Model H2` = fit_h2_rewb),
  fmt = scientific_fmt,
  estimate  = "{estimate} [{conf.low}, {conf.high}]{stars}", 
  statistic = NULL
)
Model H2
(Intercept) 2.987e+00 [2.963e+00, 3.011e+00]***
time_action_within -3.853e-02 [-1.371e-01, 6.007e-02]
time_adventure_within -6.869e-02 [-1.892e-01, 5.184e-02]
time_arcade_within -9.326e-03 [-1.663e-01, 1.476e-01]
time_card_board_game_within -1.536e-03 [-1.526e-01, 1.495e-01]
time_casual_within -2.672e-01 [-6.950e-01, 1.606e-01]
time_fighting_within -7.379e-02 [-2.286e-01, 8.105e-02]
time_hack_and_slashbeat_em_up_within 5.607e-02 [-1.075e-01, 2.197e-01]
time_indie_within -3.125e-01 [-9.225e-01, 2.975e-01]
time_moba_within -4.532e-02 [-1.991e-01, 1.084e-01]
time_music_within 2.338e-01 [7.528e-02, 3.922e-01]**
time_platform_within 1.012e-01 [-5.509e-02, 2.576e-01]
time_puzzle_within -6.681e-02 [-2.344e-01, 1.008e-01]
time_racing_within -6.856e-03 [-1.652e-01, 1.515e-01]
time_real_time_strategy_rts_within 1.428e-02 [-1.397e-01, 1.683e-01]
time_roleplaying_rpg_within -1.309e-03 [-1.542e-01, 1.516e-01]
time_shooter_within 4.741e-02 [-1.091e-01, 2.039e-01]
time_simulator_within -5.865e-02 [-2.123e-01, 9.503e-02]
time_sport_within -5.587e-02 [-2.166e-01, 1.048e-01]
time_strategy_within -1.123e-01 [-2.658e-01, 4.115e-02]
time_tactical_within -4.489e-02 [-1.957e-01, 1.059e-01]
time_turnbased_strategy_tbs_within 5.993e-02 [-9.384e-02, 2.137e-01]
time_visual_novel_within 6.599e-02 [-9.045e-02, 2.224e-01]
time_action_between -9.239e-04 [-8.611e-02, 8.426e-02]
time_adventure_between 1.422e-01 [-1.130e-01, 3.974e-01]
time_arcade_between -3.321e-02 [-3.746e-01, 3.082e-01]
time_card_board_game_between -3.027e-01 [-6.151e-01, 9.573e-03]+
time_casual_between -1.045e-01 [-1.060e+00, 8.515e-01]
time_fighting_between 3.661e-01 [2.111e-02, 7.111e-01]*
time_hack_and_slashbeat_em_up_between 1.035e-01 [-2.736e-01, 4.806e-01]
time_indie_between 5.497e-01 [-7.194e-01, 1.819e+00]
time_moba_between 7.722e-02 [-2.687e-01, 4.232e-01]
time_music_between 2.227e-01 [-1.165e-01, 5.620e-01]
time_platform_between -3.897e-02 [-3.873e-01, 3.094e-01]
time_puzzle_between -1.758e-01 [-5.439e-01, 1.924e-01]
time_racing_between 2.282e-01 [-1.294e-01, 5.858e-01]
time_real_time_strategy_rts_between -3.111e-01 [-6.528e-01, 3.056e-02]+
time_roleplaying_rpg_between 1.995e-03 [-3.482e-01, 3.522e-01]
time_shooter_between -1.979e-01 [-5.477e-01, 1.519e-01]
time_simulator_between 1.838e-01 [-1.814e-01, 5.489e-01]
time_sport_between -1.335e-01 [-4.927e-01, 2.256e-01]
time_strategy_between -2.206e-01 [-5.606e-01, 1.194e-01]
time_tactical_between 2.097e-01 [-1.393e-01, 5.586e-01]
time_turnbased_strategy_tbs_between -3.492e-02 [-3.701e-01, 3.003e-01]
time_visual_novel_between -5.597e-02 [-3.870e-01, 2.751e-01]
SD (Intercept pid) 0.000e+00 [ NA, NA]
SD (Observations) 5.362e-01 [ NA, NA]
Num.Obs. 7411
R2 Marg. 0.006
AIC 11955.5
BIC 12280.3
RMSE 0.53
Note
  • Not possible to model all genre_*_within as random. Unidentifiable model.

Ideally, the demeaned variables should be included as random slopes. However, this will likely lead to identifiability issues. This code shows how we can fit a model with random slopes, but without a correlation between slopes and intercepts; as this takes a long time to run, we do not execute it here.

# fit model
fit_h2_rewb_re_slopes <- lmer(
  paste(
      "wemwbs ~", paste(genre_vars_demean, collapse = "+"),
      "+ (1 +",
      paste(genre_within_vars, collapse = "+"),
      "|| pid)"
    ),
  aggregated_playtime
)

# Summarize the model using modelsummary
modelsummary(
  list(`Model H2` = fit_h2_rewb_re_slopes),
  fmt = scientific_fmt,
  estimate  = "{estimate} [{conf.low}, {conf.high}]{stars}", 
  statistic = NULL
)

7.6.2 Joint hypothesis test

We will conduct a joint Wald test on the coefficients in the above model. A joint test simultaneously assesses multiple related hypotheses, allowing us to determine whether the playtime effects for any of the 23 genres differ significantly from each other (H3). The joint test the estimated coefficients and their covariance matrix to determine if a set of parameters jointly equals specified value; this test follows the chi-squared distribution (Wald, 1943). The error rate is controlled in a similar manner as would be achieved by correcting the alpha level for all 23 surrogate hypotheses (García-Pérez, 2023).

# test against null of all coefficients being equal
linearHypothesis(fit_h2_rewb, paste0(genre_within_vars[1], " = ", genre_within_vars[2:length(genre_within_vars)]))

Linear hypothesis test:
time_action_within - time_adventure_within = 0
time_action_within - time_arcade_within = 0
time_action_within - time_card_board_game_within = 0
time_action_within - time_casual_within = 0
time_action_within - time_fighting_within = 0
time_action_within - time_hack_and_slashbeat_em_up_within = 0
time_action_within - time_indie_within = 0
time_action_within - time_moba_within = 0
time_action_within - time_music_within = 0
time_action_within - time_platform_within = 0
time_action_within - time_puzzle_within = 0
time_action_within - time_racing_within = 0
time_action_within - time_real_time_strategy_rts_within = 0
time_action_within - time_roleplaying_rpg_within = 0
time_action_within - time_shooter_within = 0
time_action_within - time_simulator_within = 0
time_action_within - time_sport_within = 0
time_action_within - time_strategy_within = 0
time_action_within - time_tactical_within = 0
time_action_within - time_turnbased_strategy_tbs_within = 0
time_action_within - time_visual_novel_within = 0

Model 1: restricted model
Model 2: wemwbs ~ time_action_within + time_adventure_within + time_arcade_within + 
    time_card_board_game_within + time_casual_within + time_fighting_within + 
    time_hack_and_slashbeat_em_up_within + time_indie_within + 
    time_moba_within + time_music_within + time_platform_within + 
    time_puzzle_within + time_racing_within + time_real_time_strategy_rts_within + 
    time_roleplaying_rpg_within + time_shooter_within + time_simulator_within + 
    time_sport_within + time_strategy_within + time_tactical_within + 
    time_turnbased_strategy_tbs_within + time_visual_novel_within + 
    time_action_between + time_adventure_between + time_arcade_between + 
    time_card_board_game_between + time_casual_between + time_fighting_between + 
    time_hack_and_slashbeat_em_up_between + time_indie_between + 
    time_moba_between + time_music_between + time_platform_between + 
    time_puzzle_between + time_racing_between + time_real_time_strategy_rts_between + 
    time_roleplaying_rpg_between + time_shooter_between + time_simulator_between + 
    time_sport_between + time_strategy_between + time_tactical_between + 
    time_turnbased_strategy_tbs_between + time_visual_novel_between + 
    (1 | pid)

  Df  Chisq Pr(>Chisq)
1                     
2 21 20.385      0.497
linearHypothesis(fit_h2_rewb, paste0(genre_between_vars[1], " = ", genre_between_vars[2:length(genre_between_vars)]))

Linear hypothesis test:
time_action_between - time_adventure_between = 0
time_action_between - time_arcade_between = 0
time_action_between - time_card_board_game_between = 0
time_action_between - time_casual_between = 0
time_action_between - time_fighting_between = 0
time_action_between - time_hack_and_slashbeat_em_up_between = 0
time_action_between - time_indie_between = 0
time_action_between - time_moba_between = 0
time_action_between - time_music_between = 0
time_action_between - time_platform_between = 0
time_action_between - time_puzzle_between = 0
time_action_between - time_racing_between = 0
time_action_between - time_real_time_strategy_rts_between = 0
time_action_between - time_roleplaying_rpg_between = 0
time_action_between - time_shooter_between = 0
time_action_between - time_simulator_between = 0
time_action_between - time_sport_between = 0
time_action_between - time_strategy_between = 0
time_action_between - time_tactical_between = 0
time_action_between - time_turnbased_strategy_tbs_between = 0
time_action_between - time_visual_novel_between = 0

Model 1: restricted model
Model 2: wemwbs ~ time_action_within + time_adventure_within + time_arcade_within + 
    time_card_board_game_within + time_casual_within + time_fighting_within + 
    time_hack_and_slashbeat_em_up_within + time_indie_within + 
    time_moba_within + time_music_within + time_platform_within + 
    time_puzzle_within + time_racing_within + time_real_time_strategy_rts_within + 
    time_roleplaying_rpg_within + time_shooter_within + time_simulator_within + 
    time_sport_within + time_strategy_within + time_tactical_within + 
    time_turnbased_strategy_tbs_within + time_visual_novel_within + 
    time_action_between + time_adventure_between + time_arcade_between + 
    time_card_board_game_between + time_casual_between + time_fighting_between + 
    time_hack_and_slashbeat_em_up_between + time_indie_between + 
    time_moba_between + time_music_between + time_platform_between + 
    time_puzzle_between + time_racing_between + time_real_time_strategy_rts_between + 
    time_roleplaying_rpg_between + time_shooter_between + time_simulator_between + 
    time_sport_between + time_strategy_between + time_tactical_between + 
    time_turnbased_strategy_tbs_between + time_visual_novel_between + 
    (1 | pid)

  Df  Chisq Pr(>Chisq)
1                     
2 21 23.343      0.326

7.6.3 Plot all estimates

Here we plot the estimates for the genre effects on well-being, along with both uncorrected (95%) confidence intervals, and the corrected confidence intervals from multcomp::glht.

The confidence intervals are particularly wide because there is no true covariation in the data, and the model is trying to estimate the effect of each genre on well-being while accounting for the nested structure of the data. We anticipate smaller CIs in the true data.

corrected_cis <- confint(multcomp::glht(fit_h2_rewb, linfct = paste0(genre_within_vars, " = -.06")),
                         adjusted(type = .)) |> 
  tidy()

tests <- tidy(fit_h2_rewb, conf.int = TRUE) |> 
  filter(grepl("within", term)) |> 
  rename(conf.low.uncorrected = conf.low, conf.high.uncorrected = conf.high) |>
  left_join(corrected_cis, by = c("term" = "contrast"))

# we can also calculate CIs for marginal effects; for mean+1 contrasts these are functionally identical in our models.
# ests_fit_h2_rewb <- avg_comparisons(fit_h2_rewb) |>
#   as.data.frame()

tests |> 
  ggplot(aes(estimate.x, term)) +
  geom_linerange(
    aes(xmin = conf.low, xmax = conf.high),
    linewidth = .5
  ) +
  geom_linerange(
    aes(xmin = conf.low.uncorrected, xmax = conf.high.uncorrected),
    linewidth = 1
  ) +
  geom_point() +
  geom_vline(xintercept = -.06, linetype = "dashed") +
  geom_vline(xintercept = .06, linetype = "dashed")

7.7 Precision Analysis

In the above examples, we use the simulated data, which mirrors the structure of the true data, but lacks control over the distribution and relationships between the particular variables used in this study. To provide rough indications of the estimated precision of our tests, here we simulate a dataset with a known relationship between playtime and wellbeing, and then fit the models as above.

We arbitrarily assume that the effect of an hour of daily play in each genre on wellbeing varies from -.2 to .2, consisting of both a within-person and between-person component; this would produce a roughly null relationship on average but significant for particular genres. We specify a within-person SD for the WEMWBS of .7 based on prior literature [@BallouEtAl2024Registered]. The distribution of playtime is realistic based on the parameters in 0_generateSyntheticData.qmd; although the distribution of genres is more even than likely in the true dataset.

genre_coefs <- runif(length(genre_vars), -.2, .2)
names(genre_coefs) <- genre_vars

sim_study3 <- aggregated_playtime |> 
  dplyr::select(pid, wave, contains("time"), wemwbs) %>%
  group_by(pid) |>
  mutate(
    random_intercept = rnorm(n(), mean = 0, sd = .6),
    random_slope = rnorm(n(), mean = 0, sd = .2)
  ) |> 
  ungroup() |> 
  mutate(wemwbs_mean = rowSums(across(time_action:time_indie, ~ .x * (random_slope + genre_coefs[[cur_column()]]))),
         wemwbs = rnorm(n(), mean = random_intercept + wemwbs_mean, sd = .7))

h1_total_time <- lmer(
  wemwbs ~ total_time_all_genres_within + total_time_all_genres_between + (1 + total_time_all_genres_within | pid), 
  data = sim_study3
)
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
unable to evaluate scaled gradient
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge: degenerate Hessian with 1 negative eigenvalues
summary(h1_total_time)
Linear mixed model fit by REML ['lmerMod']
Formula: 
wemwbs ~ total_time_all_genres_within + total_time_all_genres_between +  
    (1 + total_time_all_genres_within | pid)
   Data: sim_study3

REML criterion at convergence: 31763.1

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-3.6562 -0.6525  0.0021  0.6768  4.1053 

Random effects:
 Groups   Name                         Variance  Std.Dev. Corr
 pid      (Intercept)                  2.560e-08 0.00016      
          total_time_all_genres_within 7.481e-02 0.27352  0.16
 Residual                              8.967e-01 0.94697      
Number of obs: 11586, groups:  pid, 1998

Fixed effects:
                              Estimate Std. Error t value
(Intercept)                    0.01602    0.01585   1.011
total_time_all_genres_within  -0.04115    0.02494  -1.650
total_time_all_genres_between -0.03407    0.01425  -2.391

Correlation of Fixed Effects:
                 (Intr) ttl_tm_ll_gnrs_w
ttl_tm_ll_gnrs_w  0.000                 
ttl_tm_ll_gnrs_b -0.832  0.000          
optimizer (nloptwrap) convergence code: 0 (OK)
unable to evaluate scaled gradient
Model failed to converge: degenerate  Hessian with 1 negative eigenvalues
# fit model
fit_h2_rewb_sim <- lmer(
  paste(
      "wemwbs ~", paste(genre_vars_demean, collapse = "+"),
      "+ (1 | pid)"
    ),
  sim_study3
)
boundary (singular) fit: see help('isSingular')
summary(fit_h2_rewb_sim)
Linear mixed model fit by REML ['lmerMod']
Formula: 
wemwbs ~ time_action_within + time_adventure_within + time_arcade_within +  
    time_card_board_game_within + time_casual_within + time_fighting_within +  
    time_hack_and_slashbeat_em_up_within + time_indie_within +  
    time_moba_within + time_music_within + time_platform_within +  
    time_puzzle_within + time_racing_within + time_real_time_strategy_rts_within +  
    time_roleplaying_rpg_within + time_shooter_within + time_simulator_within +  
    time_sport_within + time_strategy_within + time_tactical_within +  
    time_turnbased_strategy_tbs_within + time_visual_novel_within +  
    time_action_between + time_adventure_between + time_arcade_between +  
    time_card_board_game_between + time_casual_between + time_fighting_between +  
    time_hack_and_slashbeat_em_up_between + time_indie_between +  
    time_moba_between + time_music_between + time_platform_between +  
    time_puzzle_between + time_racing_between + time_real_time_strategy_rts_between +  
    time_roleplaying_rpg_between + time_shooter_between + time_simulator_between +  
    time_sport_between + time_strategy_between + time_tactical_between +  
    time_turnbased_strategy_tbs_between + time_visual_novel_between +  
    (1 | pid)
   Data: sim_study3

REML criterion at convergence: 31761.1

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-3.8321 -0.6546  0.0062  0.6714  3.9299 

Random effects:
 Groups   Name        Variance Std.Dev.
 pid      (Intercept) 0.0000   0.0000  
 Residual             0.9051   0.9514  
Number of obs: 11586, groups:  pid, 1998

Fixed effects:
                                        Estimate Std. Error t value
(Intercept)                           -1.043e-02  1.735e-02  -0.601
time_action_within                     7.743e-02  7.018e-02   1.103
time_adventure_within                 -1.274e-01  8.810e-02  -1.446
time_arcade_within                    -1.668e-01  1.115e-01  -1.496
time_card_board_game_within           -1.589e-01  1.126e-01  -1.411
time_casual_within                     1.594e-02  3.146e-01   0.051
time_fighting_within                   2.237e-01  1.146e-01   1.952
time_hack_and_slashbeat_em_up_within   1.676e-01  1.193e-01   1.405
time_indie_within                     -3.761e-02  4.461e-01  -0.084
time_moba_within                      -1.471e-01  1.148e-01  -1.282
time_music_within                      2.291e-01  1.159e-01   1.976
time_platform_within                  -3.389e-01  1.135e-01  -2.987
time_puzzle_within                    -5.568e-02  1.184e-01  -0.470
time_racing_within                    -1.582e-01  1.152e-01  -1.374
time_real_time_strategy_rts_within     1.771e-01  1.099e-01   1.612
time_roleplaying_rpg_within            5.071e-03  1.134e-01   0.045
time_shooter_within                   -2.291e-01  1.162e-01  -1.971
time_simulator_within                 -1.444e-01  1.117e-01  -1.293
time_sport_within                     -1.291e-01  1.169e-01  -1.104
time_strategy_within                  -1.586e-01  1.134e-01  -1.398
time_tactical_within                   9.175e-02  1.110e-01   0.827
time_turnbased_strategy_tbs_within    -1.349e-01  1.127e-01  -1.197
time_visual_novel_within              -1.398e-01  1.142e-01  -1.224
time_action_between                    1.092e-01  6.171e-02   1.769
time_adventure_between                -6.008e-02  1.857e-01  -0.324
time_arcade_between                   -4.366e-01  2.471e-01  -1.767
time_card_board_game_between           1.034e-01  2.285e-01   0.453
time_casual_between                    6.267e-01  6.902e-01   0.908
time_fighting_between                 -2.066e-01  2.494e-01  -0.829
time_hack_and_slashbeat_em_up_between  2.859e-01  2.734e-01   1.046
time_indie_between                    -1.397e+00  9.522e-01  -1.467
time_moba_between                     -1.941e-01  2.547e-01  -0.762
time_music_between                     1.842e-01  2.487e-01   0.741
time_platform_between                 -6.746e-02  2.506e-01  -0.269
time_puzzle_between                   -4.591e-01  2.661e-01  -1.725
time_racing_between                   -1.331e-02  2.608e-01  -0.051
time_real_time_strategy_rts_between    1.430e-01  2.457e-01   0.582
time_roleplaying_rpg_between           1.934e-01  2.568e-01   0.753
time_shooter_between                  -1.251e-01  2.568e-01  -0.487
time_simulator_between                -6.421e-02  2.529e-01  -0.254
time_sport_between                    -8.085e-02  2.580e-01  -0.313
time_strategy_between                  3.248e-02  2.534e-01   0.128
time_tactical_between                  4.194e-01  2.573e-01   1.630
time_turnbased_strategy_tbs_between   -2.560e-06  2.453e-01   0.000
time_visual_novel_between             -4.075e-01  2.435e-01  -1.673

Correlation matrix not shown by default, as p = 45 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
tidy(fit_h2_rewb_sim, conf.int = TRUE) |>
  ggplot(aes(estimate, term)) +
  geom_linerange(
    aes(xmin = conf.low, xmax = conf.high),
    linewidth = .5
  ) +
  geom_point() +
  geom_vline(xintercept = -.06, linetype = "dashed") +
  geom_vline(xintercept = .06, linetype = "dashed")
Warning: Removed 2 rows containing missing values or values outside the scale range
(`geom_segment()`).