How to Calculate Root Mean Square Error (RMSE) in Excel


In statistics, regression analysis is a technique we use to understand the relationship between a predictor variable, x, and a response variable, y. 

When we conduct regression analysis, we end up with a model that tells us the predicted value for the response variable based on the value of the predictor variable.

One way to assess how “good” our model fits a given dataset is to calculate the root mean square error, which is a metric that tells us how far apart our predicted values are from our observed values, on average.

The formula to find the root mean square error, more commonly referred to as RMSE, is as follows:

RMSE = √[ Σ(Pi – Oi)2 / n ]

where:

  • Σ is a fancy symbol that means “sum”
  • Pi is the predicted value for the ith observation in the dataset
  • Oi is the observed value for the ith observation in the dataset
  • n is the sample size

Technical Notes: 

  • The root mean square error can be calculated for any type of model that produces predicted values, which can then be compared to the observed values of a dataset.
  • The root mean square error is also sometimes called the root mean square deviation, which is often abbreviated as RMSD.

Next, let’s look at an example of how to calculate root mean square error in Excel.

How to Calculate Root Mean Square Error in Excel

There is no built-in function to calculate RMSE in Excel, but we can calculate it fairly easily with a single formula. We’ll show how to calculate RMSE for two different scenarios.

Scenario 1

In one scenario, you might have one column that contains the predicted values of your model and another column that contains the observed values. The image below shows an example of this scenario:

Example of calculating RMSE in Excel for observed and predicted values

If this is the case, then you can calculate the RMSE by typing the following formula into any cell, and then clicking CTRL+SHIFT+ENTER:

=SQRT(SUMSQ(A2:A21-B2:B21) / COUNTA(A2:A21))

Example of calculating root mean square error in Excel

This tells us that the root mean square error is 2.6646.

RMSE calculation in Excel

The formula might look a bit tricky, but it makes sense once you break it down:

=SQRT(SUMSQ(A2:A21-B2:B21) / COUNTA(A2:A21))

  • First, we calculate the sum of the squared differences between the predicted and observed values using the SUMSQ() function.
  • Next, we divide by the sample size of the dataset using COUNTA(), which counts the number of cells in a range that are not empty.
  • Lastly, we take the square root of the whole calculation using the SQRT() function.

Scenario 2

In another scenario, you may have already calculated the differences between the predicted and observed values. In this case, you will only have one column that displays the differences.

The image below shows an example of this scenario. The predicted values are displayed in column A, the observed values in column B, and the difference between the predicted and observed values in column D:

Root mean square error example in Excel

If this is the case, then you can calculate the RMSE by typing the following formula into any cell, and then clicking CTRL+SHIFT+ENTER:

=SQRT(SUMSQ(D2:D21) / COUNTA(D2:D21))

RMSE in Excel

This tells us that the root mean square error is 2.6646, which matches the result that we got in the first scenario. This confirms that these two approaches to calculating RMSE are equivalent.

Root mean square error in Excel

The formula we used in this scenario is only slightly different than the one we used in the previous scenario:

=SQRT(SUMSQ(D2:D21) / COUNTA(D2:D21))

  • Since we already calculated the differences between the predicted and observed values in column D, we can calculate the sum of the squared differences by using the SUMSQ() function with just the values in column D.
  • Next, we divide by the sample size of the dataset using COUNTA(), which counts the number of cells in a range that are not empty.
  • Lastly, we take the square root of the whole calculation using the SQRT() function.

How to Interpret RMSE

As mentioned earlier, RMSE is a useful way to see how well a regression model (or any model that produces predicted values) is able to “fit” a dataset.

The larger the RMSE, the larger the difference between the predicted and observed values, which means the worse the regression model fits the data. Conversely, the smaller the RMSE, the better a model is able to fit the data.

It can be particularly useful to compare the RMSE of two different models with each other to see which model fits the data better.

For more tutorials in Excel, be sure to check out our Excel Guides Page, which lists every Excel tutorial on Statology.

5 Replies to “How to Calculate Root Mean Square Error (RMSE) in Excel”

  1. Make it simple, and then do the excel. Pick 5 scores and 5 corresponding predicted values, compute the differences, square them, divide by 5 and take the square root. Then consider moving onto excel for larger data sets.

  2. This makes a lot of sense to me but how does the value calculated serve in a process.
    Appreciate the explanation and examples

  3. Nice explanation about RMSE. like the way the menus are set specially it is handy and easy o understand for refresher,

  4. Hey,

    Can you post document for multiple regression RMSE calculation? where more than one input variable and one target variable

    1. Hi Krisha…Certainly! Here’s a document that describes the process of calculating the **Root Mean Square Error (RMSE)** for **Multiple Regression** where there is more than one input variable (independent variables) and one target variable (dependent variable).

      ### Multiple Regression RMSE Calculation

      #### 1. **Overview of Multiple Regression**
      Multiple Regression is a technique used to predict the outcome of a target variable based on the values of multiple input variables. The general form of the multiple linear regression equation is:

      \[
      Y = \beta_0 + \beta_1 X_1 + \beta_2 X_2 + \dots + \beta_n X_n + \epsilon
      \]

      Where:
      – \(Y\) is the target variable (dependent variable).
      – \(X_1, X_2, …, X_n\) are the input variables (independent variables).
      – \(\beta_0, \beta_1, \beta_2, …, \beta_n\) are the coefficients that represent the impact of each input variable on the target variable.
      – \(\epsilon\) is the error term (residuals).

      #### 2. **Root Mean Square Error (RMSE) Definition**
      RMSE is a standard way to measure the error of a regression model in predicting quantitative data. It represents the square root of the average of the squared differences between the actual and predicted values. It gives a measure of how well the regression model fits the data.

      The formula for RMSE is:

      \[
      RMSE = \sqrt{\frac{1}{N} \sum_{i=1}^{N} (Y_i – \hat{Y}_i)^2}
      \]

      Where:
      – \(N\) is the number of data points (observations).
      – \(Y_i\) is the actual value of the target variable for the \(i\)-th data point.
      – \(\hat{Y}_i\) is the predicted value of the target variable for the \(i\)-th data point.

      #### 3. **Steps for RMSE Calculation in Multiple Regression**

      ##### **Step 1: Prepare Your Data**
      – Collect a dataset where you have multiple input variables (e.g., \(X_1, X_2, …, X_n\)) and a target variable \(Y\).
      – Split the dataset into training and testing sets if required. This helps to evaluate the model on unseen data.

      ##### **Step 2: Fit the Multiple Regression Model**
      – Use the training data to fit the multiple regression model.
      – Estimate the regression coefficients (\(\beta_0, \beta_1, …, \beta_n\)) using methods like Ordinary Least Squares (OLS).

      In Python, you can use libraries like **scikit-learn** to build the regression model.

      ##### **Step 3: Make Predictions**
      – Use the fitted model to predict the target variable (\(\hat{Y}_i\)) for the test set or validation data.

      ##### **Step 4: Compute the Residuals**
      – For each data point, compute the difference between the actual value (\(Y_i\)) and the predicted value (\(\hat{Y}_i\)).

      \[
      \text{Residual}_i = Y_i – \hat{Y}_i
      \]

      ##### **Step 5: Calculate RMSE**
      – Square each residual, sum them up, and divide by the total number of data points \(N\).
      – Take the square root of this value to get RMSE.

      ### Example Code for Multiple Regression RMSE in Python

      “`python
      import numpy as np
      from sklearn.model_selection import train_test_split
      from sklearn.linear_model import LinearRegression
      from sklearn.metrics import mean_squared_error

      # Sample data: input variables (X1, X2) and target variable (Y)
      X = np.array([[1, 2], [2, 4], [3, 5], [4, 8], [5, 10], [6, 12], [7, 14], [8, 16]])
      Y = np.array([1, 2, 3, 4, 5, 6, 7, 8])

      # Split the dataset into training and testing sets
      X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=42)

      # Fit the multiple regression model
      model = LinearRegression()
      model.fit(X_train, Y_train)

      # Make predictions on the test set
      Y_pred = model.predict(X_test)

      # Calculate the RMSE
      rmse = np.sqrt(mean_squared_error(Y_test, Y_pred))

      print(f”Root Mean Square Error (RMSE): {rmse}”)
      “`

      ### Example Breakdown:
      1. **Data**:
      – We create a simple dataset with two input variables (X1, X2) and one target variable (Y).

      2. **Train-Test Split**:
      – The dataset is split into training and testing sets using `train_test_split` from scikit-learn.

      3. **Fitting the Model**:
      – We fit the `LinearRegression` model using the training data.

      4. **Prediction**:
      – The model is used to make predictions on the test set.

      5. **RMSE Calculation**:
      – We compute the RMSE using the predicted values and the actual target values from the test set.

      ### 4. **Interpretation of RMSE**
      – RMSE gives an idea of how far the predicted values are from the actual values.
      – Lower RMSE values indicate that the predictions are closer to the actual data.
      – RMSE is in the same unit as the target variable \(Y\), making it easily interpretable.

      ### 5. **Conclusion**
      The RMSE is a useful metric to evaluate how well a multiple regression model fits the data. It can help you understand the accuracy of your model by measuring the average magnitude of errors in predictions.

Leave a Reply

Your email address will not be published. Required fields are marked *