6.1 C
London
Saturday, December 21, 2024
HomeStatistics TutorialRHow to Calculate SMAPE in R

How to Calculate SMAPE in R

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

The symmetric mean absolute percentage error (SMAPE) is used to measure the predictive accuracy of models. It is calculated as:

SMAPE = (1/n) * Σ(|forecast – actual| / ((|actual| + |forecast|)/2) * 100

where:

  • Σ – a symbol that means “sum”
  • n – sample size
  • actual – the actual data value
  • forecast – the forecasted data value

The smaller the value for SMAPE, the better the predictive accuracy of a given model.

This tutorial explains two different methods you can use to calculate SMAPE in R.

Method 1: Use smape() from the Metrics Package

One way to calculate SMAPE in R is to use the smape() function from the Metrics package:

library(Metrics)

#define actual values
actual #define forecasted values
forecast #calculate SMAPE
smape(actual, forecast)

[1] 0.1245302

We can see that the symmetric mean absolute percentage error for this model is 12.45%.

Method 2: Write Your Own Function

Another way to calculate SMAPE is to create our own function as follows:

find_smape function(a, f) {
  return (1/length(a) * sum(2*abs(f-a) / (abs(a)+abs(f))*100))
}

We can then use this function to calculate the SMAPE between a vector of actual values and forecasted values:

#define actual values
actual #define forecasted values
forecast #calculate SMAPE
find_smape(actual, forecast)

[1] 12.45302

Once again the SMAPE turns out to be 12.45%, which matches the results from the previous example.

Additional Resources

How to Calculate MAPE in R
How to Calculate MAD in R
How to Calculate MAE in R
How to Calculate RMSE in R
How to Calculate MSE in R

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories