Use spline lookup to restrict `ObservedExpectedGrid` to potential clusters
Source:R/cluster_functions.R
add_spline_threshold.RdFunction takes a spline lookup table (or uses package default), and an object of class `ObservedExpectedGrid` and identifies which rows in each potential centroid have observed over expected values that exceed a threshold for that observed value
Arguments
- oe_grid
An object of class `ObservedExpectedGrid` generated by
generate_observed_expected()- spline_lookup
default NULL; either a spline lookup table, which is a data frame that has at least two columns: including "observed" and "spl_thresh", OR a string indicating to use one of the built in lookup tables: i.e. one of
"001", "005", "01", "05". If NULL, the default table will be 01 (i.e.spline_01dataset)
Value
an object of class `ClusterAlertTable` which is simply a data frame containing rows of the input `oe_grid“ that represent the reduced set of candidate alert clusters
Examples
case_grid <- generate_case_grids(
example_count_data, example_count_data[, max(date)]
)
nci <- gen_nearby_case_info(
cg = case_grid,
distance_matrix = county_distance_matrix("OH")[["distance_matrix"]],
distance_limit = 25
)
obs_exp_grid <- generate_observed_expected(
nearby_counts = nci,
case_grid = case_grid
)
add_spline_threshold(oe_grid = obs_exp_grid)
#> target observed spl_thresh date test_totals location base_clust_sums
#> <char> <int> <num> <Date> <int> <char> <num>
#> 1: 39003 335 0.2113664 2025-01-30 9673 39003 1263
#> 2: 39003 268 0.2393718 2025-01-31 8267 39003 1263
#> 3: 39003 187 0.3049584 2025-02-01 6898 39003 1263
#> 4: 39003 390 0.1954300 2025-01-30 9673 39011 1673
#> 5: 39003 314 0.2185447 2025-01-31 8267 39011 1673
#> ---
#> 114: 39163 199 0.2921754 2025-02-01 6898 39009 1206
#> 115: 39163 155 0.3454959 2025-02-02 5553 39009 1206
#> 116: 39165 349 0.2070769 2025-02-01 6898 39017 2511
#> 117: 39165 277 0.2345938 2025-02-02 5553 39017 2511
#> 118: 39165 242 0.2556057 2025-02-05 1447 39113 8118
#> distance_value count count_sum detect_date baseline_total expected
#> <num> <int> <int> <Date> <num> <num>
#> 1: 0.00000 67 335 2025-02-05 63803 191.4800
#> 2: 0.00000 81 268 2025-02-05 63803 163.6478
#> 3: 0.00000 49 187 2025-02-05 63803 136.5480
#> 4: 15.79103 9 55 2025-02-05 63803 253.6390
#> 5: 15.79103 8 46 2025-02-05 63803 216.7718
#> ---
#> 114: 24.18397 29 101 2025-02-05 63803 130.3855
#> 115: 24.18397 20 72 2025-02-05 63803 104.9624
#> 116: 21.14424 40 201 2025-02-05 63803 271.4744
#> 117: 21.14424 44 161 2025-02-05 63803 218.5412
#> 118: 23.56043 153 153 2025-02-05 63803 184.1096
#> log_obs_exp min_dist alert_ratio alert_gap
#> <num> <num> <num> <num>
#> 1: 0.5593471 0.00000 2.646338 0.347980688
#> 2: 0.4932704 0.00000 2.060687 0.253898550
#> 3: 0.3144322 0.00000 1.031066 0.009473807
#> 4: 0.4302348 15.79103 2.201478 0.234804791
#> 5: 0.3705478 15.79103 1.695524 0.152003149
#> ---
#> 114: 0.4228091 24.18397 1.447107 0.130633740
#> 115: 0.3898226 24.18397 1.128299 0.044326709
#> 116: 0.2512043 21.14424 1.213097 0.044127384
#> 117: 0.2370430 21.14424 1.010440 0.002449274
#> 118: 0.2734064 23.56043 1.069641 0.017800667
add_spline_threshold(oe_grid = obs_exp_grid, spline_lookup = "01")
#> target observed spl_thresh date test_totals location base_clust_sums
#> <char> <int> <num> <Date> <int> <char> <num>
#> 1: 39003 335 0.2113664 2025-01-30 9673 39003 1263
#> 2: 39003 268 0.2393718 2025-01-31 8267 39003 1263
#> 3: 39003 187 0.3049584 2025-02-01 6898 39003 1263
#> 4: 39003 390 0.1954300 2025-01-30 9673 39011 1673
#> 5: 39003 314 0.2185447 2025-01-31 8267 39011 1673
#> ---
#> 114: 39163 199 0.2921754 2025-02-01 6898 39009 1206
#> 115: 39163 155 0.3454959 2025-02-02 5553 39009 1206
#> 116: 39165 349 0.2070769 2025-02-01 6898 39017 2511
#> 117: 39165 277 0.2345938 2025-02-02 5553 39017 2511
#> 118: 39165 242 0.2556057 2025-02-05 1447 39113 8118
#> distance_value count count_sum detect_date baseline_total expected
#> <num> <int> <int> <Date> <num> <num>
#> 1: 0.00000 67 335 2025-02-05 63803 191.4800
#> 2: 0.00000 81 268 2025-02-05 63803 163.6478
#> 3: 0.00000 49 187 2025-02-05 63803 136.5480
#> 4: 15.79103 9 55 2025-02-05 63803 253.6390
#> 5: 15.79103 8 46 2025-02-05 63803 216.7718
#> ---
#> 114: 24.18397 29 101 2025-02-05 63803 130.3855
#> 115: 24.18397 20 72 2025-02-05 63803 104.9624
#> 116: 21.14424 40 201 2025-02-05 63803 271.4744
#> 117: 21.14424 44 161 2025-02-05 63803 218.5412
#> 118: 23.56043 153 153 2025-02-05 63803 184.1096
#> log_obs_exp min_dist alert_ratio alert_gap
#> <num> <num> <num> <num>
#> 1: 0.5593471 0.00000 2.646338 0.347980688
#> 2: 0.4932704 0.00000 2.060687 0.253898550
#> 3: 0.3144322 0.00000 1.031066 0.009473807
#> 4: 0.4302348 15.79103 2.201478 0.234804791
#> 5: 0.3705478 15.79103 1.695524 0.152003149
#> ---
#> 114: 0.4228091 24.18397 1.447107 0.130633740
#> 115: 0.3898226 24.18397 1.128299 0.044326709
#> 116: 0.2512043 21.14424 1.213097 0.044127384
#> 117: 0.2370430 21.14424 1.010440 0.002449274
#> 118: 0.2734064 23.56043 1.069641 0.017800667