2025-10-19

Math 1: a straight line

We’ll use a straight line to predict \(y\) from \(x\): \[ y = b_0 + b_1 x \] - \(b_0\): where the line hits the \(y\)-axis
- \(b_1\): slope (how much \(y\) changes when \(x\) goes up by 1)

Math 2: mean and sd

Given numbers \(x_1,\dots,x_n\): \[ \bar{x}=\frac{1}{n}\sum_{i=1}^n x_i, \qquad s=\sqrt{\frac{1}{n-1}\sum_{i=1}^n (x_i-\bar{x})^2} \]

ggplot 1: mpg vs weight

ggplot 2: mpg histogram

plotly: 3D scatter

Scatter + fitted line (trees)

plot(Volume ~ Girth, data = datasets::trees, pch = 19)
mod <- lm(Volume ~ Girth, data = datasets::trees)
abline(mod, col = "red")

summary(mod)
## 
## Call:
## lm(formula = Volume ~ Girth, data = datasets::trees)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -8.065 -3.107  0.152  3.495  9.587 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -36.9435     3.3651  -10.98 7.62e-12 ***
## Girth         5.0659     0.2474   20.48  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.252 on 29 degrees of freedom
## Multiple R-squared:  0.9353, Adjusted R-squared:  0.9331 
## F-statistic: 419.4 on 1 and 29 DF,  p-value: < 2.2e-16

Handling NAs quickly (airquality)