nhs-r-community / NHSRplotthedots

An SPC package to support NHSE/I 'Making Data Count' programme
https://nhs-r-community.github.io/NHSRplotthedots/
Other
47 stars 21 forks source link

Example code in vignette gives short_group warning that appears incorrect #224

Open francisbarton opened 1 month ago

francisbarton commented 1 month ago

As seen in deviations.Rmd.

Each group has 12 points as can be seen in the output from summary() below.

However the warning message still appears, suggesting that "some groups have... < 12 observations".

reprex:

NHSRdatasets::ae_attendances |>
  dplyr::summarise(across("attendances", sum), .by = "period") |>
  NHSRplotthedots::ptd_spc(
    value_field = "attendances",
    date_field = "period",
    rebase = as.Date(c("2017-04-01", "2018-04-01"))
  ) |>
  summary()
#> Warning in ptd_add_short_group_warnings(.): Some groups have 'n < 12'
#> observations. These have trial limits, which will be revised with each
#> additional observation until 'n = fix_after_n_points' has been reached.
#> Plot the Dots SPC options:
#> ===================================
#> value_field:          'attendances'
#> date_field:           'period'
#> facet_field:          not set
#> rebase:               '2017-04-01'
#> rebase:               '2018-04-01'
#> fix_after_n_points:   not set
#> improvement_direction:'increase'
#> target:               not set
#> trajectory:           not set
#> screen_outliers:      'TRUE'
#> -----------------------------------
#> # A tibble: 3 × 9
#>   rebase_group mean_col     lpl    upl     n common_cause special_cause_improv…¹
#>          <dbl>    <dbl>   <dbl>  <dbl> <int>        <int>                  <int>
#> 1            0 1946858.  1.64e6 2.25e6    12           12                      0
#> 2            1 1985843.  1.73e6 2.24e6    12           12                      0
#> 3            2 2068915.  1.81e6 2.33e6    12           12                      0
#> # ℹ abbreviated name: ¹​special_cause_improvement
#> # ℹ 2 more variables: special_cause_concern <int>, variation_type <chr>

Created on 2024-08-08 with reprex v2.1.1

Should the warning say <= 12 or is it being incorrectly triggered?

francisbarton commented 1 month ago

The code that generates the warning is in ptd_add_short_group_warnings.R:

warning_threshold = getOption("ptd_spc.warning_threshold", 13))

As 12 < 13, the warning is being triggered by groups where n = 12. Either the fallback value here needs to be set to 12, or the warning needs to say that:

Some groups have 'n <= 12' observations

or (more accurately, given the code above):

Some groups have 'n < 13' observations