2026-10-30

Introduction to Simple Linear Regression

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

  • It helps identify patterns in data.
  • It can be used to predict future outcomes.
  • It shows how one variable changes in relation to another.

Why Is Linear Regression Useful?

Linear regression helps us understand trends, make predictions, and determine how strongly two numerical variables are related.

Example: “Is studying more hours associated with higher exam scores?”

The Simple Linear Regression Equation

Simple linear regression models the relationship between two variables using the equation:

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

Where:

  • \(Y\) = Dependent variable (exam score)
  • \(X\) = Independent variable (hours studied)
  • \(\beta_0\) = Intercept
  • \(\beta_1\) = Slope
  • \(\epsilon\) = Random error

The slope represents the expected change in exam score for each additional hour studied.

Understanding the Regression Coefficients

The predicted regression equation is:

\[ \hat{Y} = b_0 + b_1X \]

  • \(b_0\) = Intercept (starting value)
  • \(b_1\) = Slope (change per hour)
  • \(X\) = Hours studied
  • \(\hat{Y}\) = Predicted exam score

Example: Predicting an Exam Score

Suppose \(\hat{Y} = 50 + 5X\).

For a student who studies 4 hours:

\[ \hat{Y} = 50 + 5(4) = 70 \]

Predicted score: 70 points

Example Dataset: Study Hours and Exam Scores

We will use a small example dataset to examine whether studying more hours is associated with higher exam scores.

hours <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scores <- c(55, 60, 65, 68, 72, 78, 82, 85, 90, 95)

study_data <- data.frame(
  Hours = hours,
  Score = scores
)

Variables:

  • Hours: Number of hours spent studying.
  • Score: Exam score out of 100.

Visualizing Study Hours and Exam Scores

A scatter plot helps us visualize the relationship between hours studied and exam scores.

Linear Regression Model

We can add a regression line to our scatter plot to better understand the relationship between study hours and exam scores.

Interpretation:

The purple points represent individual student scores. The red line represents the estimated regression line. The positive slope indicates that higher study hours are associated with higher exam scores.

Interactive Plotly Visualization

Plotly allows us to explore data interactively by hovering over points to view their values.

Interactive Features:

Hover over points to see study hours and exam scores. Zoom in to explore specific sections of the graph. Compare how exam scores change as study hours increase.

Conclusion

Simple linear regression is a useful statistical method for understanding relationships between two numerical variables.

Key Takeaways:

  • Linear regression helps identify relationships between variables.
  • Scatter plots make it easier to visualize patterns in data.
  • A regression line can be used to predict outcomes.
  • ggplot2 creates clear statistical visualizations.
  • Plotly allows users to interact with data.

Final Observation:

Our example demonstrates a positive relationship between study hours and exam scores. As study hours increase, exam scores tend to increase.

However, correlation does not necessarily imply causation.