What is Simple Linear Regression?

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

\[ y = \beta_0 + \beta_1\cdot x + \varepsilon \] where:

  • \(x\) = predictor variable
  • \(y\) = response variable
  • \(\beta_0\) = intercept
  • \(\beta_1\) = slope
  • \(\varepsilon\) = random error
  • \(R^2\) = proportion of variation in the response explained by the model

Mammal Sleep Data

The msleep dataset is from the ggplot2 package. It contains sleep and and biological information for 83 mammals.

Question: What is the relationship between the amount of REM sleep and total sleep in mammals?

  • Predictor: REM sleep (sleep_rem)
  • Response: Total sleep (sleep_total)

Below is a sample of mammals from the dataset.

                        name  vore sleep_total sleep_rem  bodywt
1                    Cheetah carni        12.1        NA  50.000
2                 Owl monkey  omni        17.0       1.8   0.480
3            Mountain beaver herbi        14.4       2.4   1.350
4 Greater short-tailed shrew  omni        14.9       2.3   0.019
5                        Cow herbi         4.0       0.7 600.000
6           Three-toed sloth herbi        14.4       2.2   3.850

REM Sleep vs Total Sleep: Raw Data

Sleep REM vs. Total Sleep: Fitted Model

R Code: Fitted Regression Model

ggplot(sleep_data, aes(x = sleep_rem, y = sleep_total)) +
  geom_point(aes(color = "Observed Data")) +
  geom_smooth(aes(color = "Fitted"), method = "lm") +
  scale_color_manual(
    values = c("Observed Data" = "black", "Fitted" = "red"),
    name = NULL
  ) +
  labs(
    x = "REM Sleep (Hours)",
    y = "Total Sleep (Hours)"
  ) +
  theme_classic()

Regression Results

\[ \widehat{\text{Total Sleep}} = 5.4660 + 2.6248(\text{REM Sleep}) \]

  • Slope: For each additional hour of REM sleep, total sleep is predicted to increase by approximately 2.62 hours.
  • Intercept: At 0 hours REM sleep, the model predicts approximately 5.47 hours of total sleep.
  • \(R^2 = 0.5651\): About 56.51% of the variation in total sleep is explained by its linear relationship with REM sleep.

Checking the Model Assumptions: Residuals

A residual(error) is the difference between the predicted and observed value interpreted by: \[ e_i = y_i - \hat{y}_i \]

The plot above shows that the residuals fall both above and below zero, indicating that the model overpredicts and underpredicts total sleep.

Mammel Sleep Patterns by Body Weight

The 3D plot helps examine how REM sleep and total sleep vary by body weight across different mammal diets. Hover over a point to identify a mammal.

Key Takeaways

  • Mammals with more REM sleep tend to sleep more.
  • The positive slope indicates that greater REM sleep is associated with greater total sleep. For each additional hour of REM sleep, total sleep is predicted to increase by approximately 2.62 hours.
  • About 56.51% of the variation in total sleep is explained by its linear relationship with REM sleep.
  • Examining the residuals helped evaluate how well the linear model fit the data by showing the overprediction and underprediction of total sleep.