R Squared Calculator - Adjusted R Squared and F Test

    Turn predictions, sums of squares or a reported value into R squared, adjusted R squared and an F test, and see why Excel RSQ and scikit-learn r2_score disagree on the same data.

    Parameters

    Enter data for calculations

    Only the boxes for your choice appear

    Without the intercept; optional with data

    Form progress0 / 1 fields

    💡 Fill in all required fields to unlock the calculate button

    R squared from predictions, from sums of squares, or adjusted from a reported value

    Three starting points lead to the same number. Actual and predicted values, as scikit-learn's r2_score takes them; the two sums of squares from an ANOVA table or a homework question; or an R squared already printed somewhere that you want to adjust for the number of predictors and test. From the pairs 3, -0.5, 2, 7 and their predictions 2.5, 0, 2, 8 the calculator gives R squared 0.9486, while Excel's RSQ on the same pairs says 0.9700, and it explains the difference. Around the headline number you also get adjusted R squared, the overall F test with its p-value, the smallest R squared that would be significant for your n and k, RMSE, MAE, MAPE, the mean error and the pairs that carry most of the error.

    R squared on its own, and R squared with context

    A single number

    • 0.40 from 12 observations and 8 predictors looks respectable, though adjusted it is -1.2000
    • predictions that are all 5 units too high can still show RSQ = 1.0000
    • nobody can tell whether 0.40 is significant without n and k
    • one bad pair can carry two thirds of the error unnoticed

    What the calculator adds

    • adjusted R squared and the shrinkage it reveals
    • R squared and RSQ side by side, with a note when they part ways
    • the overall F test, its p-value and the R squared needed to pass at 0.05
    • the five largest errors with their share of SSE

    Three starting points and the boxes each one needs

    1. What do you have - actual and predicted values, the sums of squares SSE and SST, or an R squared you want to adjust. Only the boxes for that choice appear, and values left in hidden boxes are ignored.
    2. Actual and predicted values - two lists in the same order, separated by spaces, commas or new lines, with a dot for decimals and no thousands separators. The third prediction must belong to the third observation.
    3. SSE and SST - the sum of squared errors (residual sum of squares) and the total sum of squares around the mean. If your table shows the regression sum SSR instead, SSE = SST - SSR.
    4. R squared - as a decimal: 72% is 0.72. A value above 1 is refused with the decimal it probably meant.
    5. Number of observations n and predictors k - k counts the explanatory variables without the intercept, so a simple regression has 1. Both are needed for adjusted R squared and the F test.
    6. Read the result: R squared first, then the tiles, any note about a gap between R squared and RSQ, a negative adjusted value or a small sample, and the error table.

    The formulas, with three results worked out

    R squared = 1 - SSE / SST
    adjusted R squared = 1 - (1 - R squared)(n - 1) / (n - k - 1)
    F = (R squared / k) / ((1 - R squared) / (n - k - 1)), on k and n - k - 1 degrees of freedom
    From predictions. Actual 3, -0.5, 2, 7 against predicted 2.5, 0, 2, 8. The mean of the actual values is 2.875, so SST = 29.19; the errors 0.5, 0.5, 0 and 1 give SSE = 1.500. R squared = 1 - 1.5 / 29.1875 = 0.9486, the value in the scikit-learn documentation. The pair (7, 8) alone carries 66.7% of SSE.
    From sums of squares. SSE = 13.763 and SST = 41.2727 with n = 11 and k = 1 give R squared 0.6665, adjusted 0.6295, F = 17.99 and p = 0.0022, which is exactly what R's summary prints for the first set of Anscombe's quartet.
    From a reported value. R squared 0.80 with n = 20 and k = 3: adjusted = 1 - 0.2 × 19 / 16 = 0.7625, F = 21.33 on 3 and 16 degrees of freedom, p below 0.0001.

    What predictors cost: one R squared of 0.40, five study designs

    The same R squared means very different things depending on how many observations paid for how many predictors. Each row is the calculator's output for R squared = 0.40.

    Design Adjusted Shrinkage p (F test) R squared needed at 0.05
    n = 100, k = 10.39390.0061below 0.00010.0386
    n = 30, k = 10.37860.02140.00020.1303
    n = 30, k = 50.27500.12500.02360.3532
    n = 15, k = 50.06670.33330.38170.6592
    n = 12, k = 8-1.20001.60000.94810.9593

    Going from one predictor to five on the same 30 observations costs 0.1036 of adjusted R squared (0.3786 down to 0.2750) without changing R squared at all. The last row is the classic overfitted model: eight predictors on twelve points leave three degrees of freedom, and even an R squared of 0.95 would not reach significance there.

    Excel, Python and R: which function prints which R squared

    Two definitions circulate under one name. The table shows which one each common tool reports, so you know which of the calculator's figures to compare against.

    Tool What it computes Matches this calculator's
    Excel RSQ, numpy corrcoef squaredsquare of Pearson's r between the two listssquared correlation tile
    scikit-learn r2_score1 - SSE / SST, can be negativemain R squared
    Excel LINEST with stats, chart trendlineR squared of the fitted least-squares lineboth, which agree for an in-sample fit with an intercept
    R summary(lm), statsmodelsMultiple R-squared and Adjusted R-squared, plus the F statisticR squared, adjusted R squared, F and p
    R lm without an intercept (y ~ x - 1)compares SSE with the sum of squares around zero, not the meanneither; expect a higher figure from R

    Asked about R squared, in short

    Can R squared be negative?
    Yes, whenever the predictions miss by more than the mean would. Predictions of 15 to 25 for actual values of 10 to 20, each 5 too high, give R squared -1.1429, even though RSQ is 1.0000. It cannot happen for a least-squares fit with an intercept judged on its own data.
    Why does Excel RSQ give a different number?
    RSQ squares the correlation, so it only asks whether predictions and actual values rise and fall together. A constant offset or a stretch costs nothing there but counts in full in 1 - SSE / SST. On the scikit-learn example that is 0.9700 against 0.9486, and the mean error of 0.2500 shows where the gap comes from.
    What counts as k in adjusted R squared?
    The number of estimated slopes, without the intercept. A quadratic trend y = a + bx + cx squared has k = 2, and a categorical variable with four levels coded as dummies adds 3.
    Is a high R squared enough to trust a model?
    No. A sales forecast with R squared 0.9503 can still be off by 7 units on a given week, as RMSE and the error table show, and a model tuned on its own data usually scores lower on new data. Check the errors in the units you care about.
    Why is MAPE sometimes missing or flagged?
    MAPE divides each error by the actual value, so a zero makes it undefined and a value near zero makes it explode: one actual value of 0.01 among values around 10 pushes MAPE to 1,984.58%. The calculator prints n/a for a zero and a warning for a near-zero value.

    Related tools

    Z-Score Calculator

    Turns an F or t result into a percentile or a two-tailed p on the normal curve - See calculator

    Linear Regression Calculator

    Fits the least-squares line and prints R squared with the slope test - See calculator

    Pearson Correlation Calculator

    r with its p-value and interval, the square root behind RSQ - See calculator

    Coefficient of Variation Calculator

    Puts RMSE in context as a share of the mean - See calculator

    Skewness Calculator

    Paste the errors to see whether the model misses more often in one direction - See calculator

    Standard Deviation Calculator

    Spread of the actual values, the yardstick for RMSE - See calculator

    Similar calculators from this section