One of the most fundamental statistical models
Relates the interaction between a “response” variable and one or more “explanatory” variables
Easy to interpret and understand since the basis come from the linear equation: \[ Y = mX + b \]
2024-01-05
One of the most fundamental statistical models
Relates the interaction between a “response” variable and one or more “explanatory” variables
Easy to interpret and understand since the basis come from the linear equation: \[ Y = mX + b \]
We do this by trying to establish a linear expression relating “response” or dependent variable to our “explanatory” or independent variable(s)
This expression can best be understood as being of the general form: \[ Y = b + m_1X_1 + m_2X_2 + m_nX_n + \varepsilon \]
Where:
\(Y\) is the dependent variable
The \(m\) terms are the slopes associated with their respective \(X\) term
The \(X\) terms are the independent variables
\(b\) is the y-intercept and \(\varepsilon\) is the error term
#turn the time series into a workable data frame
data <- data.frame(Year = as.numeric(time(airmiles)),
Airmiles = as.numeric(airmiles))
#Next we need to do the actual regression
#luckily R makes that very easy for us
linreg <- lm(Airmiles ~ Year, data)
ggplot(data, aes(x = Year, y = Airmiles)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "dodgerblue2") +
labs(x = "Year", y = "Airmiles") +
ggtitle("Plot With Added Regression Line")
data2 <- data.frame(Year = as.numeric(time(airmiles)),
Airmiles = as.numeric(airmiles))
# add a new IV (Incidents) to the data frame
#with random values from 0-7
data2$Incidents <- sample(0:7, nrow(data2), replace = TRUE)
# our data now looks like this:
#(note that these are totally made up incident numbers)
summary(data2)
## Year Airmiles Incidents ## Min. :1937 Min. : 412 Min. :0.000 ## 1st Qu.:1943 1st Qu.: 1580 1st Qu.:1.000 ## Median :1948 Median : 6431 Median :3.500 ## Mean :1948 Mean :10528 Mean :3.375 ## 3rd Qu.:1954 3rd Qu.:17532 3rd Qu.:5.250 ## Max. :1960 Max. :30514 Max. :7.000
The beauty of linear regression is it’s simplicity and the ease from which we can intuit general trends.
A statistician in 1960 could have made a clear prediction that going forwards air travel will continue to increase in popularity.
They also would have been able to intuit that this trend would continue regardless of the number of (fictional) incidents!
This presentation covered some of the basics of linear regression and has hopefully demonstrated some of the value of this very old, but still very useful statistical tool!