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)
.