Topics Covered
Adding Covariates
Add nuisance variables (like sex or species) to your model to isolate the primary signal in the penguins dataset.
Residual Analysis
Extract residuals from a linear model using resid(), check for patterns, and use them as "cleaned" variables.
Confound Control
Learn how controlling for underlying confounding factors changes the significance or direction of an effect.
Key Concepts
- Covariates vs. Predictors of Interest: Deciding which variables (e.g.,
island) belong in the model and why. - Partial Correlations: Removing the influence of a third variable to find the true link between flipper and bill lengths.
- Residualizing Approach: Fitting a model, extracting residuals to "regress out" the confound, and analyzing the leftover variance.
Homework
- Fit a model predicting
body_mass_gfromflipper_length_mm, controlling forsexas a covariate. - Extract the residuals from your model and plot them against fitted values to verify assumptions.
- Run a partial correlation between
bill_length_mmandbill_depth_mmwhile controlling forspeciesusing theppcorpackage.