2025-10-19

<!

Introduction

This presentation is going to be about the relationship between Petal Width and Length using the iris data set. The equation we used to figure out the relationship was a simple linear regression equation. Also used that equation to complete ggplot and plotly visualizations

Data Overview

##   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa

ggplot 1

Linear Model

## 
## Call:
## lm(formula = Petal.Length ~ Petal.Width, data = iris)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.33542 -0.30347 -0.02955  0.25776  1.39453 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.08356    0.07297   14.85   <2e-16 ***
## Petal.Width  2.22994    0.05140   43.39   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4782 on 148 degrees of freedom
## Multiple R-squared:  0.9271, Adjusted R-squared:  0.9266 
## F-statistic:  1882 on 1 and 148 DF,  p-value: < 2.2e-16

Math Explanation (1)

The Simple Linear Regression equation is: Y = b0 + b1 * X + e

where:

\(b_0\) = intercept (value of Y when X = 0) \(b_1\) = slope (how much Y changes when X increases by 1) \(e\) = error (difference between actual and predicted Y)

ggplot2

3D plotly

Math Explanation (2)

We want to know if this is an actual linear relationship between the variables.

We predict that: A \(b_1\) = 0 (not a linear relationship) B \(b_1\) ≠ 0 (linear relaionship)

If the p-value is less than 0.05, we don’t use A, now we know that Petal Width is a important predictor of Petal Length

Prediction

## # A tibble: 3 × 5
##   Petal.Width fit[,"fit"] [,"lwr"] [,"upr"] se.fit    df residual.scale
##         <dbl>       <dbl>    <dbl>    <dbl>  <dbl> <int>          <dbl>
## 1         0.5        2.20     2.20     2.20 0.0531   148          0.478
## 2         1          3.31     3.31     3.31 0.0404   148          0.478
## 3         2          5.54     5.54     5.54 0.0567   148          0.478