# Fitting models in R where coefficients are subject to linear restriction(s)?

How should I define a model formula in R, when one (or more) exact linear restrictions binding the coefficients is available. As an example, say that you know that b1 = 2*b0 in a simple linear regression model.

$Y(t) = \beta_0 + \beta_1 \cdot X_1(t) + \beta_2 \cdot X_2(t) + \varepsilon(t)$

and you are planning to restrict the coefficients, for instance like:

$\beta_1 = 2 \beta_2$

inserting the restriction, rewriting the original regression model you will get

$Y(t) = \beta_0 + 2 \beta_2 \cdot X_1(t) + \beta_2 \cdot X_2(t) + \varepsilon(t)$

$Y(t) = \beta_0 + \beta_2 (2 \cdot X_1(t) + X_2(t)) + \varepsilon(t)$

introduce a new variable $Z(t) = 2 \cdot X_1(t) + X_2(t)$ and your model with restriction will be

$Y(t) = \beta_0 + \beta_2 Z(t) + \varepsilon(t)$

In this way you can handle any exact restrictions, because the number of equal signs reduces the number of unknown parameters by the same number.

Playing with R formulas you can do directly by I() function

lm(formula = Y ~ I(1 + 2*X1) + X2 + X3 - 1, data = <your data>)
lm(formula = Y ~ I(2*X1 + X2) + X3, data = <your data>)

• This is pretty clear, but the question was suggesting a restriction between b0 and b1. Should I also create a new variable Z = 2X + 1 and fit a model without intercept? – George Dontas Jan 13 '11 at 13:04
• I think usualy I is used instead of eval in formulas, i.e. Y~I(1+2*X1)+X2+X3-1 – mpiktas Jan 13 '11 at 13:21
• @gd047: I have updated with a code pieces, yes it is as you say. @mpiktas: will change this, yes it is shorter ;) – Dmitrij Celov Jan 13 '11 at 13:21
• This is a good answer for the general theoretical approach, but for an easier way to actually implement these hypotheses in R, which also has the advantage of not requiring one to estimate multiple models, see linearHypothesis() in the car package. – Jake Westfall May 23 '13 at 22:13