Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weighted Least Square

Tags:

r

regression

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.

like image 934
user1671537 Avatar asked Jul 01 '13 15:07

user1671537


1 Answers

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.

like image 120
Chrismit Avatar answered Nov 15 '22 01:11

Chrismit