Import Data

data <- read_excel("../00_data/MyData.xlsx")
data
## # A tibble: 32 × 7
##    Team               `Avg Home Capacity`    PF    PD   SoS    WL Playoffs  
##    <chr>                            <dbl> <dbl> <dbl> <dbl> <dbl> <chr>     
##  1 Arizona Cardinals                0.967   361   -81   1.8 0.344 None      
##  2 Atlanta Falcons                  1.01    381   -18   1.1 0.438 None      
##  3 Baltimore Ravens*                0.995   531   249   0.1 0.875 Divisional
##  4 Buffalo Bills+                   0.961   314    55  -1.3 0.625 Wildcard  
##  5 Carolina Panthers                0.965   340  -130   1.1 0.313 None      
##  6 Chicago Bears                    1.01    280   -18   0.2 0.5   None      
##  7 Cincinnati Bengals               0.720   279  -141   1.5 0.125 None      
##  8 Cleveland Browns                 1       335   -58   1.7 0.375 None      
##  9 Dallas Cowboys                   1.14    434   113  -1.8 0.5   None      
## 10 Denver Broncos                   0.998   282   -34   0   0.438 None      
## # ℹ 22 more rows

Questions

How do NFL teams’ scored points (PF) affect their performance?

Variation

ggplot(data = data) +
  geom_histogram(mapping = aes(x = PF))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Visualizing distributions

data %>%
    ggplot(aes(x = PF)) +
    geom_histogram(binwidth = 12.5)

Covariation

A categorical and continuous variable

ggplot(data = data, mapping = aes(x = Playoffs, y = PF)) +
  geom_boxplot()

Two continous variables

ggplot(data = data) +
  geom_point(mapping = aes(x = PF, y = WL)) +
    geom_smooth(aes(x = PF, y = WL))
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

Patterns and models

library(modelr)
## Warning: package 'modelr' was built under R version 4.4.3
mod <- lm(log(WL) ~ log(PF), data = data)

PF_Mod <- data %>%
    modelr::add_residuals(mod) %>%
    mutate(resid = exp(resid))

PF_Mod %>%
    ggplot(aes(WL, resid)) +
    geom_point() +
    geom_smooth()
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'