2026-09-16

Simple Linear Regression

Simple Linear Regression is a statistical method that is used to predict and describe the relationship between one explanatory variable and one response variable.

In this presentation, we will use a simple example:

  • Explanatory Variable: hours studies
  • Response Variable: exam score
  • Question: How does one’s exam score tend to change as their study time increases?

The Regression Model

The population model for a simple linear regression is:

\[ Y = \beta_0 + \beta_1X + \epsilon \]

where:

  • \(Y\) is the response variable.
  • \(X\) is the explanatory variable.
  • \(\beta_0\) is the population intercept.
  • \(\beta_1\) is the population slope.
  • \(\epsilon\) represents the random error.

Example Data

Suppose we observe the following study-time and exam-score data.

##    hours score
## 1      1    51
## 2      2    54
## 3      2    57
## 4      3    60
## 5      3    63
## 6      4    66
## 7      4    71
## 8      5    74
## 9      5    77
## 10     6    78
## 11     6    80
## 12     7    83
## 13     8    87
## 14     9    89
## 15    10    95

Visualizing the Relationship

The points show an upward pattern which means students who studied more hours received generally higher scores.

Adding the Regression Line

The line represents the predicted exam score for the amount of time studied. While the shaded region shows the uncertainty around the estimated mean.

Interpreting the Slope

The fitted sample regression line is: \[ \hat{Y} = b_0 + b_1X \]

## (Intercept)       hours 
##    47.53333     4.96000

Coefficients \(b_0\) and \(b_1\) are estimated from the observed data.

The slope \(b_1\) describes the estimated change in exam score for a 1 hour increase of study time.

The intercept \(b_0\) is the predictive score when the student did not spend any time studying.

Interactive Plotly Graph

Plotly allows us to interact with the observations made.

R Code Used

The main analysis can be found by performing few lines of R.

## 
## Call:
## lm(formula = score ~ hours, data = study_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.4533 -1.8133 -0.2133  1.2067  4.6667 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  47.5333     1.4234   33.40 5.48e-14 ***
## hours         4.9600     0.2529   19.61 4.87e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.529 on 13 degrees of freedom
## Multiple R-squared:  0.9673, Adjusted R-squared:  0.9648 
## F-statistic: 384.5 on 1 and 13 DF,  p-value: 4.871e-11
## `geom_smooth()` using formula = 'y ~ x'

R Code Used cont.

lm() function fits the linear regression model.

The formula score - hours means that score is modeled as a function of hours.

Key Ideas

  • A scatter plot helps us in examining the relationship.
  • The regression equation is \(\hat{Y} = b_0 +b_1X\).
  • The slope describes the estimated change in \(Y\) for an increase of 1 in \(X\).
  • The intercept is is the predicted value when \(X=0\)
  • lm() fits a linear regression in R.
  • ggplot2 and plotly can be used as visual tools for the data we find.