[R] Weighted Mean Confidence Interval

McGehee, Robert Robert.McGehee at geodecapital.com
Wed Aug 9 21:23:11 CEST 2006

I'm looking to calculate a 95% confidence interval about my estimate for
a sample's weighted mean, where the calculated confidence interval would
equal the t-test confidence interval of the sample in the case when all
of the weights are equal.

My initial thought was to simply implement a modified version of the
t-test function but substituting the weighted variance and mean for the
unweighted variance and mean.

For example:

weighted.ttest.ci <- function(x, weights, conf.level = 0.95) {
    nx <- length(x)
    df <- nx - 1
    vx <- wtd.var(x, weights, normwt = TRUE) ## From Hmisc
    mx <- weighted.mean(x, weights)
    stderr <- sqrt(vx/nx)
    tstat <- mx/stderr ## not mx - mu
    alpha <- 1 - conf.level
    cint <- qt(1 - alpha/2, df)
    cint <- tstat + c(-cint, cint)
    cint * stderr

However, in the below extreme case where the weights are 0 for 8 of the
samples and 1 otherwise we get a much tighter confidence interval rather
than a wider one that I would expect. So it seems that the above
implementation is not correct, and perhaps lacks from some kind of
degrees of freedom adjustment (?).

> weighted.ttest(1:10, c(1, 1, rep(0, 8)))
[1] 1.122974 1.877026

Has anyone implemented a function for calculating confidence intervals
for means about weighted samples, or can anyone provide guidance for
implementing one? I realize I could always bootstrap the sample, but an
analytic (read: fast) solution is desirable if available.

Thanks in advance,

Robert McGehee
Quantitative Analyst
Geode Capital Management, LLC
53 State Street, 5th Floor | Boston, MA | 02109
Tel: 617/392-8396    Fax:617/476-6389
mailto:robert.mcgehee at geodecapital.com

This e-mail, and any attachments hereto, are intended for us...{{dropped}}

More information about the R-help mailing list