Quantifying uncertainty

Lecture 23

Prof. Mine Çetinkaya-Rundel

Duke University
STA 199 - Fall 2026

November 16, 2026

Warm-up

Participate 📱💻

How many people do you think will be in class today?

QR code for Wooclap

Go to wooclap.com and use the code SAXPGIL.

Announcements

  • HW 7 will be posted tomorrow, due Wednesday Dec 2

  • Final exam week:

    • Review session (optional): Monday, Dec 7, 10 am - 11:15 am
    • Office hours schedule will look different (to provide more timely help + accommodate TAs’ final exam schedules), to be posted next week

Quantifying uncertainty

Goal

Find range of plausible values for the slope using bootstrap confidence intervals.

Packages

# load packages
library(tidyverse) # for data wrangling and visualization
library(tidymodels) # for modeling
library(scales) # for pretty axis labels
library(knitr) # for neatly formatted tables

Statistical inference

  • Statistical inference provide methods and tools so we can use the single observed sample to make valid statements (inferences) about the population it comes from

  • For our inferences to be valid, the sample should be random and representative of the population we’re interested in

Soup in a bowl

Inference for simple linear regression

  • Calculate a confidence interval for the slope, \(\beta_1\) (today)

  • Conduct a hypothesis test for the slope,\(\beta_1\) (next week)

Confidence interval for the slope

Confidence interval

  • A plausible range of values for a population parameter is called a confidence interval
  • Using only a single point estimate is like fishing in a murky lake with a spear, and using a confidence interval is like fishing with a net
    • We can throw a spear where we saw a fish but we will probably miss, if we toss a net in that area, we have a good chance of catching the fish
    • Similarly, if we report a point estimate, we probably will not hit the exact population parameter, but if we report a range of plausible values we have a good shot at capturing the parameter

Quantify the variability of the slope

for estimation

  • Two approaches:
    1. Via simulation (what we’ll do in this course)
    2. Via mathematical models (what you can learn about in future courses)
  • Bootstrapping to quantify the variability of the slope for the purpose of estimation:
    • Bootstrap new samples from the original sample
    • Fit models to each of the samples and estimate the slope
    • Use features of the distribution of the bootstrapped slopes to construct a confidence interval

Example: Screen time and sleep

Participate 📱💻

Do you think there’s a relationship between screen time and sleep duration? If so, in which direction?

  • Yes, positive: more screen time, more sleep
  • Yes, negative: more screen time, less sleep
  • No, there’s no relationship
  • Not sure

QR code for Wooclap

Go to wooclap.com and use the code SAXPGIL.

Screen use at bedtime and sleep

Among 79 youths (ages 11-14) in New Zealand whose bedtime screen use was recorded on video, screen use in the 2 hours before bed was not associated with most sleep measures, but every additional 10 minutes of screen time once in bed was associated with about 3 minutes less total sleep.


Brosnan B, Haszard JJ, Meredith-Jones KA, Wickham S, Galland BC, Taylor RW. Screen use at bedtime and sleep duration and quality among youths. JAMA Pediatrics. 2024;178(11):1147-1154. doi:10.1001/jamapediatrics.2024.2914

Smartphone screen time and sleep

Among 653 adults whose smartphone screen time was measured directly by an app over 30 days, longer average screen time was associated with shorter sleep duration and worse sleep efficiency, and screen time around bedtime was associated with poorer sleep quality and taking longer to fall asleep.


Christensen MA, Bettencourt L, Kaye L, Moturu ST, Nguyen KT, Olgin JE, Pletcher MJ, Marcus GM. Direct measurements of smartphone screen-time: Relationships with demographics and sleep. PLOS ONE. 2016;11(11):e0165331. doi:10.1371/journal.pone.0165331

Bedtime screen use behaviors and sleep

Among 10,280 early adolescents (ages 10-14) in the Adolescent Brain Cognitive Development (ABCD) Study, several bedtime screen behaviors, such as leaving a phone ringer on overnight, streaming movies, playing video games, texting, and using social media, were associated with trouble falling or staying asleep.


Nagata JM, Singh G, Yang JH, Smith N, Kiss O, Ganson KT, Testa A, Jackson DB, Baker FC. Bedtime screen use behaviors and sleep outcomes: Findings from the Adolescent Brain Cognitive Development (ABCD) Study. Sleep Health. 2023;9(4):497-502. doi:10.1016/j.sleh.2023.02.005

Goal

What is the relationship between screen time and sleep among Duke students?

  • Data: you! We’ve collected overnight, from some of you, with a Google Form.
  • Population: All Duke undergrads this semester.
  • Sample: The students in this class who fill out the form.

Is this a random sample of Duke undergrads? What, if any, reservations do you have about the representativeness of this sample for all Duke undergrads?

Survey

The data

Code
ggplot(screen_sleep, aes(x = screen, y = sleep)) +
  geom_point(alpha = 0.7) +
  labs(
    x = "Screen time (hours per day)",
    y = "Sleep (hours per night)",
    title = "Screen time and sleep of STA 199 students"
  )

Modeling

screen_sleep_fit <- linear_reg() |>
  fit(sleep ~ screen, data = screen_sleep)

tidy(screen_sleep_fit) |>
  kable(digits = 2)
term estimate std.error statistic p.value
(Intercept) 6.12 0.81 7.53 0.00
screen 0.15 0.12 1.26 0.23

Interpret the slope in context of the data.

For each additional hour of daily screen time, the model predicts students’ nightly sleep to be higher by 0.15 hours, on average.

Bootstrapping a single sample

Bootstrapping many samples

Bootstrap distribution of the slope

set.seed(1116)

# observed slope
obs_fit <- screen_sleep |>
  specify(sleep ~ screen) |>
  fit()

# slopes of 1000 bootstrap samples
boot_fits <- screen_sleep |>
  specify(sleep ~ screen) |>
  generate(reps = 1000, type = "bootstrap") |>
  fit()

95% confidence interval

boot_fits |>
  get_confidence_interval(
    point_estimate = obs_fit,
    level = 0.95,
    type = "percentile"
  ) |>
  kable(digits = 2)
term lower_ci upper_ci
intercept 3.80 7.86
screen -0.09 0.53

Fill in the blanks: We are 95% confident that for each additional hour of daily screen time, the model predicts students’ nightly sleep to be ___ to ___ hours, on average.

Participate 📱💻

The interval includes 0, what does that tell us?

QR code for Wooclap

Go to wooclap.com and use the code SAXPGIL.

Application exercise

  • Go to your ae project in Positron.

  • If you haven’t yet done so, make sure all of your changes up to this point are committed and pushed, i.e., there’s nothing left in your source control pane.

  • If you haven’t yet done so, pull to get today’s application exercise file: ae-XX-???.qmd.

  • Work through the application exercise in class, and render, commit, and push your edits by the end of class.