March 17, 2024

simple linear regression equations

\(\hat{\beta_0}\) = \(\overline{y}\) - \(\hat{\beta_1}\) \(\overline{x}\)

\(\hat{\beta_1}\) = \(\frac{SS_{xy}}{SS_{xx}}\)

\(SS_{E}\) = \(SS_{T}\) - \(\hat{\beta_1}S_{xy}\)

coefficient of determination : \(R^{2}\)

\(R^{2}\) is the fraction of variability that can be accounted for

\(0 \le R^{2} \le 1\)

\(R^{2}\) = \(\frac{SS_{R}}{SS_{T}}\) = 1 - \(\frac{SS_{E}}{SS_{T}}\)

R is the estimate of the correlation, \({\rho}\)

\(-1 \le R \le 1\)

\(-1 \le {\rho} \le 1\)

data set

##   Sepal.Length    Sepal.Width     Petal.Length    Petal.Width   
##  Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100  
##  1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300  
##  Median :5.800   Median :3.000   Median :4.350   Median :1.300  
##  Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199  
##  3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800  
##  Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500  
##        Species  
##  setosa    :50  
##  versicolor:50  
##  virginica :50  
##                 
##                 
## 

ggplot pt 1

code for previous slide

ggplot(
  aes(x = Sepal.Width, y = Petal.Length, color = Species), 
  data = iris) +
  geom_point(aes(shape = Species), size = 2) +
  geom_smooth(method = "lm", se = FALSE) +
  xlab("Sepal Width") +
  ylab("Petal Length") +
  scale_color_manual(
    values = c("cyan4", "olivedrab", "orchid4"), 
    labels = c("setosa", "versicolor", "virginca")) +
  scale_shape_manual(values = c(1, 2, 5)) +
  facet_wrap(~ Species) +
  labs(
    title = "Relationship between Sepal Width and Petal Length 
    with Linear Regression Line"
    )

ggplot pt 2

plotly plot