2025-10-27

Body Mass by Species

Scatterplot Code

3D Plot

Regression Model (Theory)

\[ y_i = \beta_0 + \beta_1 x_i + \varepsilon_i \]

lm_fit <- lm(flipper_length_mm ~ bill_length_mm, data = penguins_clean)
summary(lm_fit)
## 
## Call:
## lm(formula = flipper_length_mm ~ bill_length_mm, data = penguins_clean)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -43.413  -7.837   0.652   8.360  21.321 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    127.3304     4.7291   26.93   <2e-16 ***
## bill_length_mm   1.6738     0.1067   15.69   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 10.63 on 331 degrees of freedom
## Multiple R-squared:  0.4265, Adjusted R-squared:  0.4248 
## F-statistic: 246.2 on 1 and 331 DF,  p-value: < 2.2e-16

Regression plots

Hypothesis testing

## 
##  Welch Two Sample t-test
## 
## data:  flipper_length_mm by species
## t = -33.506, df = 251.35, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group Adelie and group Gentoo is not equal to 0
## 95 percent confidence interval:
##  -28.72740 -25.53771
## sample estimates:
## mean in group Adelie mean in group Gentoo 
##             190.1027             217.2353

Confidence Interval for the Slope

The 95% confidence interval for the slope \(\beta_1\) is given by:

\[ \hat{\beta}_1 \pm t_{n-2,\,0.975} \cdot \text{SE}(\hat{\beta}_1) \]

##                    2.5 %     97.5 %
## (Intercept)    118.02756 136.633237
## bill_length_mm   1.46398   1.883685