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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With