Method 1:Using Actual Formulae
Mean Absolute Error (MAE) is calculated by taking the summation of the absolute difference between the actual and calculated values of each observation over the entire vector and then dividing the sum obtained by the number of observations in the vector.
In this example, we are taking the two vectors the actual vector and the calculated vector, and further, with the use of the basic formula of the MAE, we will be calculating it in R.
R
# a vector of integers for actual actual = c (8,9,6,1,4,8,6,4,5,6) # a vector of integers for actual calculated = c (9,6,4,8,4,1,2,3,9,6) n = 10 sum = 0 # for loop for iteration for (i in 1:n){ sum = abs (actual[i] - calculated[i]) + sum } error = sum/n # display error |
Output:
[1] 2.9
How to Calculate MAE in R
In this article, we are calculating the Mean Absolute Error in the R programming language.
Mean Absolute Error: It is the measure of errors between paired observations expressing the same phenomenon and the way to measure the accuracy of a given model. The formula to it is as follows:
MAE = (1/n) * Σ|yi – xi|
Where,
- Σ: Sum
- yi: Observed value for ith observation
- xi: Predicted value for ith observation
- n: Total number of observations