AI summary by TwinMind
Multiple Regression in R, Step by Step!!!
StatQuest with Josh Starmer
7m 42s
Introduction & Setup
- StatQuest tutorial by Josh Starmer from UNC Chapel Hill Genetics Department
- R code available on statquest.org
- Continuation from previous multiple regression StatQuest
- Dataset: mouse measurements (size, weight, tail)
Simple Regression Analysis
- Objective: predict size using weight alone
- Step 1: Always plot data first
- X-axis: weight, Y-axis: size
- Visual inspection confirms linear relationship exists
- Plotting essential to validate regression approach
- Step 2: Use LM (linear model) function
- Syntax: size ~ weight (tilde separates dependent/independent variables)
- R automatically adds y-intercept and slope terms
- Uses least squares to minimize squared residuals
- Results:
- R-squared = 0.613
- P-value = 0.012
- Weight does "pretty good job" predicting size
- For simple regression, use multiple R-squared (not adjusted)
- Visualization: Added regression line using abline function
Multiple Regression Analysis
- Objective: predict size using both weight and tail
- Step 1: Plot all variables
- R generates matrix of all pairwise plots when X/Y not specified
- Shows size vs weight, size vs tail, weight vs tail relationships
- Key findings:
- Both weight and tail correlate with size (good predictors)
- Weight and tail correlate with each other (provide similar information)
- Suggests might only need one predictor, not both
- Step 2: Use LM function for multiple regression
- Syntax: size ~ weight + tail (plus symbol adds variables)
- R adds y-intercept, slope1, slope2 terms automatically
- Fits plane (not line) to data
Multiple Regression Results Analysis
- Overall model performance: good R-squared, adjusted R-squared, p-value
- Key insight: For multiple regression, focus on adjusted R-squared
- Model comparisons (more interesting section):
- Weight + tail vs tail alone: p-value shows NOT significantly better
- Weight + tail vs weight alone: p-value shows IS significantly better
- Conclusion:
- Using weight + tail is good overall
- Could save time by using only tail length (skip weighing mice)
- Tail alone sufficient predictor vs weight alone
Practical Recommendations
- Multiple regression with both variables performs well
- Tail-only model viable time-saving alternative
- Weight-only model significantly inferior to combined model
