These slides show the relationship between screen time and sleep duration
2025-06-02
These slides show the relationship between screen time and sleep duration
We model this relationship using a simple linear regression:
\[ y = \beta_0 + \beta_1 x + \epsilon \] where:
\(y\): Sleep Duration (hours)
\(x\): Screen Time (hours)
\(\beta_0\): Intercept (expected sleep when screen time is 0)
\(\beta_1\): Slope (change in sleep for each additional hour of screen time)
\(\varepsilon\): Random error term
This model estimates how changes in screen time affect sleep
The average sleep duration is calculated with this formula:
\[ \bar{y} = \frac{1}{n} \sum_{i=1}^{n} y_i \] where:
\(\bar{y}\): Average sleep duration
\(y_i\): Sleep duration for individual \(i\)
\(n\): Total number of individuals
library(plotly)
set.seed(42)
df = data.frame(
ScreenTime = runif(100, 0, 12),
Sleep = rnorm(100, mean = 8, sd = 1.5) - 0.3 * runif(100, 0, 12),
Age = runif(100, 10, 60)
)
plot_ly(df, x = ~ScreenTime, y = ~Age, z = ~Sleep,
type = "scatter3d", mode = "markers",
marker = list(size = 3, color = ~Sleep, colorscale = "Viridis")) %>%
layout(scene = list(
xaxis = list(title = "Screen Time (hours)"),
yaxis = list(title = "Age"),
zaxis = list(title = "Sleep Duration (hours)")
))