Can RMSE and MAE have the same value? DyDG6
I am implementing cross validation and calculating error metrics such as RMSE, $R^2$, MAE, MSE, etc.
Can RMSE and MAE have the same value?
2 Answers
Yes, the mean squared error (MSE) and mean absolute error (MAE) can be equal.
Let $r_i = |y_i - \\hat{y}_i|$ denote the absolute value of the residual for the $i$th data point, and let $r = [r_i, \\dots, r_n]^T$ be a vector containing absolute residuals for all $n$ points in the dataset. Letting $\\vec{1}$ denote a $n \\times 1$ vector of ones, the MSE and MAE can be written as:
$$MSE = \\frac{1}{n} r^T r \\quad MAE = \\frac{1}{n} \\vec{1}^T r \\tag{1}$$
Setting the MSE equal to the MAE and rearranging gives:
$$(r - \\vec{1})^T r = 0 \\tag{2}$$
The MSE and MAE are equal for all datasets where the absolute residuals solve the above equation. Two obvious solutions are: $r = \\vec{0}$ (there's zero error) and $r = \\vec{1}$ (the residuals are all $\\pm 1$, as mkt mentioned). But, there are infinitely many solutions.
We can interpret equation $(2)$ geometrically as follows: The LHS is the dot product of $r-\\vec{1}$ and $r$. Zero dot product implies orthogonality. So, the MSE and MAE are equal if subtracting 1 from each absolute residual gives a vector that's orthogonal to the original absolute residuals.
Furthermore, by completing the square, equation $(2)$ can be rewritten as:
$$\\Big( r-\\frac{1}{2} \\vec{1} \\Big)^T \\Big( r-\\frac{1}{2} \\vec{1} \\Big) = \\frac{n}{4} \\tag{3}$$
This equation describes an $n$-dimensional sphere centered at $[\\frac{1}{2}, \\dots, \\frac{1}{2}]^T$ with radius $\\frac{1}{2} \\sqrt{n}$. The MSE and MAE are equal if and only if the absolute residuals lie on the surface of this hypersphere.
-
$\\begingroup$ +1. I felt a need to verify that most of this hypersphere lies in the region where all the components of $r$ are non-negative, which is a requirement of absolute residuals: that convinced me there truly are a great many (non-trivial) solutions. $\\endgroup$ – whuber♦ 2 hours ago
-
$\\begingroup$ +1 Great answer! $\\endgroup$ – mkt 2 hours ago
-
$\\begingroup$ Actually, the question was whether RMSE and MAE can ever be equal and not whether MSE and MAE can ever be equal. Perhaps @mkt's answer (or the generalized version thereof that I suggested in a comment) is the only answer to the RMSE = MAE question? $\\endgroup$ – Dilip Sarwate 1 min ago
Yes, in theory. The simplest case I can imagine is a dataset where all the prediction errors (i.e. residuals) are exactly 1 or -1. RMSE and MAE will return identical values of 1. One can construct other scenarios too, but none seem very likely.
-
$\\begingroup$ Could you give an example of the other scenarios that you envision? I mean an example other than a scalar multiple (when all the residuals are $\\pm \\sigma$ instead of $\\pm 1$) of the example above. $\\endgroup$ – Dilip Sarwate 3 hours ago
-
$\\begingroup$ @DilipSarwate I was pondering this when user20160 added a much better answer that covers it in more detail than I could. $\\endgroup$ – mkt 2 hours ago