[R] Case weighting

Thomas Lumley tlumley at uw.edu
Sat Mar 3 23:08:12 CET 2012


On Sun, Mar 4, 2012 at 8:04 AM, Hed Bar-Nissan <hed.barnissan at gmail.com> wrote:
> Following David example if i just wanted to do means
> would multiplying the cases according to the weight do the work?

If the weights are scaled to have mean 1, and you have no missing
data, then yes.  If you have missing data, the scaling to mean 1 would
be different for different variables.

>
> Something like this on a data.frame
> (Must be a simpler way to do it with R - the sapply scope confused me)

Yes, there must.  For a start, assign() is not your friend.

You should either use a simple weighted.mean() function (your own or
Frank Harrell's), or if you really want to package the weights with
the data, you would be better off doing it thoroughly and using the
survey package.


   -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland



More information about the R-help mailing list