0
$\begingroup$

I've discovered by chance that R produces different results when using a dataset which has been first transformed by the natural logarithm and then loaded into R for analysis and when the dataset is loaded without prior transformation and only the variables in the regression function are transformed by the natural logarithm in R. Here an illustration:

dataset already transformed, lin-lin regression in R

ols <- lm(Y ~ X, data = Dataset_log)

vs.

dataset not transformed, log-log regression in R

ols <- lm(log(Y) ~ log(X), data = Dataset_not_in_log)

It seems that only the intercept in both regressions is different (magnitude and standard error). All other coefficients have the same estimator and the same standard errors. Nonetheless, this has naturally an impact on the overall F-statistic and the residual standard errors. Why are the results different?

$\endgroup$
0

1 Answer 1

1
$\begingroup$

That should not be happening. Perhaps your "already transformed" data takes a different type of logarithm. To take a toy example when I try

Dataset_not_in_log <- data.frame(X=c(10,12,19,25), Y=c(345,234,789,678))
Dataset_log <- log(Dataset_not_in_log)
ols1 <-  lm(Y ~ X, data = Dataset_log)
ols2 <- lm(log(Y) ~ log(X), data = Dataset_not_in_log)

gives

> summary(ols1)

Call:
lm(formula = Y ~ X, data = Dataset_log)

Residuals:
      1       2       3       4 
 0.2115 -0.3821  0.3157 -0.1451 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   3.0381     1.5005   2.025    0.180
X             1.1265     0.5433   2.073    0.174

Residual standard error: 0.3946 on 2 degrees of freedom
Multiple R-squared:  0.6825,    Adjusted R-squared:  0.5237 
F-statistic: 4.299 on 1 and 2 DF,  p-value: 0.1739

and the similar looking

> summary(ols2)

Call:
lm(formula = log(Y) ~ log(X), data = Dataset_not_in_log)

Residuals:
      1       2       3       4 
 0.2115 -0.3821  0.3157 -0.1451 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   3.0381     1.5005   2.025    0.180
log(X)        1.1265     0.5433   2.073    0.174

Residual standard error: 0.3946 on 2 degrees of freedom
Multiple R-squared:  0.6825,    Adjusted R-squared:  0.5237 
F-statistic: 4.299 on 1 and 2 DF,  p-value: 0.1739
$\endgroup$
1
  • 1
    $\begingroup$ Thanks for your reply. I've just found out that my dataset was transformed using the basis of 10 in excel but I guess that R uses e as a basis, the reason for the different reasons. Thanks for taking your time for answering my question! $\endgroup$
    – TFT
    Jun 23 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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