2025-04-13

Simple Linear Regression

Linear regression is a statistical technique used to model the relationship between two variables: dependent variable y and independent variable x.

\[ Y = \beta_0 + \beta_1 X + \varepsilon \]

  • \(X\): independent variable (predictor)
  • \(Y\): dependent variable (response)
  • \(\beta_1\): slope
  • \(\beta_0\): y-intercept
  • \(\varepsilon\): error term

Introducing the Data Set

This presentation uses the built-in Tooth Growth dataset to explore the relationship between dose levels of vitamin C (0.5, 1, and 2mg per day), delivery method (orange juice or ascorbic acid), and tooth length in Guinea Pigs.

head(ToothGrowth)
##    len supp dose
## 1  4.2   VC  0.5
## 2 11.5   VC  0.5
## 3  7.3   VC  0.5
## 4  5.8   VC  0.5
## 5  6.4   VC  0.5
## 6 10.0   VC  0.5

Data Overview and Summary Statistics

A data frame with 60 observations on 3 variables.

## 'data.frame':    60 obs. of  3 variables:
##  $ len : num  4.2 11.5 7.3 5.8 6.4 10 11.2 11.2 5.2 7 ...
##  $ supp: Factor w/ 2 levels "OJ","VC": 2 2 2 2 2 2 2 2 2 2 ...
##  $ dose: num  0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ...

-Length (Min: 4.2, Max: 33.9, Median: 19.25) -Supplement Type (OJ or VC, 30 instances of each) -Dose (0.5. 1, or 2; Median: 1)

##       len        supp         dose      
##  Min.   : 4.20   OJ:30   Min.   :0.500  
##  1st Qu.:13.07   VC:30   1st Qu.:0.500  
##  Median :19.25           Median :1.000  
##  Mean   :18.81           Mean   :1.167  
##  3rd Qu.:25.27           3rd Qu.:2.000  
##  Max.   :33.90           Max.   :2.000

Tooth Length vs. Dose Scatterplot

## `geom_smooth()` using formula = 'y ~ x'

Model

  • Slope estimate (\(\beta_1\)): For each 1 mg/day increase in dose, tooth length increases by approximately X mm
## 
## Call:
## lm(formula = len ~ dose, data = ToothGrowth)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.4496 -2.7406 -0.7452  2.8344 10.1139 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   7.4225     1.2601    5.89 2.06e-07 ***
## dose          9.7636     0.9525   10.25 1.23e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.601 on 58 degrees of freedom
## Multiple R-squared:  0.6443, Adjusted R-squared:  0.6382 
## F-statistic: 105.1 on 1 and 58 DF,  p-value: 1.233e-14

Tooth Length by Supplement Type BoxPlot

Model Equation

The estimated regression equation is:

\[ Y = \beta_0 + \beta_1 \cdot \text{dose} \]

Where:
- \(Y\): predicted tooth length
- \(\beta_0\): y-intercept (estimated tooth length when dose = 0)
- \(\beta_1\): slope (change in tooth length for each additional unit of vitamin C dose)

Grouped Bar Chart (plotly)

Findings Summary

The Conclusion

  • Tooth length increases with vitamin C dose, moreso than ascorbic acid
  • Linear relationship is fairly strong