# How does “rlm” in R decide its “w” weights?

Following user603's advice, I opened a new question thread for this question.

For your reference, the original question is here:

Pointers to understand "rlm" in R better?

My question is:

How does "rlm" decide its "w" for each IRLS iteration then?

Also, is my understanding below correct?

The input argument "w" is used for the initial values of the rlm IRLS weighting and the output value "w" is the converged "w".

The "weights" input argument is actually what I want to apply.

And the real/actual weights are the product of "weights"(I supplied) and the converged output "w" (an output).

Thanks to all.

-
It is not really clear to me what you want to achieve with those weights. Do you expect them to interact with the robust fitting procedure? –  user603 Jul 19 '12 at 8:43
If my understanding is correct, i.e. my own weights can be supplied thru "weights", and the IRLS itself maintains a set of weights which is "w", and the final actually used weights are the product of my weights and the converged/output "w" weights. Then I am looking for the calculation of the "w"'s at each iteration. The reason is I am actually solving a problem and I casted it into a "rlm" problem and used "rlm" to solve it, but I have to make sure its weighting scheme in IRLS is the one what I intended. Thank you! –  Luna Jul 19 '12 at 13:57

Several things:

• Use the lmrob() implementation in the robustbase package. Avoid the MASS implementations and its strange default behaviors. Then, the lmrob() function does indeed not accept weights to interfer with the robust fitting procedure (which, in my understanding, is the sane behavior) so you have do the weighting "outside" of it:

library(robustbase)
x<-matrix(rnorm(100*2),100,2)
y<-x%*%(c(3,-1))+rnorm(100)-3
mod<-lmrob(y~x)
myinitiweights<-runif(100)
myinitiweights<-myinitiweights/sum(myinitiweights)
myfinalweights<-myinitiweights*mod\$weights
myfinalfitwols<-lm(y~x,w=myfinalweights)

• For more info on IRLS and robust regression, have a look at this report(1) (page 16 onwards)

(1): Robust Regression, C. Stuart, April, 2011 report.

EDIT:

should you want to have your myinitiweights have an influence on the IRLS algorithm then you have to add in the weights before the call to lmrob():

yw<-y*sqrt(myinitiweights)
xw<-cbind(1,x)*sqrt(myinitiweights)
wm<-lmrob(yw~xw-1)
coef(wm)


but read the report i linked to on IRLS and ask yourself if this is really the best way to achieve what you are trying to achieve.

-
Thanks user603. Q1. Could you please tell us why should we avoid MASS implementation? Q2. "lmrob" doesn't accept initial/starting points of the weights? What about the local-optima? Q3. Your "myinitiweights" is not those initial/starting points for IRLS, these are our own weights to multiply the output/converged weights with, am I right? –  Luna Jul 19 '12 at 14:01
Q1: MASS was IMHO designed to illustrate a book. As I mentioned in a related comment, some of the default choices are not in accordance with the field's state of the art practices. Most implementations are slower than those found in the specialized packages pointed to in the task view. Q2: no. Q3 yes. see also my edit. –  user603 Jul 19 '12 at 14:38