Korn and Graubard confidence intervals for proportions, adjusted for degrees of freedom
Source:R/svyciprop_adjusted.R
svyciprop_adjusted.RdA version of survey::svyciprop( method = "beta" ) that adjusts for the degrees of freedom.
Usage
svyciprop_adjusted(
formula,
design,
level = 0.95,
adj = "none",
aa_vr = NULL,
aa_pop = NULL,
...
)Arguments
- formula
see
survey::svyciprop().- design
see
survey::svyciprop().- level
see
survey::svyciprop().- adj
adjustment to the Korn and Graubard confidence intervals:
"none"(default),"NCHS", or"NHIS".- aa_vr
used to produce age-adjusted confidence intervals only. The name of a categorical age variable located in
design.- aa_pop
used to produce age-adjusted confidence intervals only. A
data.framewith columns namedLevelandPopulation.Levelmust exactly match the levels ofaa_vr.Populationis the population count or proportion/weight for that level ofaa_vr.- ...
see
survey::svyciprop().
Details
adj specifies the adjustment to the Korn and Graubard confidence intervals.
"none": No adjustment is performed. Produces standard Korn and Graubard confidence intervals, same assurvey::svyciprop( method = "beta" )."NCHS": Adjustment that might be required by some (though not all) NCHS data systems. With this adjustment, the degrees of freedom is set todegf(design). Consult the documentation for the data system that you are analyzing to determine if this is the appropriate adjustment."NHIS": Adjustment that might be required by NHIS. With this adjustment, the degrees of freedom is set tonrow(design) - 1. Consult the documentation for the data system that you are analyzing to determine if this is the appropriate adjustment.
To use these adjustments in surveytable tabulations, call set_survey() or set_opts() with the
appropriate mode or adj argument. Age-adjustment can be turned on with set_survey(). But if
adj = "none", no age-adjustment is performed.
For age-adjustment, aa_pop$Population can contain either population counts
or proportions/weights for each level. Values are normalized internally, so
counts and proportions produce the same confidence intervals when they
describe the same standard population distribution.
Originally written by Makram Talih (2019). Age-adjusted calculation based on Natalie Young (2026).
Examples
set_survey(namcs2019sv)
#> Survey info {NAMCS 2019 PUF}
#> ┌───────────┬──────────────┬────────────────────────────────────────────────┐
#> │ Variables │ Observations │ Design │
#> ├───────────┼──────────────┼────────────────────────────────────────────────┤
#> │ 33 │ 8,250 │ Stratified 1 - level Cluster Sampling design │
#> │ │ │ (with replacement) │
#> │ │ │ With (398) clusters. │
#> │ │ │ namcs2019sv = survey::svydesign(ids = ~CPSUM, │
#> │ │ │ strata = ~CSTRATM, weights = ~PATWT │
#> │ │ │ , data = namcs2019sv_df) │
#> └───────────┴──────────────┴────────────────────────────────────────────────┘
#>
set_opts(adj = "NCHS")
#> * Korn and Graubard confidence intervals for proportions with an adjustment that might be required by some (though not all) NCHS data systems.
tab("AGER")
#> Patient age recode (knowns only) {NAMCS 2019 PUF}
#> ┌─────────────┬───────┬─────────────┬──────────┬──────────┬──────────┬─────────┬─────┬──────┬──────┐
#> │ Level │ n │ Number │ SE (000) │ LL (000) │ UL (000) │ Percent │ SE │ LL │ UL │
#> │ │ │ (000) │ │ │ │ │ │ │ │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ Under 15 │ 887 │ 117,917 │ 14,097 │ 93,229 │ 149,142 │ 11.4 │ 1.3 │ 8.9 │ 14.2 │
#> │ years │ │ │ │ │ │ │ │ │ │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 15-24 years │ 542 │ 64,856 │ 7,018 │ 52,387 │ 80,292 │ 6.3 │ 0.6 │ 5.1 │ 7.5 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 25-44 years │ 1,435 │ 170,271 │ 13,966 │ 144,925 │ 200,049 │ 16.4 │ 1.1 │ 14.3 │ 18.8 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 45-64 years │ 2,283 │ 309,506 │ 23,290 │ 266,994 │ 358,787 │ 29.9 │ 1.4 │ 27.2 │ 32.6 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 65-74 years │ 1,661 │ 206,866 │ 14,366 │ 180,481 │ 237,109 │ 20 │ 1.2 │ 17.6 │ 22.5 │
#> ├─────────────┼───────┼─────────────┼──────────┼──────────┼──────────┼─────────┼─────┼──────┼──────┤
#> │ 75 years │ 1,442 │ 167,069 │ 15,179 │ 139,746 │ 199,735 │ 16.1 │ 1.3 │ 13.7 │ 18.8 │
#> │ and over │ │ │ │ │ │ │ │ │ │
#> └─────────────┴───────┴─────────────┴──────────┴──────────┴──────────┴─────────┴─────┴──────┴──────┘
#> N = 8250. Checked NCHS presentation standards. Nothing to report.
#>
set_opts(adj = "none")
#> * Korn and Graubard confidence intervals for proportions.