The language of models

Lecture 15

Dr. Mine Çetinkaya-Rundel

Duke University
STA 199 - Fall 2022

10/20/22

Warm up

While you wait for class to begin…

Clone your ae-12 project from GitHub, render your document, update your name, and commit and push.

Announcements

  • Project proposals due Friday

Goals

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

Setup

library(tidyverse)
library(gt)

Modelling

Modelling cars

  • What is the relationship between cars’ weights and their mileage?
  • What is your best guess for a car’s MPG that weighs 5000 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

ae-12

  • Go to the course GitHub org and find your ae-12 (repo name will be suffixed with your GitHub name).
  • Clone the repo in your container, open the Quarto document in the repo, and follow along and complete the exercises.
  • Render, commit, and push your edits by the AE deadline – 3 days from today.