Skip to contents

Compare principal, secondary-only, and any-position diagnosis definitions.

Usage

nis_audit_dx_position(
  .data,
  code,
  system = c("icd10", "icd9"),
  weight_var = "DISCWT",
  outcomes = tidyselect::any_of(c("DIED", "ELECTIVE"))
)

Arguments

.data

A data frame or lazy DuckDB query.

code

Non-missing character vector of diagnosis prefixes.

system

Code system of the diagnosis slots: "icd10" (default) or "icd9" (experimental, NIS 2012 to Q3 2015).

weight_var

Name of the discharge weight column. Defaults to DISCWT.

outcomes

<tidy-select> Outcome columns to summarize. By default, selects DIED and ELECTIVE when present. Use NULL to omit rates or all_of() to select a character vector of names. Use name-based selectors on DuckDB queries.

Value

A collected tibble with one row per presentation and unweighted and weighted counts, shares of all prefix-positive presentations, and rates for requested outcomes. The principal presentation is a strict subset of any-position cases, so Cohen's kappa is not meaningful here. Existing input groups are ignored: summaries describe the full input. Empty inputs return zero counts and missing shares and rates. Missing weights are omitted from weighted sums; missing outcomes are excluded from that outcome's denominator. Rates with zero denominators are missing.

Details

The result describes how the diagnosis position changes counts and selected outcome rates. Use nis_design() to estimate standard errors. Review disclosure before sharing the results.

Examples

nis <- nis_open(nis_example(years = 2019))
nis_audit_dx_position(nis, "I50")
#> # A tibble: 3 × 9
#>   presentation n_unweighted n_weighted pct_of_any_unweighted pct_of_any_weighted
#>   <chr>               <dbl>      <dbl>                 <dbl>               <dbl>
#> 1 principal              54       62.4                   100                 100
#> 2 secondary_o…            0        0                       0                   0
#> 3 any                    54       62.4                   100                 100
#> # ℹ 4 more variables: DIED_rate_unweighted <dbl>, DIED_rate_weighted <dbl>,
#> #   ELECTIVE_rate_unweighted <dbl>, ELECTIVE_rate_weighted <dbl>
outcome_names <- c("ELECTIVE", "DIED")
nis_audit_dx_position(nis, "I50", outcomes = tidyselect::all_of(outcome_names))
#> # A tibble: 3 × 9
#>   presentation n_unweighted n_weighted pct_of_any_unweighted pct_of_any_weighted
#>   <chr>               <dbl>      <dbl>                 <dbl>               <dbl>
#> 1 principal              54       62.4                   100                 100
#> 2 secondary_o…            0        0                       0                   0
#> 3 any                    54       62.4                   100                 100
#> # ℹ 4 more variables: ELECTIVE_rate_unweighted <dbl>,
#> #   ELECTIVE_rate_weighted <dbl>, DIED_rate_unweighted <dbl>,
#> #   DIED_rate_weighted <dbl>