Slide 1: Introduction

Simple linear regression involves the use of an equation for prediction of a 1st order dependent variable based on an independent variable.

Its purpose in to uncover relationships between variables and make predictions for hypothetical or future values.

Slide 2: Model Format

Simple linear regression follows the format of the following formula:

\[\hat{y} = \beta_0 + \beta_1x\]

where

  • \(\hat{y}\) represents the expected value for the dependent variable
  • \(x\) represents the observed value of the independent variable
  • \(\beta_0\) represents the intercept
  • \(\beta_1\) represents the slope

Slide 3: Sample Calculation

Let’s say we are attempting to determine the score on an exam based on the number of hours the student studied.

If we were given the following formula:

\[\hat{y} = 52 + 12x\]

we could then determine how the expected score for a student who studied for 3 hours:

\[\hat{y} = 52 + 12 \cdot 3 = 88\]

Thus, based on our hypothetical model, a student who studies 3 hours for the exam is expected to score an 88%.

Slide 4: Model Interpretations

In our previous model, interpretations can be made of the y-intercept and slope of the best-fit line, also know as the Least-Squares Regression Line (LSRL).

Here is the equation again:

\[\hat{y} = 52 + 12x\]

The model interpretations are as follows:

Intercept: If the student studies for 0 hours, we would expect the student to get a 52% on the exam.

Slope: For each additional hour studied, we would expect the student’s exam score to increase by 12%.

Slide 5: Flower Sample ggplot Graph

Now, let’s try an example with the flower data.

ggplot(aes(x = weight, y = shootarea), data = flower) + geom_point() + 
  geom_smooth(method = "lm", se = T, color = "#a8c88f") +
   labs(x = "Weight (kg)", y = expression("Shoot Area (cm"^2~")"))

The graph appears to be approximately linear, with a strong positive correlation, and no outliers.

Slide 6: Diamond Sample ggplot Graph

Let’s seek another example, now with the diamond data.

ggplot(aes(x = carat, y = price), data = diamonds) + geom_point() + 
  geom_smooth(method = "lm", se = T, color = "#ff307d") + 
  labs(x = "Carat", y = "Price (USD)")

The graph appears to be approximately linear, with a strong positive correlation, and an outlier with about 5 carats and a high value.

Slide 7: Iris Sample plotly Graph

A similar graph to the previous one can be made using plotly instead of ggplot.

plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, type = 'scatter', 
        mode = 'markers') %>%
  add_trace(type = 'scatter', mode = 'lines', x = ~Sepal.Length,
            y = ~fitted(lm(Petal.Length ~ Sepal.Length, data = iris)),
            line = list(color = '#7a42f4')) %>%
  layout(xaxis = list(title = "Sepal Length (cm)"), 
         yaxis = list(title = "Petal Length (cm)"))

Slide 8: Correlation Coefficient

While one can guess at the effectiveness of the model, there is actually a numerical measurement that can help analysis, called the correlation coefficient (\(r\)).

\(-1 \leq r \leq 1\)

If \(|r| = 1\), then perfectly correlated

If \(|r| = 0\), then no correlation

Slide 9: Correlation Coefficient Example

One can easily calculate the correlation coefficient in R.

cor.test(iris$Sepal.Length, iris$Petal.Length)
## 
##  Pearson's product-moment correlation
## 
## data:  iris$Sepal.Length and iris$Petal.Length
## t = 21.646, df = 148, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.8270363 0.9055080
## sample estimates:
##       cor 
## 0.8717538

Here, the correlation coefficient is 0.872, which is relatively high, indicating the linear model is a good fit for the data.