2026-10-18

Models and Formulas (Latex 1)

Population regression model with normally distributed errors \[ y_i = \beta_0 + \beta_1 x_i + \varepsilon_i, \qquad \varepsilon_i \sim N(0, \sigma^2), \qquad i = 1 \dots n \]

Mean (population) regression line \[ E[y \mid x] = \beta_0 + \beta_1 x \]

Sum of squared residuals, minimized by least squares \[ S(\beta_0, \beta_1) = \sum_{i=1}^{n} \left( y_i - \beta_0 - \beta_1 x_i \right)^2 \]

Least squares estimates: slope and intercept (respectively) \[ \hat\beta_1 = \frac{\sum_{i=1}^{n} (x_i - \bar x)(y_i - \bar y)}{\sum_{i=1}^{n} (x_i - \bar x)^2} = \frac{S_{xy}}{S_{xx}}, \qquad \hat\beta_0 = \bar y - \hat\beta_1 \bar x \]

Fitted values and residuals \[ \hat y_i = \hat\beta_0 + \hat\beta_1 x_i, \qquad e_i = y_i - \hat y_i \]

Star Wars Dataset Overview

name height mass birth_year species
Jabba Desilijic Tiure 175 1358 600.0 Hutt
Grievous 216 159 NA Kaleesh
IG-88 200 140 15.0 Droid
Darth Vader 202 136 41.9 Human
Tarfful 234 136 NA Wookiee
Owen Lars 178 120 52.0 Human

Height vs Mass (Ggplot 1)

Height vs Mass: Without Jabba the Hutt (Ggplot 2)

Linear Regression for Graph 2 (R-code)

fit <- lm(mass ~height, data = sw)
fit_no_jabba <- lm(mass ~ height, data = graph2)
coef(fit)
## (Intercept)      height 
## -11.4868157   0.6240033
coef(fit_no_jabba)
## (Intercept)      height 
## -31.2504692   0.6127301
graph2 <- filter(sw, mass < 1000)
ggplot(graph2, aes(x=height, y=mass)) + 
geom_point(color="darkblue", size = 3) +
geom_smooth(method = "lm", se = TRUE, color = "gold")+
labs(x="Height (cm)", y="Mass (kg)")+
theme_minimal(base_size = 14)

Model Performance and Evaluation

Fit Quality w and w/o Jabba \[ R^2_{\text{with Jabba}}= 0.017 \qquad R^2_{\text{without Jabba}}= 0.564 \]

Regression Results for Ggplot 2

Estimate Standard Error t-value p-value 95% CI
(Intercept) -31.250 12.815 -2.44 1.79e-02 (-56.92,-5.58)
height 0.613 0.072 8.51 1.14e-11 (0.47,0.76)

Analyzing the Graphs (Latex 2)

Prediction Formula \[ \widehat{\text{mass}}= -31.25 + 0.613 \cdot \text{height} \]

Hypothesis Test \[ H_0: \beta_1 = 0\quad\text{vs} \quad H_1:\beta_1 \neq 0 \] Test Statistic t, Standard Error of the line, & Variance Estimation (Respectively) \[ t = \frac{\hat\beta_1}{\operatorname{SE}(\hat\beta_1)} \sim t_{n-2} \qquad \operatorname{SE}(\hat\beta_1)= \sqrt{\frac{\hat\sigma^2}{S_{xx}}}, \qquad \hat\sigma^2= \frac{1}{n-2}\sum_{i=1}^n e_i^2 \]

95% Confidence Interval for the Slope \[ CI = \hat{\beta}_1 \pm t_{(\alpha/2,\;n-2)} SE(\hat{\beta}_1) \]

Adding a Z-axis: Comparing Height, Age, and Mass (Plotly)