Skip to contents

Apply 30-Day Aging Bins

Usage

bin_aging(df, ndays, bin_type = c("case", "chop"))

Arguments

df

<data.frame> or <tibble>

ndays

<dbl> column of counts of days elapsed to bin by

bin_type

<chr> string specifying the bin type; one of "chop", "cut" or "ivs"

Value

a tibble

Examples

mock_claims(100) |>
  dplyr::mutate(
    dar = dplyr::if_else(
      !is.na(date_reconciliation),
      as.numeric((date_reconciliation - date_service)),
      as.numeric((date_adjudication - date_service))
    )
  ) |>
    bin_aging(dar, "chop") |>
    dplyr::summarise(
      n_claims = dplyr::n(),
      balance = sum(balance, na.rm = TRUE),
      .by = c(aging_bin))
#> # A tibble: 2 × 3
#>   aging_bin n_claims balance
#>   <fct>        <int>   <dbl>
#> 1 (30, 60]        61   5861.
#> 2 (0, 30]         39   2813.

mock_claims(10)[c(
  "date_service",
  "charges",
  "payer")] |>
  days_between(date_service) |>
  bin_aging(days_elapsed)
#> # A tibble: 10 × 5
#>    date_service charges payer             days_elapsed aging_bin
#>    <date>         <dbl> <fct>                    <int> <fct>    
#>  1 2024-06-23      189. Allianz                     29 0-30     
#>  2 2024-06-22      119. Mass Mutual                 30 0-30     
#>  3 2024-06-12      145. Mass Mutual                 40 31-60    
#>  4 2024-06-08      141. GuideWell                   44 31-60    
#>  5 2024-06-08       31. UnitedHealth                44 31-60    
#>  6 2024-05-26       14. Allianz                     57 31-60    
#>  7 2024-05-13      225. Medicare                    70 61-90    
#>  8 2024-05-12       16. Elevance (Anthem)           71 61-90    
#>  9 2024-04-20      186. BCBS MI                     93 91-120   
#> 10 2024-04-19       59. HCSC                        94 91-120   

load_ex("aging_ex") |>
  dplyr::select(dos, charges, ins_name) |>
  days_between(dos) |>
  bin_aging(days_elapsed) |>
  dplyr::arrange(aging_bin) |>
  dplyr::group_by(
    year = clock::get_year(dos),
    month = clock::date_month_factor(dos),
  ) |>
  janitor::tabyl(ins_name, aging_bin, year)
#> $`2023`
#>    ins_name 61-90 91-120 121+
#>       AETNA     0      0    6
#>  Blue Cross     0      0   13
#>       CIGNA     0      0    6
#>    Coventry     0      0    0
#>    Medicare     0      0    9
#>     Patient     0      0   24
#> 
#> $`2024`
#>    ins_name 61-90 91-120 121+
#>       AETNA    84     30  134
#>  Blue Cross   207     87  228
#>       CIGNA   116     37  120
#>    Coventry    11      4   15
#>    Medicare   188     74  226
#>     Patient   396    157  446
#>