I have a simple matrix:
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
[4,] 10 11 12
I have to calculate linear regression and orthogonal regression using lm() and prcomp() respectively. (for orthogonal see: here)
Assume that the first column is the the X and M the matrix I wrote before.
LINEAR REG.
mod1 <- lm(M[,1] ~ M[,2] + M[,3] + 0)
Its output is (coefficient):
Coefficients: M[, 2] M[, 3]
2 -1
Ok, I have these coefficients.
Now for
ORTHOGONAL REG.
mod2 <- prcomp(~ M[,1] + M[,2] + M[,3])
Its output is:
PC1 PC2 PC3
M[, 1] 0.5773503 0.0000000 0.8164966
M[, 2] 0.5773503 -0.7071068 -0.4082483
M[, 3] 0.5773503 0.7071068 -0.4082483
The question is: out to interpret prcomp() result instead of lm() result ? Using lm() the coefficients are using to predict the X values.
What about prcomp() ?
Thank you!
lm()
. I get-1, 1, NA
for the data/model you show, which is correct given the linear dependencies in the example data. Don't forget that the intercept is also a coefficient, so your model actually has three coefficients. $\endgroup$