{
    "name": "R-Squared Calculator",
    "url": "https://calculators.geekmidst.com/calculators/regression-r-squared-calculator",
    "markdown": "https://calculators.geekmidst.com/calculators/regression-r-squared-calculator.md",
    "category": "Statistics & probability",
    "description": "Get R² and adjusted R² for a straight-line fit with its F test, or for any model’s predictions against actual values, with SSres and SStot shown.",
    "summary": "R² is the share of the variation in y that a model explains: 1 − SSres ÷ SStot. Fit a line to x and y, or paste a model’s predictions next to the actual values.",
    "also_called": [
        "Coefficient of determination calculator",
        "R² calculator"
    ],
    "applies_to": "Worldwide",
    "last_updated": "2026-10-29",
    "computation": "Results are computed in the visitor’s browser on the HTML page. This API describes the calculator; it does not compute results.",
    "inputs": [
        {
            "name": "mode",
            "label": "Data",
            "type": "segmented",
            "default": "fit",
            "options": {
                "fit": "Fit a line to x, y",
                "predictions": "Actual vs predicted"
            }
        },
        {
            "name": "x",
            "label": "X values",
            "type": "textarea",
            "default": "1, 2, 3, 4, 5",
            "shown_when": {
                "mode": "fit"
            }
        },
        {
            "name": "y",
            "label": "Y values (same order)",
            "type": "textarea",
            "default": "2, 4, 5, 4, 5",
            "shown_when": {
                "mode": "fit"
            }
        },
        {
            "name": "actual",
            "label": "Actual values",
            "type": "textarea",
            "default": "3, 5, 7, 9",
            "shown_when": {
                "mode": "predictions"
            }
        },
        {
            "name": "predicted",
            "label": "Predicted values (same order)",
            "type": "textarea",
            "default": "2.5, 5.5, 7, 8",
            "shown_when": {
                "mode": "predictions"
            }
        },
        {
            "name": "predictors",
            "label": "Number of predictors in the model (k)",
            "type": "number",
            "default": "1",
            "shown_when": {
                "mode": "predictions"
            }
        }
    ],
    "outputs": [
        {
            "key": "r2",
            "label": "R²",
            "format": "number"
        },
        {
            "key": "adj_r2",
            "label": "Adjusted R²",
            "format": "number"
        },
        {
            "key": "ss_res",
            "label": "Residual sum of squares (SSres)",
            "format": "number"
        },
        {
            "key": "ss_tot",
            "label": "Total sum of squares (SStot)",
            "format": "number"
        },
        {
            "key": "f_stat",
            "label": "F statistic",
            "format": "text"
        },
        {
            "key": "p_value",
            "label": "p-value of the F test",
            "format": "text"
        },
        {
            "key": "equation",
            "label": "Fitted line",
            "format": "text"
        },
        {
            "key": "n",
            "label": "Observations (n)",
            "format": "integer"
        }
    ],
    "formula": {
        "text": "R² = 1 − SSres ÷ SStot;  adjusted R² = 1 − (1 − R²)(n − 1) ÷ (n − k − 1);  F = (SStot − SSres) ÷ (SSres ÷ (n − 2)) on 1 and n − 2 df",
        "variables": {
            "SSres": "Σ(actual − fitted)²",
            "SStot": "Σ(actual − mean)²",
            "n": "observations",
            "k": "number of predictors (1 for a straight line)"
        }
    },
    "worked_example": {
        "inputs": {
            "mode": "fit",
            "x": "1, 2, 3, 4, 5",
            "y": "2, 4, 5, 4, 5",
            "actual": "3, 5, 7, 9",
            "predicted": "2.5, 5.5, 7, 8",
            "predictors": "1"
        },
        "steps": [
            "The least-squares line is ŷ = 2.2 + 0.6x, leaving SSres = 2.4; SStot = Σ(y − 4)² = 6.",
            "R² = 1 − 2.4 ÷ 6 = 0.6.",
            "Adjusted R² = 1 − 0.4 × 4 ÷ 3 = 0.4667; F = 3.6 ÷ 0.8 = 4.5 on 1 and 3 df (p = 0.124)."
        ],
        "result": "The straight line explains 60% of the variation in y (adjusted R² 0.47), but the F test is not significant with only five points."
    },
    "interpretation": "R² says how much of the spread the model accounts for, not whether the model is right: a curved relation can have a high R² for a straight line and still be badly specified. Adjusted R² penalises extra predictors. With predictions from another model, a negative R² means the model is worse than predicting the mean every time.",
    "assumptions": [
        "Fit mode uses ordinary least squares with an intercept; the F test assumes independent, normal, constant-variance residuals.",
        "Predictions mode uses R² = 1 − SSres ÷ SStot for any model, so it can be negative."
    ],
    "limitations": [
        "The F test is not computed for supplied predictions, because their degrees of freedom depend on how the model was fitted.",
        "R² on the data used to fit a model overstates how well it predicts new data."
    ],
    "rules": null,
    "faqs": [
        {
            "question": "Is R² the same as r squared?",
            "answer": "For a straight line fitted by least squares with an intercept, yes: R² equals the square of Pearson’s r. For other models it is not."
        },
        {
            "question": "What is a good R²?",
            "answer": "It depends on the field. Physical measurements often exceed 0.95, while models of human behaviour may be useful at 0.2."
        }
    ],
    "sources": [],
    "related": [
        {
            "name": "Linear Regression Slope Calculator",
            "url": "https://calculators.geekmidst.com/calculators/linear-regression-slope-calculator"
        },
        {
            "name": "Pearson Correlation Calculator",
            "url": "https://calculators.geekmidst.com/calculators/pearson-correlation-calculator"
        },
        {
            "name": "RMSE Calculator",
            "url": "https://calculators.geekmidst.com/calculators/root-mean-square-error-calculator"
        },
        {
            "name": "Mean Absolute Error Calculator",
            "url": "https://calculators.geekmidst.com/calculators/mean-absolute-error-calculator"
        }
    ],
    "disclaimer": null,
    "publisher": "GM¹X CalcVerse"
}