[R] Flat tables for confidence intervals with "survey" package

Michael.Laviolette at dhhs.state.nh.us Michael.Laviolette at dhhs.state.nh.us
Wed Feb 4 16:16:55 CET 2015


I'm preparing some reports for substate regions from BRFSS survey data. I
can get estimates easily enough, but am having problems putting the results
in convenient form. Here's some code using the New Hampshire portion of the
public BRFSS "SMART" data:

library(foreign)
library(survey)
# download and extract http://www.cdc.gov/brfss/smart/2012/CNTY12XPT.zip
nh.smart <- svydesign(ids = ~0, strata = ~X_STSTR, weights = ~X_CNTYWT,
                      data = subset(read.xport("CNTY12.xpt"), X_STATE ==
33))
# using asthma status as example
nh.smart <- update(nh.smart,
  X_ASTHMS1 = factor(X_ASTHMS1, levels = 1:3,
                     labels = c("Current","Former","Never")),
  X_CNTY = factor(X_CNTY, labels = c("Belknap","Carroll","Cheshire","Coos",
                                     "Grafton","Hillsborough","Merrimack",
                                     "Rockingham","Strafford")))
a <- svyby(~X_ASTHMS1, ~X_CNTY, nh.smart, svymean, na.rm = TRUE,
           vartype = "ci")

Is there a convenient way to get a flat table similar to the following? I'm
not having much success with "ftable."

Thanks in advance,
Michael L.

#                    Percent   LCI   UCI
# Belknap   Current     10.4   5.6  15.3
#           Former       1.5   0.4   2.7
#           Never       88.1  83.1  93.0
# Carroll   Current      7.5   4.9  10.1
#           Former       2.9   1.3   4.5
#           Never       89.6  86.5  92.7
# ...



More information about the R-help mailing list