[R] weighted m-estimator

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Dec 8 10:29:04 CET 2005

On Thu, 8 Dec 2005, Daniel Metzler wrote:

> Dear R listers,
> I'm trying use Huber's m-estimator on a dataset, which works fine so
> far.

Huber's M-estimator of what?  Location, scale, regression, AR coefficients 
....  What software are you using to do so?

> In the next step I would like to assign a (frequency) weight to the
> observations.
> It seemed straight forward to me to replicate the rows according to
> their count variable.
> Unfortunately,  a solution provided by jim holtman on Wed 19 Oct 2005
> in this list doesn't work for me:
> > y <- unlist(lapply(seq(nrow(x)), function(.row)rep(.row, x$count
> [.row])))
> # replicate the row numbers
> > y
> > result <- x[y,] # pick out the rows
> > result$count <- 1 # set the count to 1
> > result
> R keeps crashing. I presume because of 800,000 rows, which should be
> produced.

R should not `crash', but the posting guide does ask you not to use that 
word but give the exact messages received.  Running out of memory is not a 

> Does a smarter solution exist for weighting the observations
> according to their frequency than manually replicating rows when
> using the huber function?

Yes.  I have no idea what you are trying to do, but if it is regression, 
rlm in package MASS has case weights.  (Location estimation is a special 
case of regression.)

Please do read the posting guide and try to give us the information needed 
to answer your question.  In particular, do give credit if you are using a 
contributed package (including the recommended contributed package).

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list