[R] weighted quantiles

0 views
Skip to first unread message

sj

unread,
Oct 7, 2008, 2:38:03 PM10/7/08
to r-help
I have a set of values and their corresponding weights. I can use the
function weighted.mean to calculate the weighted mean, I would like to be
able to similarly calculate the weighted median and quantiles? Is there a
function in R that can do this?

thanks,


Spencer

[[alternative HTML version deleted]]

______________________________________________
R-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Frank E Harrell Jr

unread,
Oct 7, 2008, 3:13:22 PM10/7/08
to sj, r-help
sj wrote:
> I have a set of values and their corresponding weights. I can use the
> function weighted.mean to calculate the weighted mean, I would like to be
> able to similarly calculate the weighted median and quantiles? Is there a
> function in R that can do this?
>
> thanks,
>
>
> Spencer

library(Hmisc)
?wtd.quantile

Brian S Cade

unread,
Oct 7, 2008, 3:07:48 PM10/7/08
to sj, r-help-...@r-project.org, r-help
Try the linear quantile regression function rq() in the quantreg package.
For 1 sample estimates, your model would have just an intercept term.
There is a weight argument.

quantiles.out <- rq(y ~ 1, data=mydata, tau=1:9/10, weight=myweights)

would yield the 0.10, 0.20, ..., 0.80, 0.90 weighted quantile estimates.

Brian

Brian S. Cade, PhD

U. S. Geological Survey
Fort Collins Science Center
2150 Centre Ave., Bldg. C
Fort Collins, CO 80526-8818

email: brian...@usgs.gov
tel: 970 226-9326

sj <ssj...@gmail.com>
Sent by: r-help-...@r-project.org
10/07/2008 12:38 PM

To
r-help <r-h...@stat.math.ethz.ch>
cc

Subject
[R] weighted quantiles

Norbert NEUWIRTH

unread,
Oct 22, 2008, 7:28:00 AM10/22/08
to Frank E Harrell Jr, sj, r-help
Dear Frank,

Thank you for your usefull package Hmisc! I use it in my microsimulation project every day. But now a problem arose ...

....Having updated to R 2.8.0 (under windows XP) your library "Hmisc" isn't installed any more. Trying to reinstal I recognized, that it isn't even in the package list. When trying to reinstal it via local zip-sources I get the error-message (wrong R version ... ).

Will the Hmisc-package be updated or are their functions now embedded within another package??

Thanks,

Norbert

--
**********************************************************
Mag. Norbert Neuwirth

Österreichisches Institut für Familienforschung (ÖIF) - Universität Wien
Austrian Institute for Family Studies - University of Vienna

http://www.oif.ac.at

e-mail: norbert....@oif.ac.at
tel: +43-1-4277-489-11
fax: +43-1-4277-9-489
address: A-1010 Wien, Grillparzerstraße 7/9

Reply all
Reply to author
Forward
0 new messages