[R] function to generate weights for lm?
Kingsford Jones
kingsfordjones at gmail.com
Tue Apr 29 19:00:30 CEST 2008
On Tue, Apr 29, 2008 at 6:20 AM, tom soyer <tom.soyer at gmail.com> wrote:
> Hi,
>
> I would like to use a weighted lm model to reduce heteroscendasticity. I am
> wondering if the only way to generate the weights in R is through the
> laborious process of trial and error by hand. Does anyone know if R has a
> function that would automatically generate the weights need for lm?
Hi Tom,
The 'weights' argument to the 'gls' function in the nlme package
provides a great deal of flexibility in estimate weighting parameters
and model coefficients. For example, if you want to model monotonic
heteroscedasticity by estimating the weights $E(Y)^{-2\alpha}$,
you can use the varPower variance function class. E.g., something like
f1 <- gls(y ~ x1 + x2, data = your.data, weights = varPower())
will estimate the regression coefficients and alpha parameter together
via maximum likelihood. (note that the usual specification for varPower is
varPower(form = ~ your.formula), but by default the mean is used. See
Ch 5 of the Pinheiro and Bates Mixed-effects Models book for details)
Kingsford Jones
More information about the R-help
mailing list