0
$\begingroup$

I try to do a simple linear model with logarithmic transformation of y values. I found that depending on which method I use the results differ and I don't understand why. I used 3 different methods:

  1. I log10-transformed y values and run a linear model: lm = lm(log10.y ~ x)
    > log10.y = log10(y)
    > lm = lm(log10.y ~ x)
    > summary(lm)

    Call:
    lm(formula = log10.y ~ x)
    
    Residuals:
         Min       1Q   Median       3Q      Max 
    -0.18026 -0.06582  0.01475  0.05069  0.15280 
    
    Coefficients:
                 Estimate Std. Error t value Pr(>|t|)    
    (Intercept) 2.5135003  0.4180387   6.013 0.000319 ***
    x           0.0005840  0.0003388   1.724 0.123027    
    ---
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    
    Residual standard error: 0.1142 on 8 degrees of freedom
    Multiple R-squared:  0.2708,    Adjusted R-squared:  0.1797 
    F-statistic: 2.972 on 1 and 8 DF,  p-value: 0.123
  1. I used raw y values and used log-transformation within model call: lm = lm(log(y) ~ x)
    > lm = lm(log(y) ~ x)
    > summary(lm)
    
    Call:
    lm(formula = log(y) ~ x)
    
    Residuals:
         Min       1Q   Median       3Q      Max 
    -0.46187 -0.18506 -0.03391  0.20047  0.40393 
    
    Coefficients:
                 Estimate Std. Error t value Pr(>|t|)   
    (Intercept) 5.3713191  1.1063922   4.855  0.00126 **
    x           0.0018070  0.0008967   2.015  0.07864 . 
    ---
    Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    
    Residual standard error: 0.3021 on 8 degrees of freedom
    Multiple R-squared:  0.3367,    Adjusted R-squared:  0.2538 
    F-statistic: 4.061 on 1 and 8 DF,  p-value: 0.07864
  1. I used raw y values and used log10-transformation within model call: lm = lm(log10(y) ~ x)
> lm = lm(log10(y) ~ x)
> summary(lm)

Call:
lm(formula = log10(y) ~ x)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.20059 -0.08037 -0.01473  0.08706  0.17542 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)   
(Intercept) 2.3327342  0.4805000   4.855  0.00126 **
x           0.0007848  0.0003894   2.015  0.07864 . 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1312 on 8 degrees of freedom
Multiple R-squared:  0.3367,    Adjusted R-squared:  0.2538 
F-statistic: 4.061 on 1 and 8 DF,  p-value: 0.07864

As you can see, models differ between a model with pre-transformed y values lm = lm(log10.y ~ x) and log transformation within the models (2nd and 3rd method). Model lm = lm(log(y) ~ x) and lm = lm(log10(y) ~ x) only differ in intercept and slope, but the overall models are the same which is logical. But I don't understand why there is a difference in whether I first transform data log10.y = log10(y) and use it in the model lm = lm(log10.y ~ x) or use transformation in the formula directly lm = lm(log10(y) ~ x?

I'd be grateful for any help and explanation.

$\endgroup$
4
  • $\begingroup$ I don't know why 1 and 3 are different. Those look like they should be the same. #2 is a natural log transformation, which is a lot more commonly used to transform Y. $\endgroup$ Commented Apr 28, 2022 at 18:17
  • 1
    $\begingroup$ Additionally I tried approach #1 and #3 with R's iris data set and their output was the same. So I'm wondering if there is an issue in code not included in your example. $\endgroup$ Commented Apr 28, 2022 at 18:26
  • $\begingroup$ To make it easier to get help, please provide a minimal reproducible example as explained here: stackoverflow.com/help/mcve. This includes the sample data. In R this is particularly easy with the reprex addin. $\endgroup$
    – dipetkov
    Commented Apr 28, 2022 at 18:29
  • $\begingroup$ @MichaelWebb thanks for the tipp! I checked the data and it looks like I had y and log10.y = log10(y) values (n = 100) a the beginning and used mean values of populations for both mean(y) and mean(log10.y) which gave me 10 values with differences: >y [1] 3.058297 3.168199 3.160605 3.401012 3.278835 3.308509 3.333238 3.239909 3.456366 3.569432 > log10.y [1] 3.043786 3.043178 3.146205 3.320925 3.275831 3.276134 3.264016 3.237092 3.248434 3.458792 I think to make it simple and avoid mistakes I should use raw data and use log transformation in the formula. Thanks a lot! $\endgroup$
    – Natalia
    Commented Apr 28, 2022 at 18:55

0

Your Answer

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