*15*

In statistics, **R-squared** (R^{2}) measures the proportion of the variance in the response variable that can be explained by the predictor variable in a regression model.

We use the following formula to calculate R-squared:

R^{2} =Â [ (nÎ£xy â€“ (Î£x)(Î£y)) / (âˆšnÎ£x^{2}-(Î£x)^{2} * âˆšnÎ£y^{2}-(Î£y)^{2}) ]^{2}

The following step-by-step example shows how to calculate R-squared by hand for a given regression model.

**Step 1: Create a Dataset**

First, letâ€™s create a dataset:

**Step 2: Calculate Necessary Metrics**

Next, letâ€™s calculate each metric that we need to use in the R^{2} formula:

**Step 3: Calculate R-Squared**

Lastly, weâ€™ll plug in each metric into the formula for R^{2}:

- R
^{2}=Â [ (nÎ£xy â€“ (Î£x)(Î£y)) / (âˆšnÎ£x^{2}-(Î£x)^{2}* âˆšnÎ£y^{2}-(Î£y)^{2}) ]^{2} - R
^{2}=Â [ (8*(2169) â€“ (72)(223)) / (âˆš8*(818)-(72)^{2}* âˆš8*(6447)-(223)^{2}) ]^{2} - R
^{2}=Â 0.6686

**Note:** The *n* in the formula represents the number of observations in the dataset and turns out to be n = 8 observations in this example.

Assuming *x* is the predictor variable and *y* is the response variable in this regression model, the R-squared for the model is **0.6686**.

This tells us that 66.86% of the variation in the variable *y* can be explained by variable *x*.

**Additional Resources**

Introduction to Simple Linear Regression

Introduction to Multiple Linear Regression

R vs. R-Squared: Whatâ€™s the Difference?

What is a Good R-squared Value?