[R] qr.solve and lm (SOLVED)
Vladimir Eremeev
wl2776 at gmail.com
Tue May 15 12:58:04 CEST 2007
Vladimir Eremeev wrote:
>
> Dear R experts,
>
> I have a Matlab code which I am translating to R in order to examine and
> enhance it.
> First of all, I need to reproduce in R the results which were already
> obtained in Matlab (to make sure that everything is correct).
>
> There are some matrix manipulations and '\' operation among them in the
> code.
>
> I have the following data frame
>
>> ABS.df
> Pro syn unk Chl
> Y Nh V1
> [skip]
>
>> qr.solve(ABS.df[,1:6],ABS.df[,7])
> Pro syn unk Chl Y Nh
> 0.3877544 0.4282277 0.2221960 -0.8668715 0.2821082 -1.3696411
>
> This reproduces the Matlab's numbers
> However, I used to lm, its syntax seems to me more clear.
>
> ?lm says that it uses QR decomposition to fit the model.
> Trying it:
>
>> coef(lm(V1~Pro+syn+unk+Chl+Y+Nh,data=ABS.df))
> (Intercept) Pro syn unk Chl
> Y Nh
> 0.001640184 0.417253116 0.351472810 0.196977369 -0.899729874
> 0.265585292 -1.181526491
>
> Numbers differ.
> Obviously, I don't understand something.
> Please, could you clarify, what?
> Thank you.
>
>
This was because of implied intercept term.
> lm(V1~Pro+syn+unk+Chl+Y+Nh+0,data=ABS.df)
Call:
lm(formula = V1 ~ Pro + syn + unk + Chl + Y + Nh + 0, data = ABS.df)
Coefficients:
Pro syn unk Chl Y Nh
0.3878 0.4282 0.2222 -0.8669 0.2821 -1.3696
That is, reproduces earlier results.
--
View this message in context: http://www.nabble.com/qr.solve-and-lm-tf3757650.html#a10620691
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list