Modelli di raccordo in R in cui i coefficienti sono soggetti a restrizioni lineari


16

Come dovrei definire una formula modello in R, quando sono disponibili una (o più) restrizioni lineari esatte che legano i coefficienti. Ad esempio, supponiamo che tu sappia che b1 = 2 * b0 in un modello di regressione lineare semplice.

Grazie!

Risposte:


16

Supponiamo che il tuo modello sia

Y(t)=β0+β1X1(t)+β2X2(t)+ε(t)

e stai pianificando di limitare i coefficienti, ad esempio come:

β1=2β2

inserendo la restrizione, riscrivendo il modello di regressione originale che otterrai

Y(t)=β0+2β2X1(t)+β2X2(t)+ε(t)

Y(t)=β0+β2(2X1(t)+X2(t))+ε(t)

introduce a new variable Z(t)=2X1(t)+X2(t) and your model with restriction will be

Y(t)=β0+β2Z(t)+ε(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

2
I think usualy I is used instead of eval in formulas, i.e. Y~I(1+2*X1)+X2+X3-1
mpiktas

@gd047: I have updated with a code pieces, yes it is as you say. @mpiktas: will change this, yes it is shorter ;)
Dmitrij Celov

4
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
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.