Search code examples
rglmlm

In R is it possible to use MAE (Mean Absolute Error) instead of RMSE as the cost function to a linear regression (lm/glm)


I am trying to do several regressions on financial data, and one problem with financial data is that it tends to have lots of extreme outliers that are possibly not all that informational. In R linear regression uses RMSE as it's cost function. I understand this, RMSE is more useful for regression in that it has a derivative etc. But it also tends to penalise outliers more heavily than MAE which treats all values as equal. So I was wondering is there any parameter that can be passed to lm/glm that will instruct it to use MAE instead of RMSE as the cost function? I can think of a few alternative work-arounds, weighting by the inverse of the absolute return or applying a transformation, but it would be nicer if I could just do a regression using MAE.


Solution

  • Searching for R robust linear regression lead me to the rlm function from the MASS package (included standarly in R). I think this is a nice place to start for your solution. It does not work with the MAE, but I would read up on how rlm performs robust fitting (i.e. fitting while not being unduly influenced by outliers).