The language of models

Lecture 14

Dr. Mine Çetinkaya-Rundel

Duke University
STA 199 - Spring 2024

2024-03-05

Warm up

While you wait for class to begin…

Any questions from prepare materials?

Announcements

  • TEAMMATES survey to provide feedback to your teammates deadline extended to tonight (Tuesday, 3/5) till midnight
  • Lab 5 due upon return from Spring Break, 8 am on Monday as usual – help will be available on Ed over the break (though a bit more sporadically)
  • Monday after Spring Break: All team members must be in lab to work on project proposal

Questions from last time

Are there universal standards for ethical data scraping?

How will we be tested on data science ethics?

Goals

  • What is a model?
  • Why do we model?
  • What is correlation?

Setup

library(tidyverse)
library(gt)

Prediction / classification

Let’s drive a Tesla!

Semi or garage?

i love how Tesla thinks the wall in my garage is a semi. 😅

Semi or garage?

New owner here. Just parked in my garage. Tesla thinks I crashed onto a semi.

Car or trash?

Tesla calls Mercedes trash

Description

Leisure, commute, physical activity and BP

Relation Between Leisure Time, Commuting, and Occupational Physical Activity With Blood Pressure in 125,402 Adults: The Lifelines Cohort

Byambasukh, Oyuntugs, Harold Snieder, and Eva Corpeleijn. “Relation between leisure time, commuting, and occupational physical activity with blood pressure in 125 402 adults: the lifelines cohort.” Journal of the American Heart Association 9.4 (2020): e014313.

Leisure, commute, physical activity and BP

Background: Whether all domains of daily‐life moderate‐to‐vigorous physical activity (MVPA) are associated with lower blood pressure (BP) and how this association depends on age and body mass index remains unclear.

Methods and Results: In the population‐based Lifelines cohort (N=125,402), MVPA was assessed by the Short Questionnaire to Assess Health‐Enhancing Physical Activity, a validated questionnaire in different domains such as commuting, leisure‐time, and occupational PA. BP was assessed using the last 3 of 10 measurements after 10 minutes’ rest in the supine position. Hypertension was defined as systolic BP ≥140 mm Hg and/or diastolic BP ≥90 mm Hg and/or use of antihypertensives. In regression analysis, higher commuting and leisure‐time but not occupational MVPA related to lower BP and lower hypertension risk. Commuting‐and‐leisure‐time MVPA was associated with BP in a dose‐dependent manner. β Coefficients (95% CI) from linear regression analyses were −1.64 (−2.03 to −1.24), −2.29 (−2.68 to −1.90), and finally −2.90 (−3.29 to −2.50) mm Hg systolic BP for the low, middle, and highest tertile of MVPA compared with “No MVPA” as the reference group after adjusting for age, sex, education, smoking and alcohol use. Further adjustment for body mass index attenuated the associations by 30% to 50%, but more MVPA remained significantly associated with lower BP and lower risk of hypertension. This association was age dependent. β Coefficients (95% CI) for the highest tertiles of commuting‐and‐leisure‐time MVPA were −1.67 (−2.20 to −1.15), −3.39 (−3.94 to −2.82) and −4.64 (−6.15 to −3.14) mm Hg systolic BP in adults <40, 40 to 60, and >60 years, respectively.

Conclusions: Higher commuting and leisure‐time but not occupational MVPA were significantly associated with lower BP and lower hypertension risk at all ages, but these associations were stronger in older adults.

Modeling

Modeling cars

  • What is the relationship between cars’ weights and their mileage?
  • What is your best guess for a car’s MPG that weighs 3,500 pounds?

Modelling cars

Describe: What is the relationship between cars’ weights and their mileage?

Modelling cars

Predict: What is your best guess for a car’s MPG that weighs 3,500 pounds?

Modelling

  • Use models to explain the relationship between variables and to make predictions
  • For now we will focus on linear models (but there are many many other types of models too!)

Modelling vocabulary

  • Predictor (explanatory variable)
  • Outcome (response variable)
  • Regression line
    • Slope
    • Intercept
  • Correlation

Predictor (explanatory variable)

mpg wt
21 2.62
21 2.875
22.8 2.32
21.4 3.215
18.7 3.44
18.1 3.46
... ...

Outcome (response variable)

mpg wt
21 2.62
21 2.875
22.8 2.32
21.4 3.215
18.7 3.44
18.1 3.46
... ...

Regression line

Regression line: slope

Regression line: intercept

Correlation

Correlation

  • Ranges between -1 and 1.
  • Same sign as the slope.

Visualizing the model

ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  geom_smooth(method = "lm")

Application exercise

Application exercise: ae-10-modeling-fish

  • Go back to your project called ae.
  • If there are any uncommitted files, commit them, and push.
  • Work on ae-10-modeling-fish.qmd.