Home » How to Calculate SMAPE in R

How to Calculate SMAPE in R

by Erma Khan

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

Related Posts