This package provides functions to detect Funnel plot and Statistical Process Control patterns.
The pattern_detection function extracts the most recent
detected SPC and Funnel pattern for each indicator and group
combination.
The data that feeds into the pattern_detection function
should be in a long format and contain the following columns:
indicator - A vector to denote the indicator group.
Used to calculate aggregate SPC and Funnel Plotsgroup - A vector of group names. Used to aggregate and
group points on plotsperiod_end - A date (or character of format
“yyyy-mm-dd”) for the end date of the period.numerator - A vector of the numerator. Used to
calculate the value for SPC and Funnel plotsdenominator - A vector of the denominator Used to
calculate the value for SPC and Funnel plotsmultiplier - Scale relative risk and funnel by this
factor.better_is - A string identifying the direction that is
favourable for the indicator. “Higher” for points below the lower
control limit to be unfavourable, “Lower” for points above the upper
control limit to be unfavourable, and “Neutral” if the direction is not
stated.parent_group_name - A vector of parent group names
which are to be displayed in the tooltip. These are the major categories
for the groups.spc_chart_type - A string identifying the type of SPC
chart.funnel_chart_type - A string identifying the type of
funnel plot.parent_indicator - A vector used for parent indicator
categorisation. i.e. categorising together maternity related indicators
into a Maternity parent.indicator_name - A vector of descriptive names for
indicator.group_name - A vector of descriptive names for groups
Default group variablefunnel_data_points - A vector of “Yes” or NA, marks
which data points are included in the funnel plot calculation.An example of this is shown below using the
example_spc_data dataset:
head(example_spc_data)
#> indicator group period_end period_start numerator
#> <char> <char> <Date> <Date> <int>
#> 1: Standardised Mortality Ratio A 2021-01-31 2021-01-01 6
#> 2: Standardised Mortality Ratio A 2021-02-28 2021-02-01 4
#> 3: Standardised Mortality Ratio A 2021-03-31 2021-03-01 4
#> 4: Standardised Mortality Ratio A 2021-04-30 2021-04-01 4
#> 5: Standardised Mortality Ratio A 2021-05-31 2021-05-01 8
#> 6: Standardised Mortality Ratio A 2021-06-30 2021-06-01 4
#> denominator multiplier better_is spc_chart_type funnel_chart_type
#> <num> <num> <char> <char> <char>
#> 1: 4.379261 100 Lower i SR
#> 2: 3.778151 100 Lower i SR
#> 3: 4.398701 100 Lower i SR
#> 4: 4.913439 100 Lower i SR
#> 5: 4.950847 100 Lower i SR
#> 6: 3.115129 100 Lower i SRThe dataset is then passed to the pattern_detection
function to detect SPC and Funnel patterns:
pattern_detection_data <- pattern_detection(
indicator = example_spc_data$indicator,
group = example_spc_data$group,
period_end = example_spc_data$period_end,
numerator = example_spc_data$numerator,
denominator = example_spc_data$denominator,
multiplier = example_spc_data$multiplier,
better_is = example_spc_data$better_is,
spc_chart_type = example_spc_data$spc_chart_type,
funnel_chart_type = example_spc_data$funnel_chart_type,
parent_indicator = "All", # Allocates indicators into one parent group named All
indicator_name = example_spc_data$indicator,
group_name = example_spc_data$group,
funnel_data_points = "Yes", # Includes all data points in the funnel plot
trend_size = 5,
shift_size = 7
)
#> Funnel Patterns Completed
#> SPC Data Validated
#> Start SPC Pattern Detection
#> SPC Patterns Completed
head(pattern_detection_data, 20)
#> indicator_name group_name parent_indicator better_is numerator
#> <char> <char> <char> <char> <int>
#> 1: Caesarean Section A All Lower 178
#> 2: Caesarean Section Aggregate All Lower 3226
#> 3: Caesarean Section B All Lower 646
#> 4: Caesarean Section C All Lower 773
#> 5: Caesarean Section D All Lower 305
#> 6: Caesarean Section E All Lower 66
#> 7: Caesarean Section F All Lower 848
#> 8: Caesarean Section G All Lower 44
#> 9: Caesarean Section H All Lower 36
#> 10: Caesarean Section I All Lower 239
#> 11: Caesarean Section J All Lower 58
#> 12: Caesarean Section L All Lower 33
#> 13: Crude Mortality A All Lower 3234
#> 14: Crude Mortality Aggregate All Lower 75085
#> 15: Crude Mortality B All Lower 18305
#> 16: Crude Mortality C All Lower 16649
#> 17: Crude Mortality D All Lower 5844
#> 18: Crude Mortality E All Lower 1098
#> 19: Crude Mortality F All Lower 17828
#> 20: Crude Mortality G All Lower 294
#> indicator_name group_name parent_indicator better_is numerator
#> <char> <char> <char> <char> <int>
#> denominator astro shift trend twointhree fpl_astro
#> <num> <Date> <Date> <Date> <Date> <Date>
#> 1: 622 <NA> <NA> <NA> <NA> <NA>
#> 2: 9802 <NA> <NA> <NA> <NA> <NA>
#> 3: 2108 <NA> <NA> <NA> <NA> <NA>
#> 4: 2459 <NA> 2022-03-31 <NA> <NA> <NA>
#> 5: 906 <NA> <NA> <NA> <NA> <NA>
#> 6: 237 <NA> <NA> <NA> <NA> <NA>
#> 7: 2214 <NA> <NA> 2022-04-30 <NA> 2022-12-31
#> 8: 116 <NA> <NA> <NA> <NA> <NA>
#> 9: 103 <NA> <NA> <NA> <NA> <NA>
#> 10: 788 <NA> <NA> <NA> <NA> <NA>
#> 11: 161 <NA> <NA> <NA> <NA> <NA>
#> 12: 88 <NA> <NA> <NA> <NA> <NA>
#> 13: 128801 <NA> <NA> <NA> <NA> <NA>
#> 14: 1974093 <NA> <NA> <NA> <NA> <NA>
#> 15: 424038 <NA> <NA> <NA> <NA> 2022-12-31
#> 16: 478545 <NA> <NA> <NA> <NA> <NA>
#> 17: 184608 <NA> <NA> 2022-05-31 <NA> <NA>
#> 18: 50091 <NA> <NA> <NA> <NA> <NA>
#> 19: 447835 <NA> <NA> <NA> <NA> 2022-12-31
#> 20: 24002 <NA> <NA> <NA> <NA> <NA>
#> denominator astro shift trend twointhree fpl_astro
#> <num> <Date> <Date> <Date> <Date> <Date>The above code will also work if you are not interested in generating funnel data points, and only have data for one group.
pattern_detection_data_groupA <- pattern_detection(
indicator = example_spc_data[group == "A"]$indicator,
group = example_spc_data[group == "A"]$group,
period_end = example_spc_data[group == "A"]$period_end,
numerator = example_spc_data[group == "A"]$numerator,
denominator = example_spc_data[group == "A"]$denominator,
multiplier = example_spc_data[group == "A"]$multiplier,
better_is = example_spc_data[group == "A"]$better_is,
spc_chart_type = example_spc_data[group == "A"]$spc_chart_type,
funnel_chart_type = example_spc_data[group == "A"]$funnel_chart_type,
parent_indicator = "All", # Allocates indicators into one parent group named All
indicator_name = example_spc_data[group == "A"]$indicator,
group_name = example_spc_data[group == "A"]$group,
funnel_data_points = "Yes", # Includes all data points in the funnel plot
trend_size = 5,
shift_size = 7
)
#> No overdispersion detected, or draw_adjusted set to FALSE
#> , plotting using unadjusted limits
#> No overdispersion detected, or draw_adjusted set to FALSE
#> , plotting using unadjusted limits
#> No overdispersion detected, or draw_adjusted set to FALSE
#> , plotting using unadjusted limits
#> No overdispersion detected, or draw_adjusted set to FALSE
#> , plotting using unadjusted limits
#> No overdispersion detected, or draw_adjusted set to FALSE
#> , plotting using unadjusted limits
#> Funnel Patterns Completed
#> SPC Data Validated
#> Start SPC Pattern Detection
#> SPC Patterns Completed
head(pattern_detection_data_groupA, 20)
#> indicator_name group_name parent_indicator better_is numerator
#> <char> <char> <char> <char> <int>
#> 1: Caesarean Section A All Lower 178
#> 2: Crude Mortality A All Lower 3234
#> 3: Falls A All Lower 24
#> 4: Pressure Injury A All Lower 22
#> 5: Staff Feel Safe To Speak Up A All Higher 378
#> 6: Standardised Mortality Ratio A All Lower 100
#> denominator astro shift trend twointhree fpl_astro
#> <num> <Date> <Date> <Date> <Date> <Date>
#> 1: 622.0000 <NA> <NA> <NA> <NA> <NA>
#> 2: 128801.0000 <NA> <NA> <NA> <NA> <NA>
#> 3: 127800.0000 2021-07-31 <NA> <NA> <NA> <NA>
#> 4: 129072.0000 <NA> <NA> <NA> 2021-05-31 <NA>
#> 5: 662.0000 <NA> <NA> <NA> <NA> <NA>
#> 6: 122.5909 <NA> <NA> <NA> <NA> <NA>As displayed above, the output is one record for each indicator and group combination. The columns show:
The sum of the numerator
The sum of the denominator
The most recent astronomical point period end date
The most recent shift period end date
The most recent trend period end date
The most recent two-in-three period end date
The most recent funnel plot outlier period end date
The pattern_rules function extracts all patterns
relating to Statistical Process Control patterns for Astronomical
Points, Trends, Shifts and Two-in-three.
The pattern_rules function uses data.table to
parallelise the SPC limit calculations and pattern detections. This
requires a unique.key to be created to identify which records are
related to each other, and should be considered in the same SPC
calculations. An example is as follows:
pattern_rules_data <- qiverse.qipatterns::pattern_rules(
numerator = example_spc_data$numerator,
denominator = example_spc_data$denominator,
period_end = as.character(example_spc_data$period_end),
unique_key = example_spc_data[, paste0(indicator, "_", group)],
spc_chart_type = example_spc_data$spc_chart_type,
multiplier = example_spc_data$multiplier,
better_is = example_spc_data$better_is,
trend_size = 5,
shift_size = 7
)
head(pattern_rules_data, 72)
#> unique_key period_end numerator denominator
#> <char> <char> <int> <num>
#> 1: Standardised Mortality Ratio_A 2021-01-31 6 4.379261
#> 2: Standardised Mortality Ratio_A 2021-02-28 4 3.778151
#> 3: Standardised Mortality Ratio_A 2021-03-31 4 4.398701
#> 4: Standardised Mortality Ratio_A 2021-04-30 4 4.913439
#> 5: Standardised Mortality Ratio_A 2021-05-31 8 4.950847
#> 6: Standardised Mortality Ratio_A 2021-06-30 4 3.115129
#> 7: Standardised Mortality Ratio_A 2021-07-31 5 5.413828
#> 8: Standardised Mortality Ratio_A 2021-08-31 6 6.804866
#> 9: Standardised Mortality Ratio_A 2021-09-30 5 5.082595
#> 10: Standardised Mortality Ratio_A 2021-10-31 2 6.932753
#> 11: Standardised Mortality Ratio_A 2021-11-30 5 4.464551
#> 12: Standardised Mortality Ratio_A 2021-12-31 6 5.617537
#> 13: Standardised Mortality Ratio_A 2022-01-31 1 5.430184
#> 14: Standardised Mortality Ratio_A 2022-02-28 3 7.850169
#> 15: Standardised Mortality Ratio_A 2022-03-31 2 3.700881
#> 16: Standardised Mortality Ratio_A 2022-04-30 2 6.109831
#> 17: Standardised Mortality Ratio_A 2022-05-31 6 5.626688
#> 18: Standardised Mortality Ratio_A 2022-06-30 3 2.928832
#> 19: Standardised Mortality Ratio_A 2022-07-31 2 7.133609
#> 20: Standardised Mortality Ratio_A 2022-08-31 4 5.316866
#> 21: Standardised Mortality Ratio_A 2022-09-30 3 4.870002
#> 22: Standardised Mortality Ratio_A 2022-10-31 5 4.042340
#> 23: Standardised Mortality Ratio_A 2022-11-30 5 5.225269
#> 24: Standardised Mortality Ratio_A 2022-12-31 5 4.504521
#> 25: Standardised Mortality Ratio_B 2021-01-31 27 19.825173
#> 26: Standardised Mortality Ratio_B 2021-02-28 34 16.935151
#> 27: Standardised Mortality Ratio_B 2021-03-31 31 18.465319
#> 28: Standardised Mortality Ratio_B 2021-04-30 26 16.381745
#> 29: Standardised Mortality Ratio_B 2021-05-31 31 18.023426
#> 30: Standardised Mortality Ratio_B 2021-06-30 26 17.246990
#> 31: Standardised Mortality Ratio_B 2021-07-31 17 19.183385
#> 32: Standardised Mortality Ratio_B 2021-08-31 18 15.480281
#> 33: Standardised Mortality Ratio_B 2021-09-30 20 16.709238
#> 34: Standardised Mortality Ratio_B 2021-10-31 19 16.461623
#> 35: Standardised Mortality Ratio_B 2021-11-30 26 17.638278
#> 36: Standardised Mortality Ratio_B 2021-12-31 32 15.337096
#> 37: Standardised Mortality Ratio_B 2022-01-31 27 18.677970
#> 38: Standardised Mortality Ratio_B 2022-02-28 31 18.384813
#> 39: Standardised Mortality Ratio_B 2022-03-31 18 17.007116
#> 40: Standardised Mortality Ratio_B 2022-04-30 24 19.133213
#> 41: Standardised Mortality Ratio_B 2022-05-31 24 18.469504
#> 42: Standardised Mortality Ratio_B 2022-06-30 20 17.027364
#> 43: Standardised Mortality Ratio_B 2022-07-31 23 17.305899
#> 44: Standardised Mortality Ratio_B 2022-08-31 21 17.346641
#> 45: Standardised Mortality Ratio_B 2022-09-30 21 19.137677
#> 46: Standardised Mortality Ratio_B 2022-10-31 29 16.141388
#> 47: Standardised Mortality Ratio_B 2022-11-30 30 18.983033
#> 48: Standardised Mortality Ratio_B 2022-12-31 24 19.638377
#> 49: Standardised Mortality Ratio_C 2021-01-31 14 20.403348
#> 50: Standardised Mortality Ratio_C 2021-02-28 21 19.473598
#> 51: Standardised Mortality Ratio_C 2021-03-31 11 20.301085
#> 52: Standardised Mortality Ratio_C 2021-04-30 25 19.292963
#> 53: Standardised Mortality Ratio_C 2021-05-31 11 20.029217
#> 54: Standardised Mortality Ratio_C 2021-06-30 16 22.540925
#> 55: Standardised Mortality Ratio_C 2021-07-31 14 19.199281
#> 56: Standardised Mortality Ratio_C 2021-08-31 22 19.119888
#> 57: Standardised Mortality Ratio_C 2021-09-30 13 19.651803
#> 58: Standardised Mortality Ratio_C 2021-10-31 28 22.153208
#> 59: Standardised Mortality Ratio_C 2021-11-30 24 19.471874
#> 60: Standardised Mortality Ratio_C 2021-12-31 18 18.904965
#> 61: Standardised Mortality Ratio_C 2022-01-31 19 20.840416
#> 62: Standardised Mortality Ratio_C 2022-02-28 26 19.707241
#> 63: Standardised Mortality Ratio_C 2022-03-31 8 18.387359
#> 64: Standardised Mortality Ratio_C 2022-04-30 19 21.026034
#> 65: Standardised Mortality Ratio_C 2022-05-31 14 18.422189
#> 66: Standardised Mortality Ratio_C 2022-06-30 11 19.877997
#> 67: Standardised Mortality Ratio_C 2022-07-31 22 20.936131
#> 68: Standardised Mortality Ratio_C 2022-08-31 23 20.856755
#> 69: Standardised Mortality Ratio_C 2022-09-30 14 19.711456
#> 70: Standardised Mortality Ratio_C 2022-10-31 18 19.558676
#> 71: Standardised Mortality Ratio_C 2022-11-30 15 20.154740
#> 72: Standardised Mortality Ratio_C 2022-12-31 14 19.946863
#> unique_key period_end numerator denominator
#> <char> <char> <int> <num>
#> spc_chart_type multiplier better_is spc_y spc_cl spc_ul99 spc_ul95
#> <char> <num> <char> <num> <num> <num> <num>
#> 1: i 100 Lower 1.3700940 0.8664562 1.839290 1.515012
#> 2: i 100 Lower 1.0587189 0.8664562 1.839290 1.515012
#> 3: i 100 Lower 0.9093595 0.8664562 1.839290 1.515012
#> 4: i 100 Lower 0.8140937 0.8664562 1.839290 1.515012
#> 5: i 100 Lower 1.6158852 0.8664562 1.839290 1.515012
#> 6: i 100 Lower 1.2840560 0.8664562 1.839290 1.515012
#> 7: i 100 Lower 0.9235610 0.8664562 1.839290 1.515012
#> 8: i 100 Lower 0.8817220 0.8664562 1.839290 1.515012
#> 9: i 100 Lower 0.9837494 0.8664562 1.839290 1.515012
#> 10: i 100 Lower 0.2884857 0.8664562 1.839290 1.515012
#> 11: i 100 Lower 1.1199334 0.8664562 1.839290 1.515012
#> 12: i 100 Lower 1.0680837 0.8664562 1.839290 1.515012
#> 13: i 100 Lower 0.1841558 0.8664562 1.839290 1.515012
#> 14: i 100 Lower 0.3821574 0.8664562 1.839290 1.515012
#> 15: i 100 Lower 0.5404118 0.8664562 1.839290 1.515012
#> 16: i 100 Lower 0.3273413 0.8664562 1.839290 1.515012
#> 17: i 100 Lower 1.0663467 0.8664562 1.839290 1.515012
#> 18: i 100 Lower 1.0242990 0.8664562 1.839290 1.515012
#> 19: i 100 Lower 0.2803630 0.8664562 1.839290 1.515012
#> 20: i 100 Lower 0.7523229 0.8664562 1.839290 1.515012
#> 21: i 100 Lower 0.6160162 0.8664562 1.839290 1.515012
#> 22: i 100 Lower 1.2369074 0.8664562 1.839290 1.515012
#> 23: i 100 Lower 0.9568886 0.8664562 1.839290 1.515012
#> 24: i 100 Lower 1.1099959 0.8664562 1.839290 1.515012
#> 25: i 100 Lower 1.3619049 1.4157557 2.208298 1.944117
#> 26: i 100 Lower 2.0076585 1.4157557 2.208298 1.944117
#> 27: i 100 Lower 1.6788228 1.4157557 2.208298 1.944117
#> 28: i 100 Lower 1.5871325 1.4157557 2.208298 1.944117
#> 29: i 100 Lower 1.7199838 1.4157557 2.208298 1.944117
#> 30: i 100 Lower 1.5075094 1.4157557 2.208298 1.944117
#> 31: i 100 Lower 0.8861835 1.4157557 2.208298 1.944117
#> 32: i 100 Lower 1.1627696 1.4157557 2.208298 1.944117
#> 33: i 100 Lower 1.1969427 1.4157557 2.208298 1.944117
#> 34: i 100 Lower 1.1541997 1.4157557 2.208298 1.944117
#> 35: i 100 Lower 1.4740668 1.4157557 2.208298 1.944117
#> 36: i 100 Lower 2.0864446 1.4157557 2.208298 1.944117
#> 37: i 100 Lower 1.4455532 1.4157557 2.208298 1.944117
#> 38: i 100 Lower 1.6861744 1.4157557 2.208298 1.944117
#> 39: i 100 Lower 1.0583805 1.4157557 2.208298 1.944117
#> 40: i 100 Lower 1.2543633 1.4157557 2.208298 1.944117
#> 41: i 100 Lower 1.2994393 1.4157557 2.208298 1.944117
#> 42: i 100 Lower 1.1745799 1.4157557 2.208298 1.944117
#> 43: i 100 Lower 1.3290266 1.4157557 2.208298 1.944117
#> 44: i 100 Lower 1.2106090 1.4157557 2.208298 1.944117
#> 45: i 100 Lower 1.0973119 1.4157557 2.208298 1.944117
#> 46: i 100 Lower 1.7966237 1.4157557 2.208298 1.944117
#> 47: i 100 Lower 1.5803586 1.4157557 2.208298 1.944117
#> 48: i 100 Lower 1.2220969 1.4157557 2.208298 1.944117
#> 49: i 100 Lower 0.6861619 0.8735189 1.793456 1.486810
#> 50: i 100 Lower 1.0783832 0.8735189 1.793456 1.486810
#> 51: i 100 Lower 0.5418430 0.8735189 1.793456 1.486810
#> 52: i 100 Lower 1.2958092 0.8735189 1.793456 1.486810
#> 53: i 100 Lower 0.5491977 0.8735189 1.793456 1.486810
#> 54: i 100 Lower 0.7098200 0.8735189 1.793456 1.486810
#> 55: i 100 Lower 0.7291940 0.8735189 1.793456 1.486810
#> 56: i 100 Lower 1.1506344 0.8735189 1.793456 1.486810
#> 57: i 100 Lower 0.6615169 0.8735189 1.793456 1.486810
#> 58: i 100 Lower 1.2639253 0.8735189 1.793456 1.486810
#> 59: i 100 Lower 1.2325470 0.8735189 1.793456 1.486810
#> 60: i 100 Lower 0.9521308 0.8735189 1.793456 1.486810
#> 61: i 100 Lower 0.9116901 0.8735189 1.793456 1.486810
#> 62: i 100 Lower 1.3193120 0.8735189 1.793456 1.486810
#> 63: i 100 Lower 0.4350815 0.8735189 1.793456 1.486810
#> 64: i 100 Lower 0.9036416 0.8735189 1.793456 1.486810
#> 65: i 100 Lower 0.7599531 0.8735189 1.793456 1.486810
#> 66: i 100 Lower 0.5533757 0.8735189 1.793456 1.486810
#> 67: i 100 Lower 1.0508150 0.8735189 1.793456 1.486810
#> 68: i 100 Lower 1.1027602 0.8735189 1.793456 1.486810
#> 69: i 100 Lower 0.7102469 0.8735189 1.793456 1.486810
#> 70: i 100 Lower 0.9203077 0.8735189 1.793456 1.486810
#> 71: i 100 Lower 0.7442418 0.8735189 1.793456 1.486810
#> 72: i 100 Lower 0.7018648 0.8735189 1.793456 1.486810
#> spc_chart_type multiplier better_is spc_y spc_cl spc_ul99 spc_ul95
#> <char> <num> <char> <num> <num> <num> <num>
#> spc_ll95 spc_ll99 spc_astro spc_trend spc_twointhree spc_shift
#> <num> <num> <char> <char> <char> <char>
#> 1: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 2: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 3: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 4: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 5: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 6: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 7: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 8: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 9: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 10: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 11: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 12: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 13: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 14: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 15: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 16: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 17: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 18: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 19: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 20: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 21: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 22: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 23: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 24: 0.2179000 -0.10637812 <NA> <NA> <NA> <NA>
#> 25: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 26: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 27: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 28: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 29: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 30: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 31: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 32: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 33: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 34: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 35: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 36: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 37: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 38: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 39: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 40: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 41: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 42: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 43: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 44: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 45: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 46: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 47: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 48: 0.8873944 0.62321371 <NA> <NA> <NA> <NA>
#> 49: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 50: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 51: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 52: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 53: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 54: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 55: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 56: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 57: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 58: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 59: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 60: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 61: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 62: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 63: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 64: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 65: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 66: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 67: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 68: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 69: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 70: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 71: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> 72: 0.2602274 -0.04641834 <NA> <NA> <NA> <NA>
#> spc_ll95 spc_ll99 spc_astro spc_trend spc_twointhree spc_shift
#> <num> <num> <char> <char> <char> <char>Similarly, we can generate SPC patterns and limit calculations for a single indicator and group combination.
example_spc_data_SMR_A <- example_spc_data[indicator == "Standardised Mortality Ratio" & group == "A"]
pattern_rules_data_SMR_A <- qiverse.qipatterns::pattern_rules(
numerator = example_spc_data_SMR_A$numerator,
denominator = example_spc_data_SMR_A$denominator,
period_end = as.character(example_spc_data_SMR_A$period_end),
unique_key = NA,
spc_chart_type = "i",
multiplier = 100,
better_is = "Lower",
trend_size = 5,
shift_size = 7
)
head(pattern_rules_data_SMR_A, 36)
#> unique_key period_end numerator denominator spc_chart_type multiplier
#> <lgcl> <char> <int> <num> <char> <num>
#> 1: NA 2021-01-31 6 4.379261 i 100
#> 2: NA 2021-02-28 4 3.778151 i 100
#> 3: NA 2021-03-31 4 4.398701 i 100
#> 4: NA 2021-04-30 4 4.913439 i 100
#> 5: NA 2021-05-31 8 4.950847 i 100
#> 6: NA 2021-06-30 4 3.115129 i 100
#> 7: NA 2021-07-31 5 5.413828 i 100
#> 8: NA 2021-08-31 6 6.804866 i 100
#> 9: NA 2021-09-30 5 5.082595 i 100
#> 10: NA 2021-10-31 2 6.932753 i 100
#> 11: NA 2021-11-30 5 4.464551 i 100
#> 12: NA 2021-12-31 6 5.617537 i 100
#> 13: NA 2022-01-31 1 5.430184 i 100
#> 14: NA 2022-02-28 3 7.850169 i 100
#> 15: NA 2022-03-31 2 3.700881 i 100
#> 16: NA 2022-04-30 2 6.109831 i 100
#> 17: NA 2022-05-31 6 5.626688 i 100
#> 18: NA 2022-06-30 3 2.928832 i 100
#> 19: NA 2022-07-31 2 7.133609 i 100
#> 20: NA 2022-08-31 4 5.316866 i 100
#> 21: NA 2022-09-30 3 4.870002 i 100
#> 22: NA 2022-10-31 5 4.042340 i 100
#> 23: NA 2022-11-30 5 5.225269 i 100
#> 24: NA 2022-12-31 5 4.504521 i 100
#> unique_key period_end numerator denominator spc_chart_type multiplier
#> <lgcl> <char> <int> <num> <char> <num>
#> better_is spc_y spc_cl spc_ul99 spc_ul95 spc_ll95 spc_ll99
#> <char> <num> <num> <num> <num> <num> <num>
#> 1: Lower 1.3700940 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 2: Lower 1.0587189 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 3: Lower 0.9093595 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 4: Lower 0.8140937 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 5: Lower 1.6158852 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 6: Lower 1.2840560 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 7: Lower 0.9235610 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 8: Lower 0.8817220 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 9: Lower 0.9837494 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 10: Lower 0.2884857 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 11: Lower 1.1199334 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 12: Lower 1.0680837 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 13: Lower 0.1841558 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 14: Lower 0.3821574 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 15: Lower 0.5404118 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 16: Lower 0.3273413 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 17: Lower 1.0663467 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 18: Lower 1.0242990 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 19: Lower 0.2803630 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 20: Lower 0.7523229 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 21: Lower 0.6160162 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 22: Lower 1.2369074 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 23: Lower 0.9568886 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> 24: Lower 1.1099959 0.8664562 1.83929 1.515012 0.2179 -0.1063781
#> better_is spc_y spc_cl spc_ul99 spc_ul95 spc_ll95 spc_ll99
#> <char> <num> <num> <num> <num> <num> <num>
#> spc_astro spc_trend spc_twointhree spc_shift
#> <char> <char> <char> <char>
#> 1: <NA> <NA> <NA> <NA>
#> 2: <NA> <NA> <NA> <NA>
#> 3: <NA> <NA> <NA> <NA>
#> 4: <NA> <NA> <NA> <NA>
#> 5: <NA> <NA> <NA> <NA>
#> 6: <NA> <NA> <NA> <NA>
#> 7: <NA> <NA> <NA> <NA>
#> 8: <NA> <NA> <NA> <NA>
#> 9: <NA> <NA> <NA> <NA>
#> 10: <NA> <NA> <NA> <NA>
#> 11: <NA> <NA> <NA> <NA>
#> 12: <NA> <NA> <NA> <NA>
#> 13: <NA> <NA> <NA> <NA>
#> 14: <NA> <NA> <NA> <NA>
#> 15: <NA> <NA> <NA> <NA>
#> 16: <NA> <NA> <NA> <NA>
#> 17: <NA> <NA> <NA> <NA>
#> 18: <NA> <NA> <NA> <NA>
#> 19: <NA> <NA> <NA> <NA>
#> 20: <NA> <NA> <NA> <NA>
#> 21: <NA> <NA> <NA> <NA>
#> 22: <NA> <NA> <NA> <NA>
#> 23: <NA> <NA> <NA> <NA>
#> 24: <NA> <NA> <NA> <NA>
#> spc_astro spc_trend spc_twointhree spc_shift
#> <char> <char> <char> <char>