This free R squared calculator computes R² and adjusted R² from actual vs predicted values, or from x and y with a fitted line, and shows the sums of squares, RMSE and residuals.
Show residuals for every point
| x / # | y | ŷ | residual |
|---|
What does an R squared calculator measure?
An R squared calculator measures how much of the variation in your data a model explains. R², the coefficient of determination, compares the model's errors with the errors of the simplest possible model, one that always predicts the mean of y:
\[ R^2 = 1 - \frac{SS_{res}}{SS_{tot}} = 1 - \frac{\sum (y_i - \hat y_i)^2}{\sum (y_i - \bar y)^2} \]
R² = 1 means perfect predictions. R² = 0 means the model is no better than the mean. On new data, R² can even be negative, which means the model is worse than the mean.
This free R squared calculator works two ways. Enter actual vs predicted values from any model, such as a neural network, random forest or spreadsheet forecast. Or enter x and y and it fits a least-squares line for you, like our linear regression calculator. Either way you get R², adjusted R², both sums of squares, RMSE and a residual table.
How to use the R squared calculator
- Choose what your data is: actual vs predicted, or x and y.
- Paste the two lists, separated by commas, spaces or new lines.
- Set p, the number of predictors in your model, for adjusted R². A simple straight line has p = 1.
- Press Calculate R², then open the residual table to see which points the model misses.
In the example, the actual values have \( SS_{tot} = 939.5 \) and the predictions leave \( SS_{res} = 23.92 \), so \( R^2 = 1 - 23.92/939.5 = 0.9745 \). The model explains about 97.5% of the variance. Press Try a bad model to see a negative R².
Adjusted R squared in the R squared calculator
Adding a predictor can never lower ordinary R² on the training data, even if the new variable is pure noise. Adjusted R² charges for each extra predictor:
\[ R^2_{adj} = 1 - (1 - R^2)\,\frac{n - 1}{n - p - 1} \]
where n is the number of points and p the number of predictors. For the example (n = 8, p = 1), adjusted R² = 0.9703. If adding a variable raises R² but lowers adjusted R², the variable is probably not earning its place, an early warning of overfitting.
R squared vs correlation, RMSE and MAE
- Correlation r. For a least-squares line with an intercept, \( R^2 = r^2 \). For predictions from any other model, R² and \( r^2 \) can differ: a model can be perfectly correlated with the truth and still be badly off by a constant. See covariance vs correlation.
- RMSE and MAE. R² is unit-free and relative to the spread of y. RMSE and MAE are in the units of y, so they tell you how big a typical error is. Report both kinds.
- MSE. \( SS_{res}/n \) is the mean squared error, so R² is simply \( 1 - \mathrm{MSE}/\mathrm{Var}(y) \).
What is a good R squared? Reading the R squared calculator's result
It depends on the field. Physical measurements often reach 0.95 or more, while models of human behaviour may be useful at 0.3. Three cautions matter more than any threshold:
- Measure it on held-out data. Training R² flatters the model; use a test set or cross-validation.
- A high R² does not prove causation. It measures fit, not cause and effect.
- Check the residuals. A curved pattern means a straight line is the wrong shape, even when R² is high. A few outliers can also inflate or deflate it.
The R squared calculator uses exactly this definition, so its result matches standard software. scikit-learn computes the same number with sklearn.metrics.r2_score(y_true, y_pred), which can also return negative values. The definition follows the coefficient of determination on Wikipedia.
Frequently asked questions
Can R squared be negative? Yes, when the predictions are worse than always predicting the mean. This happens on test data or with models not fitted by least squares with an intercept.
What is the difference between R squared and adjusted R squared? Adjusted R² penalises extra predictors, so it only rises when a new variable improves the fit more than chance would.
Is R squared the same as r squared? For a simple linear regression with an intercept, yes. For other models, compute R² from the sums of squares as this calculator does.
How many data points do I need? At least 3, and n must be larger than p + 1 for adjusted R². More points give a more trustworthy value.