# How to Calculate SMAPE in R

How to Calculate SMAPE in R?, SMAPE indicates the symmetric mean absolute percentage error.SMAPE is mainly used to measure the predictive accuracy of models.

## Mathematical formula is

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

where:

Σ indicates “sum”

n – indicates sample size

actual – indicates the actual data value

forecast – indicates the forecasted data value

How to perform ANCOVA in R » Quick Guide »

When coming to inference similar to other cases, the smaller the value for SMAPE the better the predictive accuracy of a given model.

Here we are going to describe two different approaches in R.

How to Calculate SMAPE in R

### Approach 1: Use Metrics Package

We can make use of Metrics library and smape() function in R for SMAPE calculation.

Compare data frames in R-Quick Guide »

library(Metrics)

define actual values

actual <- c(15, 16, 14, 15, 18, 22, 20)

define forecasted values

forecast <- c(15, 14, 14, 14, 17, 16, 18)

calculate SMAPE

smape(actual, forecast)

[1] 0.09721348

It indicates that the symmetric mean absolute percentage error for this model is 9.72%.

Timeseries analysis in R » Decomposition, & Forecasting »

### Approach 2: Function

The above-mentioned approach is one of the easiest ways to calculate SMAPE, however, we can define our own function for SMAPE calculation.

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

The above function will be helpful for SMAPE calculation between a vector of actual values and forecasted values:

define actual values

actual <- c(15, 16, 14, 15, 18, 22, 20)

define forecasted values

forecast <- c(15, 14, 14, 14, 17, 16, 18)

calculate SMAPE

smape(actual, forecast) [1] 9.721348

As we got earlier the SMAPE value is 9.72%.

When we need to compare different models SMAPE value will be more useful.

Linear Discriminant Analysis in R » LDA Prediction »