Introduction

  • Simple Linear Regression models the relationship between two continuous variables.
  • In this presentation, we will predict students’ test scores based on hours studied.
  • Regression is an efficient way to find the best fit line that minimizes actual and predicted values differences.

Mathematical Model: Latex Example 1

The linear regression model is:

\[ y = \beta_0 + \beta_1 x + \epsilon \]

where
- \(y\): dependent variable (test score)
- \(x\): independent variable (hours studied)
- \(\beta_0, \beta_1\): coefficients
- \(\epsilon\): random error term

Estimated Equation: Latex Example 2

The estimated equation based on sample data is: \[ \hat{y} = \hat{\beta}_0 + \hat{\beta}_1 x \]

  • \(\hat{\beta}_0\) (Intercept): The predicted score when study hours (\(x\)) are zero.
  • \(\hat{\beta}_1\) (Slope): The predicted change in score (\(\hat{y}\)) for a one-unit increase in study hours (\(x\)).
  • This slide fulfills the second LaTeX requirement.

Scatterplot with Regression Line (Code)

set.seed(123)
hours <- runif(30, 1, 10)
scores <- 50 + 5 * hours + rnorm(30, mean = 0, sd = 5)
data <- data.frame(hours, scores)

library(ggplot2)

ggplot(data, aes(x = hours, y = scores)) +
  geom_point(color = "lightblue", size = 3) +
  geom_smooth(method = "lm", color = "green", se = TRUE) +
  labs(
    title = "Test Scores vs Hours Studied",
    x = "Hours Studied",
    y = "Test Score"
  ) +
  theme_minimal()

Scatterplot with Regression Line (Plot)

Regression Model Summary

## 
## Call:
## lm(formula = scores ~ hours, data = data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -10.7147  -3.6014   0.0977   3.5281   9.4061 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  53.2998     2.3323   22.85  < 2e-16 ***
## hours         4.4834     0.3497   12.82 3.07e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.938 on 28 degrees of freedom
## Multiple R-squared:  0.8545, Adjusted R-squared:  0.8493 
## F-statistic: 164.4 on 1 and 28 DF,  p-value: 3.073e-13

Residual Plot

Interactive 3D Plot

Estimated Equation

## (Intercept)       hours 
##   53.299819    4.483374