# dataset in log & lin-lin regression function vs. dataset not in log & log-log regression function: Why different results in R?

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?

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

• 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!
– TFT
Jun 23 at 10:10