Weighted Least Square

混江龙づ霸主 提交于 2019-12-30 06:44:46

问题


I want to do a regression of y~x (just 1 dependent and 1 independent variable) but I have heteroskedasticity. The variability of y increases as x increases. To deal with it, I would like to use weighted least squares through the "gls()" function in R.

But I have to admit that I don't understand how to use it. I have to apply a variance function to the "weights" argument of the gls function. But I don't which one to choose and how to use it.


回答1:


Here's an example of taking care of poisson count like data where the variation will be proportional to the mean (which it sounds like you have).

fit = lm (y ~ x, data=dat,weights=(1/dat$x^2))

You use the recipricol as the weight since you will be multiplying the values. You square it for taking care of Poisson count data because the variance has units squared. You can do something like:

fit = lm (y ~ x, data=dat,weights=(1/dat$x))

To simply scale it by the x value and see what works better.



来源:https://stackoverflow.com/questions/17408439/weighted-least-square

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