April 10, 2025

Definition of Simple Linear Regression

Simple linear regression is a model that focuses on finding a linear relationship between an independent and possible dependent variable.

There are two popular formulas for simple linear regression.

\[y = \beta_0 + \beta_1 + \epsilon\] \[\hat{y} = a + bx\]

We will be focusing on the first formula.

Formula

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

\(\mathbf{y}\) is the dependent variable

\(\mathbf{\beta_0}\) is the constant or intercept

\(\mathbf{\beta_1}\) is the regression coefficient

\(\mathbf{X}\) is the independent variable

\(\mathbf{\epsilon}\) is the error

Plotting the Data

Before solving the linear regression model for the line of best fit, let us use a scatter plot to visualize the data.

Linear Regression Analysis in R

Now we will run the linear regression model which is built into R.

happiness.income.lm <- lm(happiness ~ income, income.data)

summary.lm <- summary(happiness.income.lm)

Summary of Analysis

## 
## Call:
## lm(formula = happiness ~ income, data = income.data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.02479 -0.48526  0.04078  0.45898  2.37805 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.20427    0.08884   2.299   0.0219 *  
## income       0.71383    0.01854  38.505   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7181 on 496 degrees of freedom
## Multiple R-squared:  0.7493, Adjusted R-squared:  0.7488 
## F-statistic:  1483 on 1 and 496 DF,  p-value: < 2.2e-16

Line of Best Fit

The model produces the line of best fit:

## `geom_smooth()` using formula = 'y ~ x'

\(P\)-Value

One of the most important pieces of data is the \(p\)-value which describes the probability of our results occurring under the null-hypothesis.

The \(p\)-value of this data is \(2.2 \times 10^{-16}\) which is basically zero. This indicates that the model fits the data well.

Happiness x Income Linear Regression Graph

## `geom_smooth()` using formula = 'y ~ x'

Data Set