A simple linear regression is used to draw a relationship between an explanatory variable, or x, and a quantiative response variable, y.
2024-03-17
A simple linear regression is used to draw a relationship between an explanatory variable, or x, and a quantiative response variable, y.
Simple linear regression models can be represented by the following equation, where
The equation for a simple linear regression model is:
\[ y = \beta_0 + \beta_1x + \epsilon \]
model <- lm(dist ~ speed, data = cars) cars$predicted_dist <- predict(model) p <- plot_ly(data = cars, x = ~speed, y = ~dist, type = 'scatter', mode = 'markers') p <- add_trace(p, x = ~speed, y = ~predicted_dist, type = 'scatter', mode = 'lines') p
In order to evaluate a regression line, we can use something called the coefficient of determination, which is denoted by “r-squared”:
The coefficient of determination, \(R^2\), is computed as:
\[ R^2 = 1 - \frac{SS_{\text{res}}}{SS_{\text{tot}}} \]
where: