tags:

views:

260

answers:

1

I am fitting a simple regression in R on gas usage per capita. The regression formulas looks like:

gas_b<-lm(log(gasq_pop)~log(gasp)+log(pcincome)+log(pn)+log(pd)+log(ps)+log(years),data=gas) summary(gas_b)

I want to include a linear constraint that the beta coefficients of log(pn)+log(pd)+log(ps)=1 (sum to one). Is there a simple way of implementing this (possibly in the lm package) in R without having to use constrOptim() function?

Thanks, Thomas

+6  A: 

Modify your regression as follows:

gas_b <- lm(log(gasq_pop) - log(ps) ~ log(gasp) + log(pcincome) +
  I(log(pn)-log(ps)) + I(log(pd)-log(ps)) + log(years), data=gas) 
summary(gas_b)

If b=coef(gas_b), then the relevant coefficients are

log(pn): b[4]
log(pd): b[5]
log(ps): 1 - b[4] - b[5]
Rob Hyndman
Thanks Rob, ran that and it worked like a charm. However, I couldn't find in the R manual, what the "I" in front of I(log(pn)-log(ps)) and I(log(pd)-log(ps)) stands for?Thanks,Thomas
Thomas
I stands for identity. see help(I).
Rob Hyndman