Re: [R] function to generate weights for lm?

From: Kingsford Jones <>
Date: Tue, 29 Apr 2008 10:00:30 -0700

On Tue, Apr 29, 2008 at 6:20 AM, tom soyer <> 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 =, 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 mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue 29 Apr 2008 - 19:48:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 Apr 2008 - 20:30:44 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive