3
$\begingroup$

I am trying to find the best transformations for my data to use in a linear model. I call summary(lm(log10(Y)~X3^2) and get a RSE of 0.1787.

Then I saved my data and call a summary of the same data just by the object names summary(lm(log10_Y~X3squared) and get a RSE of 0.1735.

I have checked my saved data and they are correct, i.e., identical to the original columns. How can the RSE be different for identical data?

$\endgroup$
4
$\begingroup$

Your intuition is right - if you use the same variables and fit the same model. The results has to be identical.

Given that the results are different something must have changed.

In fact, you are getting two different results because of how you specify the model.

mod1 = lm(log(Girth)~Volume^2, trees)
summary(mod1)

Vs.

trees$nY = log(trees$Girth)
trees$nX = trees$Volume^2 
mod2 = lm(nY~nX, trees)
summary(mod2)

If we dig a little deeper and compare the data used to fit both models, we will see that they are in fact different

> head(mod1$model)
  log(Girth) Volume
1   2.116256   10.3
2   2.151762   10.3
3   2.174752   10.2
4   2.351375   16.4
5   2.370244   18.8
6   2.379546   19.7

Vs.

> head(mod2$model)
        nY     nX
1 2.116256 106.09
2 2.151762 106.09
3 2.174752 104.04
4 2.351375 268.96
5 2.370244 353.44
6 2.379546 388.09

In mod1 we see that Volume has not been squared!, hence this is the reason why you are seeing different RSEs. The ^ actually has a special meaning when specifying a model formula, you can read more about it here.

If you are trying to fit Volume^2, you can use the following command: lm(log(Girth)~I(Volume^2), trees).

$\endgroup$
2
  • $\begingroup$ That is so helpful, thank you. $\endgroup$ – D.man Apr 27 '20 at 3:52
  • $\begingroup$ No problem. Great question! $\endgroup$ – nwaldo Apr 27 '20 at 4:53

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.