简体   繁体   中英

Weighted Least Square

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM