In this post, you will learn what the Sum of Squared Errors (SSE) is and how to calculate it in R. SSE measures the difference between observed values and the values predicted by a regression model. In other words, it indicates how well the model fits the data.
We will first look at what SSE means in regression analysis and how to calculate it. After that, we will use R to calculate SSE for a linear regression model. Finally, we will briefly discuss how to interpret the results.
What Is SSE in Regression?
SSE stands for Sum of Squared Errors and is calculated by summing the squared differences between the observed values and the values predicted by a regression model. In other words, SSE tells us how much variation in our data the model leaves unexplained.
The formula for calculating SSE is:

A smaller SSE value indicates that the model’s predictions are close to the actual values. On the other hand, a large SSE may suggest that the model is not accurately capturing the pattern in the data.
Let’s say you are running a simple linear regression to predict reaction time based on age. Each predicted value will likely differ slightly from the observed value. The difference between the predicted and observed values is called a residual. Squaring each residual and summing them gives you the SSE. This quantifies how much variance your model doesn’t explain.
What Does SSE Represent in Regression Analysis?
SSE measures how much the observed values differ from the values predicted by a regression model. A smaller SSE indicates that the model fits the data better, at least when comparing models using the same observations.
SSE can also be used together with other measures, such as R-squared and Mean Squared Error (MSE). While R-squared tells us what proportion of the variation in the dependent variable the model explains, SSE measures the remaining variation as the sum of squared residuals.
We can also use SSE to compare regression models fitted to the same data. For example, if we fit two models to predict reaction time, the model with the lower SSE will have smaller squared prediction errors on those observations. However, adding more predictors to a linear regression model will generally reduce SSE or leave it unchanged, even if the additional predictors are not particularly useful. Therefore, SSE alone is not enough to decide which model to use.

How to Calculate SSE in R
We can calculate SSE in R by fitting a linear regression model and extracting the residuals. We then square each residual and sum the squared values. Here is an example using R:
# Example data
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 5, 4, 5)
# Fit a linear model
model <- lm(y ~ x)
# Calculate SSE
sse <- sum(residuals(model)^2)
sseCode language: R (r)
In the code above, we use lm() to fit a linear regression model. We then extract the residuals using residuals(model), square them with ^2, and add them together using sum(). The result is the SSE for our regression model.
If you want to learn more about calculating SSE in R, including examples using real datasets and multiple regression, see my previous post: How to Calculate SSE in R.
Conclusion
In this post, we looked at what SSE is, how it is used in regression analysis, and how to calculate it in R. SSE measures how much the observed values differ from those predicted by our regression model. A smaller SSE indicates a better fit when comparing models fitted to the same observations. However, SSE does not account for model complexity, so we should also consider other measures when comparing regression models.
I hope you found this post useful. If you have any questions or suggestions, feel free to leave a comment below.