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.


locked by whuber Feb 3 at 12:37

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. See the help center for guidance on writing a good question.

Read more about locked posts here.

  • $\begingroup$ You can't. Including - 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$ – Roland Mar 24 '15 at 13:04
  • $\begingroup$ I am not sure I follow you rationale either. Anyway... this may be of help: model.matrix() returns the design matrix of your model object. $\endgroup$ – ocram Mar 24 '15 at 13:05
  • $\begingroup$ This is documented in ?lm. In order to remove intercept you can do either y ~ x - 1 or y ~ 0 + x so lm(formula = y ~ x1 + x2 -1) or similarly lm(formula = y ~ 0 + x1 + x2) is the way to go. $\endgroup$ – David Arenburg Mar 24 '15 at 13:10
  • 1
    $\begingroup$ @DavidArenburg Please read my comment again and more carefully. I'm not wrong. $\endgroup$ – Roland Mar 24 '15 at 13:12
  • $\begingroup$ @Roland, right, you meant to the second option mentioned by the OP. $\endgroup$ – David Arenburg Mar 24 '15 at 13:14

The formula

lm(formula = y ~ x1 + x2)

will include an intercept by default.

The formula

lm(formula = y ~ x1 + x2 -1)


lm(formula = y ~ x1 + x2 +0)

is how R estimates an OLS model without an intercept. The formula

lm(formula = y-1 ~ x1 + x2)

estimates a model against a dependent variable y with 1 subtracted from it.

Centering all terms at their mean will also enforce a zero intercept.


Not the answer you're looking for? Browse other questions tagged or ask your own question.