2025-10-19

What is Linear Regression?

Linear regression helps us answer: Can we predict one variable from another?

Example: Can we predict exam scores from study hours?

The model draws the “best fit” line through our data points.

\[\text{Exam Score} = \beta_0 + \beta_1 \times \text{Study Hours}\]

  • \(\beta_0\) = starting point (intercept)
  • \(\beta_1\) = how much score changes per hour (slope)

The Data: Study Hours vs Exam Scores

The line shows the trend: more study hours = higher scores!

Creating the Plot in R

# Scatter plot with best fit line
ggplot(data, aes(x = hours, y = score)) +
  geom_point(color = "#2E86AB", size = 3) +
  geom_smooth(method = "lm", se = TRUE) +
  labs(
    title = "Study Hours vs Exam Scores",
    x = "Study Hours per Week",
    y = "Exam Score"
  ) +
  theme_minimal()

Our Model Results

Fitted Line: \[\text{Exam Score} = 5.39 + 1.92 \times \text{Study Hours}\]

What this means:

  • Starting point: 5.39 points (if someone studied 0 hours)
  • For every extra hour of study, score goes up by 1.92 points
  • R-squared = 0.594 (the model explains 59.4% of the variation)

Checking if the Pattern is Real

We test: Is the relationship real, or just random chance?

\[H_0: \beta_1 = 0 \text{ (no relationship)}\] \[H_A: \beta_1 \neq 0 \text{ (there is a relationship)}\]

Our test statistic: \(t = 11.98\), p-value < 0.001

Conclusion: The relationship is REAL (not random)!

Checking Model Quality

Points should be randomly scattered around zero ✓

Summary

What we learned:

  • Linear regression finds the best line through data points
  • We can use it to make predictions
  • The slope tells us how much Y changes when X increases
  • We can test if the relationship is statistically significant

Our example: Each extra hour of study increases exam scores by about 1.92 points!

Uses: Business, science, engineering, social sciences, and more!