I am trying to calculate multiple regression in R
without intercept.
My data is as follow:
y <- c(60.323,61.122,60.171,61.187,63.221,63.639,64.989,63.761,66.019,67.857,68.169,66.513,68.655,69.564,69.331,70.551)
x1 <- c(83,88.5,88.2,89.5,96.2,98.1,99,100,101.2,104.6,108.4,110.8,112.6,114.2,115.7,116.9)
x2 <- c(107.608,108.632,109.773,110.929,112.075,113.27,115.094,116.219,117.388,118.734,120.445,121.95,123.366,125.368,127.852,130.081)
In this case, (I believe?) I am getting the coefficients WITH intercept:
lm(formula = y ~ x1 + x2)
I would like to get the coefficients WITHOUT intercept. I tried this:
lm(formula = y ~ x1 + x2 -1)
Is this correct? If so, my question would be: How can I calculate WITHOUT intercept without changing the x values (on the right side of the tilde), but by changing something on the y value (on the left side of the tilde). For instance:
lm(formula = y -1 ~ x1 + x2)
Gets a different (and presumably incorrect coefficient estimation).
I know your question is ... why do you have to only change the y values? The reason is because I am writing code in C to do this, and I do not want to change the dimensions of X by adding a -1 at the end because that would require dynamic array allocation, which is very meticulous for me.
- 1
on the LHS just subtracts 1 from the DV. Coefficients are only estimated for the RHS. I'm not sure I follow your rationale. $\endgroup$?lm
. In order to remove intercept you can do eithery ~ x - 1
ory ~ 0 + x
solm(formula = y ~ x1 + x2 -1)
or similarlylm(formula = y ~ 0 + x1 + x2)
is the way to go. $\endgroup$