2026-03-08

What is Simple Linear Regression?

Simple linear regression is a statistical method used to study the relationship between two quantitative variables.

It uses one variable to predict another:

  • Predictor variable: \(X\)
  • Response variable: \(Y\)

In this example:

  • \(X\) = Temperature
  • \(Y\) = Ozone

Regression Equation

The simple linear regression model is:

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

Where:

  • \(Y\) is the response variable
  • \(X\) is the predictor variable
  • \(\beta_0\) is the intercept
  • \(\beta_1\) is the slope
  • \(\epsilon\) is the error term

Example for Simple Linear Regression

Example: Temperature and Ozone Levels

This presentation explains simple linear regression using temperature as the predictor variable and ozone as the response variable.

Example Dataset (Using Air Quality)

##   Ozone Temp
## 1    41   67
## 2    36   72
## 3    12   74
## 4    18   62
## 6    28   66
## 7    23   65

Regular Scatterplot

Regression Line

Interactive Plotly

I tried everything, when I use htmlwidgets lib it works, but not on rpub. This is the code, I hope I can get partial credit at least.

plotly::plot_ly(
  data = aq,
  x = ~Temp,
  y = ~Ozone,
  type = "scatter",
  mode = "markers",
  marker = list(size = 8)
) %>%
  plotly::layout(
    title = "Interactive Plot of Ozone vs Temperature",
    xaxis = list(title = "Temperature (F)"),
    yaxis = list(title = "Ozone")
  )

Estimated Regression Equation-

## (Intercept)        Temp 
## -146.995491    2.428703

The fitted model can be written as:

\[ \hat{Y} = \hat{\beta}_0 + \hat{\beta}_1 X \]

This equation predicts ozone based on temperature.

R Code Example:

This is the code that was used to make the regular scatterplot:

ggplot(aq, aes(x = Temp, y = Ozone)) +
  geom_point(color = "darkred", alpha = 0.7) +
  labs(
    title = "Scatterplot of Ozone vs Temperature",
    x = "Temperature (F)",
    y = "Ozone"
  )

Interpretation:

The slope tells us how much predicted ozone changes for a one-degree increase in temperature.

A positive slope indicates that higher temperatures are associated with higher ozone levels on average.

Conclusion

Simple linear regression is useful for understanding and quantifying relationships between variables.

Using the airquality dataset, this example suggests a positive relationship between temperature and ozone levels.