2
$\begingroup$

I have a relationship of two variables which is somehow log shaped. Now, I establish two models for this dataset, for one I log transform the dependent variable:

    y_ln=ln(y)
    fit=lm(y~x) #lm fits the linear model
    fit_ln=lm(y_ln~x)

If fit_ln has a higher R², is it valid to say that the fit_ln model is the better one?

$\endgroup$
1
  • 1
    $\begingroup$ Some people are dead against this, but it is important to be clear either way what you are doing. $R^2$ the first way is the square of the correlation between outcome and predicted outcome on the original scale. $R^2$ the second way is the square of the correlation between log outcome and predicted log outcome. So, they are answers to different questions. Both are summaries that have meaning, which doesn't imply that they indicate what your decision should be. For example, it's entirely possible that the first $R^2$ is driven up by an outlier, but you're still better off on log scale. $\endgroup$
    – Nick Cox
    Sep 2, 2021 at 10:53

2 Answers 2

1
$\begingroup$

Nope, that will not work. Because the outcome is not the same, and the scaling is not linear.

There are many ways to get a measure, but the one suggested by Wooldridge is to calculate the square correlation af $y$ (in levels) and the fitted value $\hat{y}$ obtained from the regression - after a back transformation.

Now the question is how to obtain a prediction when $\log(y)$ is the dependent variable. Wooldridge suggests (but there are many ways to do this):

  1. Obtain the fitted values from $\log(y)$ on $x_1, x_2, ... , x_n$, as well as the residuals $u_i$.

  2. Calculate: $a_0 = n^{-1} \sum_{i=1}^n \exp(u_i)$

  3. Then for each $y_i$ calculate: $\hat{y}_i = a_0 \cdot \exp(\widehat{\log(y)})$

Now you can calculate an $R^2$ which is comparable.

$\endgroup$
1
$\begingroup$

Consistent with @repmat, it is also a good idea to compute accuracy scores that were not the scores used to optimize either of the two models. See for example median absolute error on the original scale.

But related to the bigger picture, analysts often seem too quick to assume that either log or original scale "works", and that if using long the number to subtract before taking logs is 0.0. These are tenuous assumptions. Think about using either a transformation-free method (semiparametric ordinal regression models such as the proportional odds model, with no binning of Y) or nonparametric transform-both-sides additive models. These are both covered in RMS. Semiparametric models also have the advantage of being robust to outliers.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.