# Making a residuals plot in R after anti-logging a predicted variable

I want to predict $y$, but I can only predict $\log_{10} y$. So in R I do

fit <- lm(log10(y) ~ x)


Now I want to know how well I've done with respect to my original variable. So naively I plot

y_hat <- 10**fitted(fit)
plot(y-y_hat ~ y)


but I recall that logging and then anti-logging (exponentiating) the variable isn't quite so straightforward, that I have to apply some correction to y_hat. How do I do it?

• Did you mean y_hat <- 10**fitted(fit)? Or do you really intend to look at residuals this way?
– EdM
Sep 30, 2015 at 14:34
• You're right, fixed Sep 30, 2015 at 14:39
• If the residuals with respect to y are what matter to you, then you should not be using least squares to fit log10(y). You might prefer something like the Duan smearing estimator.
– whuber
Sep 30, 2015 at 15:28

Doing a regression with $log_{10}(y)$ as the outcome variable suggests that you (at least implicitly) expected your residual errors to be more or less proportional to the values of $y$. Under that assumption about the error distribution, that's the scale in which any statistical tests you wish to perform will be most correctly interpreted.
For checking the quality of your fit, you should do your follow-up work in that scale, calling plot(fit) to examine the relation of residuals agenst fitted values, etc. If you want to compare predicted and fitted, try it first in that log scale. There's nothing wrong with working directly in a log scale; for example, chemists who use pH values are working directly in a scale related to log hydrogen-ion activity.
Taking 10**fitted(fit) returns the equivalent of the predicted geometric mean of $y$ as a function of $x$. As a result your usual visual intuition about quality of fits will be wrong, as that intuition is working in the arithmetic scale after back-transformation. You will probably have some observed values that look extremely high compared to fitted values, with no obviously offsetting similarly extreme low values. That would seem wrong for a standard linear regression, but is to be expected when the fit was done on a log scale of the outcome variable.
So if the desired analysis was done on $log_{10}(y)$ (versus something like the Duan smearing estimator linked in a comment by @whuber), it isn't so much that you need to correct your estimates of y_hat to plot in the original scale. You need to correct your visual intuition. That's hard, so I try to stay in the log scale for plots after transformation.