if (!require("pacman")) install.packages("pacman")Loading required package: pacman
library(pacman)
p_load(tidyverse, lme4, marginaleffects, glmmTMB, mice, modelsummary)if (!require("pacman")) install.packages("pacman")Loading required package: pacman
library(pacman)
p_load(tidyverse, lme4, marginaleffects, glmmTMB, mice, modelsummary)diary <- read_csv("data/synthetic/data-synthetic-clean/synDiaryClean.csv.gz") # requires that the preprocessing script has been runRows: 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.
nin <- 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.
xbox <- 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.
steam <- 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.
dat <- diary |>
left_join(intake |> select(pid, age, gender, eduLevel, employment),
by = "pid"
) |>
mutate(pid = as.character(pid)) |>
# this is needed otherwise nlme and marginaleffects don't play nicely
mutate(
gender = factor(gender),
eduLevel = factor(eduLevel),
employment = factor(employment),
day = factor(day)
)There’s a flukey result here wherein gameNS_cw and globalNS are negatively related, even though these variables have nothing to do with each other in the sim. We weren’t able to diagnose yet whether this is simulation problem or a bug elsewhere, but will continue investigating prior to the collection of human data and update accordingly.
Experiences of gaming feed into and co-constitute experiences of life as a whole—experiences with games are one (greater or lesser) element of lives in general. Thus, H6 in BANG predicts: Greater in-game need satisfaction is associated with greater global need satisfaction.
We model this with a multilevel within-between linear regression whereby game-level need satisfaction (within- and between-centered; gameNS_cw and gameNS_cb) predicts deviation from a person’s typical globalNS (globalNS, with a random intercept and slope), and an AR(1) autocorrelation term.
h1mod <- glmmTMB(globalNS ~ gameNS_cw + gameNS_cb + (1 + gameNS_cw | pid) + ar1(day + 0 | pid),
data = dat
)
plot_predictions(h1mod, condition = "gameNS_cw", vcov = TRUE)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.
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.

Experiences of need satisfaction during a particular gaming session lead players to update expectations for future experiences with the current game, similar games, and gaming as a whole, such that greater need satisfaction leads to higher expectations for future need satisfaction. Under BANG, need-related outcome expectations are conceptually similar to intrinsic motivation, and the behavioral product of these expectations is therefore greater behavioral engagement.
Thus, the model attempts to evaluate whether experiencing high game-level need satisfaction in one’s most recent session is linked with a higher likelihood of playing games again in the 24-hour period after the survey.
Another factor that might increase the likelihood that someone (re)turns to gaming is global need frustration. SDT predicts that (global) need frustration results in compensatory behavior—people attempt to replenish needs that are not being met by altering their behavior. The dense need satisfaction offered by games constitute one way for people to compensate. BANG operationalizes this compensatory play in via intrinsic motivation. Frustrated needs in one’s life in general make opportunities to fulfill those needs more salient, which—all else equal—manifests phenomenologically as an increased energy towards those activities. Given this, we predict: Global need frustration is associated with higher likelihood of playing in the 24-hour period after survey completion (H9 in BANG)
As they share an outcome variable, we model these together. We model these with a multilevel within-between logistic regression, where in-game need satisfaction and global need frustration (each within- and between-person centered; gameNS_cw, gameNS_cb, globalNF_cw, globalNF_cb) predict playedAfterSurvey, a binary variable indicating whether any play happened in the 24-hour period after diary survey completion.
As before, we include an AR(1) term to account for the fact that likelihood of play might be autocorrelated (if, e.g., people tend to get on a roll and play multiple days in a row).
h2mod <- glmmTMB(
playedLaterAny ~ gameNS_cw + gameNS_cb + globalNF_cw + globalNF_cb +
(1 + gameNS_cw + globalNF_cw | pid) + ar1(day + 0 | pid),
data = dat,
family = binomial(link = "logit"),
dispformula = ~1,
ziformula = ~0
)Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in (function (start, objective, gradient = NULL, hessian = NULL, :
NA/NaN function evaluation
Warning in finalizeTMB(TMBStruc, obj, fit, h, data.tmb.old): Model convergence
problem; non-positive-definite Hessian matrix. See vignette('troubleshooting')
Warning in finalizeTMB(TMBStruc, obj, fit, h, data.tmb.old): Model convergence
problem; false convergence (8). See vignette('troubleshooting'),
help('diagnose')
summary(h2mod) Family: binomial ( logit )
Formula:
playedLaterAny ~ gameNS_cw + gameNS_cb + globalNF_cw + globalNF_cb +
(1 + gameNS_cw + globalNF_cw | pid) + ar1(day + 0 | pid)
Data: dat
AIC BIC logLik -2*log(L) df.resid
NA NA NA NA 6956
Random effects:
Conditional model:
Groups Name Variance Std.Dev. Corr
pid (Intercept) 1.041e+00 1.020e+00
gameNS_cw 5.539e-04 2.353e-02 -1.00
globalNF_cw 1.891e-03 4.348e-02 -1.00 1.00
pid.1 day1 2.574e-301 5.074e-151 1.00 (ar1)
Number of obs: 6969, groups: pid, 973
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.19893 0.04339 -4.584 4.55e-06 ***
gameNS_cw 0.01046 0.02527 0.414 0.6787
gameNS_cb -0.28593 0.11770 -2.429 0.0151 *
globalNF_cw -0.03673 0.03942 -0.932 0.3514
globalNF_cb 0.02890 0.22880 0.126 0.8995
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot_predictions(h2mod, condition = "globalNF_cw", vcov = TRUE)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.
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.
The variance-covariance matrix is not positive definite. Returning the
nearest positive definite matrix now.
This ensures that eigenvalues are all positive real numbers, and
thereby, for instance, it is possible to calculate standard errors for
all relevant parameters.

plot_predictions(h2mod, condition = "gameNS_cw", vcov = TRUE)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.
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.
The variance-covariance matrix is not positive definite. Returning the
nearest positive definite matrix now.
This ensures that eigenvalues are all positive real numbers, and
thereby, for instance, it is possible to calculate standard errors for
all relevant parameters.

The above models are fit to 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 Study 1 tests, here we simulate a dataset with a known relationship between need satisfaction in games and need satisfaction in daily life, and then fit H1 as above (selecting just one hypothesis for detailed inspection to illustrate).
# sim parameters
n_pid <- 1000
n_days <- 21
beta_0 <- 2.0 # global intercept
beta_cw <- 0.1 # global slope for within-person
beta_cb <- 0.1 # global slope for between-person
sigma_cw <- .5
sigma_intercept <- 1.0 # Random intercept SD
sigma_slope <- 0.5 # Random slope SD
sigma_residual <- 1 # Residual SD
rho <- 0.2 # AR(1) autocorrelation coefficient
sim_s1 <- dat |>
group_by(pid) |>
mutate(
random_intercept = rnorm(1, mean = 0, sd = sigma_intercept),
random_slope = rnorm(1, mean = 0, sd = sigma_slope),
gameNS_cb = rnorm(1)
) |>
ungroup() |>
mutate(
gameNS_cw = rnorm(n(), mean = 0, sd = sigma_cw),
)
# Generate AR(1) errors for each individual
sim_s1$residual <- unlist(lapply(1:n_pid, function(i) {
arima.sim(n = n_days, model = list(ar = rho), sd = sigma_residual)
}))
# Generate the response variable based on the model
sim_s1 <- sim_s1 |>
mutate(globalNS = beta_0 + random_intercept + (beta_cw + random_slope)*gameNS_cw + beta_cb * gameNS_cb + residual)
h1mod <- glmmTMB(globalNS ~ gameNS_cw + gameNS_cb + (1 + gameNS_cw| pid) + ar1(as.factor(day) + 0 | pid),
data = sim_s1
)
summary(h1mod) Family: gaussian ( identity )
Formula:
globalNS ~ gameNS_cw + gameNS_cb + (1 + gameNS_cw | pid) + ar1(as.factor(day) +
0 | pid)
Data: sim_s1
AIC BIC logLik -2*log(L) df.resid
62925.1 62996.7 -31453.6 62907.1 20991
Random effects:
Conditional model:
Groups Name Variance Std.Dev. Corr
pid (Intercept) 0.9569 0.9782
gameNS_cw 0.2391 0.4890 -0.08
pid.1 as.factor(day)1 0.8515 0.9227 0.25 (ar1)
Residual 0.1839 0.4289
Number of obs: 21000, groups: pid, 1000
Dispersion estimate for gaussian family (sigma^2): 0.184
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.01394 0.03215 62.64 < 2e-16 ***
gameNS_cw 0.07916 0.02089 3.79 0.000151 ***
gameNS_cb 0.02039 0.03163 0.64 0.519074
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot_predictions(h1mod, condition = "gameNS_cw", vcov = TRUE, re.form = NA) +
ylim(1, 5)
confint(h1mod)[2,3] - confint(h1mod)[2,2][1] -0.04094002