0

Suppose I have a simple linear model in r of the form linear_mod <- lm(log(target) ~ a + b + c).

I am able to predict() with this model by predicting on my training data, back transforming the prediction results for log(target) using exp() and then manually calculating an evaluation metric such as RMSE.

I wondered if there's any framework or setting I can use to tell r to backtransform automatically, like when I call summary(linear_mod) where r returns the RMSE as well as R squared.

Is there a package (e.g. caret?) that can accept as a argument whether or not to back transform the target variable when using a transformation? Or must I do this manually, perhaps by creating a function?

Doug Fir
  • 1,218
  • 1
  • 13
  • 27
  • 2
    Search for "Duan Smearing." Here's [a good example](https://stats.stackexchange.com/questions/93089/reporting-regression-statistics-after-logarithmic-transformation) of what you have to do. – dimitriy Nov 09 '17 at 01:44
  • 1
    What quantity are you trying to obtain when you transform back? What assumptions are you making on the log scale? (whatever you're looking for a prediction of it's probably already answered on site) – Glen_b Nov 09 '17 at 02:31
  • Hi @Glen_b I was interested in RMSE as well as having predict return the backtransformed values rather than the log values. Is this "standard practice"? See also for example this post on kdnuggets I found while researching. On the last paragraph of page 1, the author compares RMSE of a log model to a regular model. This confused me since I thought it was not comparable. Have I misunderstood the article? https://www.kdnuggets.com/2017/10/learn-generalized-linear-models-glm-r.html – Doug Fir Nov 09 '17 at 02:44
  • You're missing what I am asking. What do your predicted values represent? Are you trying to get expected values or something else? – Glen_b Nov 09 '17 at 02:50
  • I believe I'm seeking both expected values as well as evaluation metric. I understand how to do this manually by predicting on the data, back transforming the results (thus expected values) and then calculating RMSE. However I wondered that this must be such a common task that perhaps predict() function or a package might have a way to automatically return back transformed predictions and evaluation metric with a log(target variable) type of linear model? – Doug Fir Nov 09 '17 at 02:54

0 Answers0