Constrained least squares

百般思念 提交于 2020-01-10 19:59:33

问题


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 function) in R without having to use constrOptim() function?


回答1:


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]


来源:https://stackoverflow.com/questions/1551554/constrained-least-squares

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!