# [R] why does lm() not allow for negative weights?

Jens Hainmueller jhainm at fas.harvard.edu
Fri Aug 4 19:45:28 CEST 2006

```Thanks Duncan Murdoch,

> > Why do commonly used estimator functions (such as lm(),
> > glm(), etc.)
> > not allow negative case weights?

> Residual sums of squares (or deviances) could be negative
> with negative case weights.  This doesn't seem like a good
> thing:  would you really want the fit to be far from those points?

Yes, this is actually what I want for this particular estimator. But I can
see now why this generally doesn't seem like a a good idea.

Best,
Jens

> -----Ursprüngliche Nachricht-----
> Von: Duncan Murdoch [mailto:murdoch at stats.uwo.ca]
> Gesendet: Friday, August 04, 2006 7:36 PM
> An: Jens Hainmueller
> Cc: r-help at stat.math.ethz.ch
> Betreff: Re: [R] why does lm() not allow for negative weights?
>
> On 8/4/2006 1:26 PM, Jens Hainmueller wrote:
> > Dear List,
> >

>

>
>  > I suspect that there is a good reason for this.
> > Yet, I can see reasonable cases when one wants to use
> negative case weights.
> >
> > Take lm() for example:
> >
> > ###
> >
> > n <- 20
> > Y <- rnorm(n)
> > X <- cbind(rep(1,n),runif(n),rnorm(n)) Weights <- rnorm(n)
> # Includes
> > Pos and Neg Weights Weights
> >
> > # Now do Weighted LS and get beta coeffs:
> > b <- solve(t(X)%*%diag(Weights)%*%X) %*% t(X) %*% diag(Weights)%*%Y
>
> That formula does not necessarily give least squares
> estimates in the case where weights might be negative.  For
> example, with a single observation y, a single parameter mu,
> design matrix X = 1, and weight -1, that formula becomes
>
> b <- y,
>
> but that is the worst possible estimator in a least squares
> sense.  The residual sum of squares can be made arbitrarily
> large and negative by setting b to a large value.
>
> Duncan Murdoch
>
>
> > b
> >
> > # This seems like a valid model, but when I try lm(Y ~
> > X[,2:3],weights=Weights)
> >
> > # I get: "missing or negative weights not allowed"
> >
> > ###
> >
> > What is the rationale for not allowing negative weights? I
> > because I am currently trying to implement a (two stage) estimator
> > into R that involves negative case weights. Weights are
> generated in
> > the first stage, so it would be nice if I could use canned
> functions
> > such as
> > lm(,weights=Weights) in the second stage.
> >
> > Thank you for your help.
> >
> > Best,
> > Jens
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help