Skip to contents

Estimate means, totals, and supported survey-weighted models in DuckDB.

Usage

nis_survey(.data, weights = DISCWT)

Arguments

.data

A lazy DuckDB query from nis_open().

weights

A data-masked SQL-translatable expression for the analysis weights. The default uses discharge weights without annualization.

Value

A lazy nis_survey design.

Details

Use dplyr::filter() on the design to define a domain while retaining the original sample for variance. Invalid design fields are excluded when defining the sample.

Use survey::svymean(), survey::svytotal(), and survey::svyby() for summaries. survey::svyglm() supports additive Gaussian identity, binomial and quasibinomial logit, and Poisson and quasipoisson log models. Use nis_design() for interactions, offsets, survey quantiles, chi-square tests, or gtsummary::tbl_svysummary().

The design supports the "fail" and "adjust" settings of survey.lonely.psu and honors survey.adjust.domain.lonely.

Examples

nis <- nis_open(nis_example(2019:2020))
design <- nis_survey(nis)
older <- dplyr::filter(design, AGE >= 65)
survey::svymean(~LOS, older)
#>       mean     SE
#> LOS 4.5771 0.2929
survey::svyby(~LOS, ~YEAR, older, survey::svymean)
#>      YEAR      LOS        se
#> 2019 2019 4.577143 0.4142243
#> 2020 2020 4.577143 0.4142243