A school psychologist wants to know whether recreational screen time relates to anxiety symptoms in adolescents once physical activity and parental monitoring are taken into account, and whether monitoring changes how strongly screen time relates to anxiety.
You have anonymized records for 140 adolescents (13-16 years): weekly screen time, weekly moderate-to-vigorous physical activity, parental monitoring (“High”/“Low”), and an anxiety-symptom score. Set up and interpret the analysis independently, following the same logic as the lab practical – as a model for how to reason through each step, not a template to copy mechanically, since the variables and one of the conclusions differ here.
data/screen_time_anxiety_homework.csv contains 140 rows,
one per adolescent.
| Variable | Type | Description |
|---|---|---|
| adolescent_id | Integer | Anonymous participant identifier, 1-140 |
| screen_time | Continuous | Average daily recreational screen time, in hours |
| physical_activity | Continuous | Hours per week spent in moderate-to-vigorous physical activity |
| monitoring | Categorical (2 levels) | Parent-reported level of monitoring of the adolescent’s screen use: “High” or “Low” |
| anxiety_score | Continuous | Score on a standardized adolescent anxiety-symptom scale, 0-100 |
These questions ask for more independent judgment than the lab
practical. In several places you are asked to choose or justify a step
yourself, rather than being told which one to take. Use
data/screen_time_anxiety_homework.csv.
monitoring group, the mean and standard deviation of
screen_time, physical_activity, and
anxiety_score. Also report the correlation between
screen_time and physical_activity, and explain
what it implies for interpreting a model that includes both.monitoring to the model as a dummy predictor. State
explicitly which level you coded as the reference category and why that
choice does or does not matter for the conclusions you can draw. Report
the coefficient, its test, and the model improvement over Question 3’s
model.d <- read.csv("data/screen_time_anxiety_homework.csv", stringsAsFactors = TRUE)
d$monitoring <- relevel(d$monitoring, ref = "Low")
str(d)
## 'data.frame': 140 obs. of 5 variables:
## $ adolescent_id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ screen_time : num 4.6 3.5 2.3 6.6 5.9 3.8 7 6.6 3.6 4.2 ...
## $ physical_activity: num 5.6 6.8 4.4 4.5 4.5 4.2 8.8 3.3 6.2 7.8 ...
## $ monitoring : Factor w/ 2 levels "Low","High": 2 2 2 2 2 2 2 1 1 1 ...
## $ anxiety_score : num 9.5 26.2 30.6 26 20.3 13.4 23.6 44.4 35.3 48.6 ...
d %>%
group_by(monitoring) %>%
summarise(n = n(),
screen_time_M = mean(screen_time), screen_time_SD = sd(screen_time),
physical_activity_M = mean(physical_activity), physical_activity_SD = sd(physical_activity),
anxiety_score_M = mean(anxiety_score), anxiety_score_SD = sd(anxiety_score)) %>%
kable()
| monitoring | n | screen_time_M | screen_time_SD | physical_activity_M | physical_activity_SD | anxiety_score_M | anxiety_score_SD |
|---|---|---|---|---|---|---|---|
| Low | 75 | 4.368 | 1.618 | 5.023 | 2.649 | 40.25 | 11.22 |
| High | 65 | 4.705 | 1.537 | 4.877 | 2.363 | 23.03 | 10.48 |
cor(d$screen_time, d$physical_activity)
## [1] -0.2336
The negative correlation between screen time and physical activity is modest, consistent with adolescents who spend more time on screens also spending somewhat less time active. It is small enough that entering both predictors together should not create serious collinearity, but it is not negligible, so each coefficient below should still be read as “controlling for the other,” not as if the two predictors were unrelated.
ggplot(d, aes(screen_time, anxiety_score, color = monitoring)) +
geom_point(alpha = 0.75) +
scale_color_manual(values = c("Low" = "grey40", "High" = ntnublue)) +
labs(x = "Daily screen time (hours)", y = "Anxiety score",
title = "Screen time and anxiety score, by parental monitoring level", color = "Monitoring")
m1 <- lm(anxiety_score ~ screen_time, data = d)
summary(m1)
##
## Call:
## lm(formula = anxiety_score ~ screen_time, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -30.972 -9.095 0.285 9.583 30.932
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 20.265 3.398 5.96 2e-08 ***
## screen_time 2.649 0.709 3.74 0.00027 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 13.2 on 138 degrees of freedom
## Multiple R-squared: 0.0918, Adjusted R-squared: 0.0853
## F-statistic: 14 on 1 and 138 DF, p-value: 0.000273
confint(m1)
## 2.5 % 97.5 %
## (Intercept) 13.545 26.984
## screen_time 1.247 4.052
Each additional hour of daily screen time is associated with a 2.65-point increase in predicted anxiety score, on average. The effect is statistically significant, though screen time alone accounts for a modest 9.2% of the variance in anxiety scores.
m2 <- lm(anxiety_score ~ screen_time + physical_activity, data = d)
summary(m2)
##
## Call:
## lm(formula = anxiety_score ~ screen_time + physical_activity,
## data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -31.81 -8.64 0.46 9.14 26.85
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 30.758 4.382 7.02 9.4e-11 ***
## screen_time 2.063 0.700 2.95 0.00377 **
## physical_activity -1.582 0.441 -3.58 0.00047 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 12.7 on 137 degrees of freedom
## Multiple R-squared: 0.17, Adjusted R-squared: 0.158
## F-statistic: 14 on 2 and 137 DF, p-value: 2.93e-06
confint(m2)
## 2.5 % 97.5 %
## (Intercept) 22.0922 39.4228
## screen_time 0.6791 3.4473
## physical_activity -2.4552 -0.7095
anova(m1, m2)
## Analysis of Variance Table
##
## Model 1: anxiety_score ~ screen_time
## Model 2: anxiety_score ~ screen_time + physical_activity
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 138 24219
## 2 137 22142 1 2077 12.8 0.00047 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Physical activity significantly improves the model (\(\Delta R^2\) = 0.078). Its coefficient is negative: each additional hour of weekly moderate-to-vigorous activity is associated with a 1.58-point decrease in predicted anxiety score, holding screen time constant. This is consistent with physical activity being protective against anxiety symptoms, independent of how much time an adolescent spends on screens.
“Low” monitoring is coded as the reference category (0), “High” monitoring as 1. This choice does not change any conclusion about statistical significance or model fit; it only changes the sign and the wording of the monitoring coefficient.
m3 <- lm(anxiety_score ~ screen_time + physical_activity + monitoring, data = d)
summary(m3)
##
## Call:
## lm(formula = anxiety_score ~ screen_time + physical_activity +
## monitoring, data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -22.529 -6.484 0.084 5.562 20.342
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 36.596 3.073 11.91 < 2e-16 ***
## screen_time 2.674 0.487 5.48 2.0e-07 ***
## physical_activity -1.599 0.306 -5.23 6.3e-07 ***
## monitoringHigh -18.351 1.501 -12.23 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.81 on 136 degrees of freedom
## Multiple R-squared: 0.604, Adjusted R-squared: 0.596
## F-statistic: 69.3 on 3 and 136 DF, p-value: <2e-16
confint(m3)
## 2.5 % 97.5 %
## (Intercept) 30.519 42.6733
## screen_time 1.710 3.6376
## physical_activity -2.203 -0.9938
## monitoringHigh -21.319 -15.3823
anova(m2, m3)
## Analysis of Variance Table
##
## Model 1: anxiety_score ~ screen_time + physical_activity
## Model 2: anxiety_score ~ screen_time + physical_activity + monitoring
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 137 22142
## 2 136 10549 1 11593 149 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Adolescents under high parental monitoring scored, on average, 18.35 points lower on the anxiety measure than those under low monitoring, holding screen time and physical activity constant. This is a large association, and adding monitoring more than tripled the variance explained by the model.
lm.beta(m3)
##
## Call:
## lm(formula = anxiety_score ~ screen_time + physical_activity +
## monitoring, data = d)
##
## Standardized Coefficients::
## (Intercept) screen_time physical_activity monitoringHigh
## NA 0.3058 -0.2899 -0.6631
The two continuous predictors have fairly close standardized
associations with anxiety score. lm.beta() also returns a
number for monitoring, but, for the same reason discussed
in the lab practical, it is not interpreted the same way: a dummy
variable’s “standardized coefficient” reflects the arbitrary group split
as much as the effect itself, so the unstandardized group difference
above remains the right way to report the monitoring effect.
par(mfrow = c(2, 2))
plot(m3)
par(mfrow = c(1, 1))
durbinWatsonTest(m3)
## lag Autocorrelation D-W Statistic p-value
## 1 -0.05477 2.085 0.638
## Alternative hypothesis: rho != 0
shapiro.test(resid(m3))
##
## Shapiro-Wilk normality test
##
## data: resid(m3)
## W = 0.99, p-value = 0.9
vif(m3)
## screen_time physical_activity monitoring
## 1.069 1.058 1.011
This is a useful point of contrast with the lab practical, where normality showed a mild, explainable departure: check whether all four LINE assumptions hold comfortably here, or whether a similar issue turns up. It is just as important to correctly conclude “no violation” as it is to correctly detect one.
d$resid_m3 <- resid(m3)
d %>% mutate(abs_resid = abs(resid_m3)) %>%
arrange(desc(abs_resid)) %>%
select(adolescent_id, screen_time, physical_activity, monitoring, anxiety_score, resid_m3) %>%
head(1) %>%
kable()
| adolescent_id | screen_time | physical_activity | monitoring | anxiety_score | resid_m3 |
|---|---|---|---|---|---|
| 92 | 5.4 | 4.1 | High | 3.6 | -22.53 |
cooks <- cooks.distance(m3)
sort(cooks, decreasing = TRUE)[1:5]
## 133 15 43 78 90
## 0.04678 0.04535 0.04113 0.04077 0.03049
m4 <- lm(anxiety_score ~ screen_time * monitoring + physical_activity, data = d)
summary(m4)
##
## Call:
## lm(formula = anxiety_score ~ screen_time * monitoring + physical_activity,
## data = d)
##
## Residuals:
## Min 1Q Median 3Q Max
## -21.88 -5.86 1.07 5.81 20.68
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 33.207 3.650 9.10 1.1e-15 ***
## screen_time 3.398 0.646 5.26 5.5e-07 ***
## monitoringHigh -10.997 4.591 -2.40 0.018 *
## physical_activity -1.553 0.305 -5.10 1.2e-06 ***
## screen_time:monitoringHigh -1.613 0.953 -1.69 0.093 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 8.75 on 135 degrees of freedom
## Multiple R-squared: 0.613, Adjusted R-squared: 0.601
## F-statistic: 53.4 on 4 and 135 DF, p-value: <2e-16
confint(m4)
## 2.5 % 97.5 %
## (Intercept) 25.988 40.4250
## screen_time 2.120 4.6752
## monitoringHigh -20.077 -1.9176
## physical_activity -2.156 -0.9505
## screen_time:monitoringHigh -3.498 0.2708
anova(m3, m4)
## Analysis of Variance Table
##
## Model 1: anxiety_score ~ screen_time + physical_activity + monitoring
## Model 2: anxiety_score ~ screen_time * monitoring + physical_activity
## Res.Df RSS Df Sum of Sq F Pr(>F)
## 1 136 10549
## 2 135 10329 1 219 2.87 0.093 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
b <- coef(m4)
slope_low <- b[["screen_time"]]
slope_high <- b[["screen_time"]] + b[["screen_time:monitoringHigh"]]
c(Low = slope_low, High = slope_high)
## Low High
## 3.398 1.784
Look carefully at the \(p\)-value for the interaction term before interpreting the two simple slopes above. If it is not below the conventional .05 threshold, the correct conclusion is that this sample does not provide statistically significant evidence that the association between screen time and anxiety differs by monitoring level, even if the two simple-slope point estimates look different from each other. The interaction test is exactly the test of whether that apparent difference is larger than what sampling variability alone would produce. In that case, the additive model (Model 3) remains the best-supported description of the data, and it is Model 3’s coefficients that should be the headline results; the simple slopes may be noted as a directional, non-significant observation for future research, but not reported as an established finding.
pa_mean <- mean(d$physical_activity)
newdat <- expand.grid(
screen_time = seq(min(d$screen_time), max(d$screen_time), length.out = 100),
monitoring = levels(d$monitoring),
physical_activity = pa_mean
)
newdat$predicted <- predict(m4, newdata = newdat)
ggplot(newdat, aes(screen_time, predicted, color = monitoring)) +
geom_line(linewidth = 1.2) +
scale_color_manual(values = c("Low" = "grey40", "High" = ntnublue)) +
labs(x = "Daily screen time (hours)", y = "Predicted anxiety score",
title = "Predicted anxiety score by screen time and monitoring level",
subtitle = "Physical activity held at its sample mean", color = "Monitoring")
Daily screen time significantly predicted adolescent anxiety symptoms (Model 1). Physical activity added a significant further contribution, with more activity associated with lower anxiety (Model 2). Parental monitoring level was strongly associated with anxiety after accounting for both, with high-monitoring adolescents scoring lower on average (Model 3). A screen time by monitoring interaction was in the expected direction (a smaller screen-time slope under high monitoring) but should be reported as significant or non-significant strictly according to its own test (Model 4), not according to how different the two simple slopes look. Because screen time, physical activity, and monitoring level were all measured, not manipulated, these results describe associations only; they do not establish that screen time causes anxiety symptoms, or that increasing parental monitoring would reduce them, since unmeasured factors (for example, an adolescent’s baseline anxiety influencing both their screen use and how closely a parent chooses to monitor it) could account for part or all of the observed associations.
Expected answers to the Questions above, reusing the models fitted in the Guided Walkthrough section.
\(N\) = 140 (65 High monitoring, 75 Low monitoring). See the descriptives chunk above for means and SDs by group. \(r\)(screen_time, physical_activity) = -0.234: small enough that entering both predictors together should not create serious collinearity (confirmed by the VIF check below), but not negligible, so each coefficient should be read as controlling for the other.
\(\widehat{anxiety\_score}\) =
20.26 + 2.65 \(\times\) screen_time.
See summary(m1) above for \(SE\), \(t\), \(df\), and \(p\). \(R^2\) = 0.092. Each additional hour of
daily screen time is associated with a 2.65-point increase in predicted
anxiety score, and the effect is significant.
\(R^2\) = 0.17, \(\Delta R^2\) = 0.078. See
anova(m1, m2) above for the full test (residual sums of
squares, \(df\), \(F\), \(p\)). The physical-activity coefficient is
negative (-1.58), consistent with physical activity being protective
against anxiety, independent of screen time.
“Low” monitoring is the reference category (0); this choice
changes only which coefficients are printed and their sign, not the
model’s fit or its substantive conclusions. Monitoring coefficient =
-18.35 (High vs. Low). See summary(m3) and
anova(m2, m3) above for the test statistics and \(\Delta R^2\) (= 0.435).
See the lm.beta(m3) output above. The two continuous
predictors have fairly close standardized associations; the number
lm.beta() returns for the monitoring dummy is
not interpreted the same way, for the reason given in the Guided
Walkthrough (it reflects the group split, not a meaningful “amount” of
the categorical predictor).
See the diagnostic plots and test statistics above. Compare each printed test’s \(p\)-value against .05 and each plot against the pattern expected under no violation; contrast explicitly with the lab practical’s mild normality departure.
See the largest residual chunk above: report the
identified adolescent_id and compare its Cook’s distance
against the conventional concern threshold of 1.0 (and against the other
largest values printed) to judge influence, not the residual
alone.
See summary(m4) and anova(m3, m4) above
for the interaction coefficient and its test.
If the interaction \(p\)-value from Question 8 is not below .05 (as is the case for this dataset), the correct conclusion is that the data do not provide significant evidence that monitoring moderates the screen-time effect. It is not appropriate to present the two simple slopes as a confirmed pattern; the additive model (Model 3) remains the best-supported description, and any mention of the directionally different slopes must be clearly flagged as non-significant and exploratory, not reported as a finding.
See the Reporting the results paragraph above for a model answer, including the explicit non-causal caveat given that screen time, physical activity, and monitoring were all measured rather than manipulated.
Common errors and points to watch for
sessionInfo()
## R version 4.4.2 (2024-10-31)
## Platform: aarch64-apple-darwin20
## Running under: macOS 26.6.2
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: Europe/Oslo
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.51 car_3.1-5 carData_3.0-6 lm.beta_1.7-3 lubridate_1.9.5 forcats_1.0.1 stringr_1.6.0
## [8] dplyr_1.2.0 purrr_1.2.1 readr_2.2.0 tidyr_1.3.2 tibble_3.3.1 ggplot2_4.0.2 tidyverse_2.0.0
## [15] pacman_0.5.1
##
## loaded via a namespace (and not attached):
## [1] gtable_0.3.6 jsonlite_2.0.0 compiler_4.4.2 tidyselect_1.2.1 jquerylib_0.1.4 scales_1.4.0
## [7] yaml_2.3.12 fastmap_1.2.0 R6_2.6.1 labeling_0.4.3 generics_0.1.4 Formula_1.2-5
## [13] tzdb_0.5.0 bslib_0.10.0 pillar_1.11.1 RColorBrewer_1.1-3 rlang_1.1.7 stringi_1.8.7
## [19] cachem_1.1.0 xfun_0.57 sass_0.4.10 S7_0.2.1 otel_0.2.0 timechange_0.4.0
## [25] cli_3.6.5 withr_3.0.2 magrittr_2.0.4 digest_0.6.39 grid_4.4.2 xtable_1.8-8
## [31] rstudioapi_0.18.0 hms_1.1.4 lifecycle_1.0.5 vctrs_0.7.2 evaluate_1.0.5 glue_1.8.0
## [37] farver_2.1.2 abind_1.4-8 rmarkdown_2.30 tools_4.4.2 pkgconfig_2.0.3 htmltools_0.5.9