
Pettitt-style change-point on yearly incident counts
Source:R/tps_temporal.R
morie_tps_changepoint_detection.RdImplements Pettitt's non-parametric change-point statistic U_t = sum_i sum_j sign(x_i - x_j) for i <= t < j, then reports the year maximising |U_t| and an approximate p-value. No external change-point dependency is required.
Examples
set.seed(1)
df <- data.frame(OCC_YEAR = rep(2014:2023, each = 30),
OCC_MONTH = sample(month.name, 300, TRUE),
HOOD_158 = sample(sprintf("%03d", 1:20), 300, TRUE),
LAT_WGS84 = runif(300, 43.6, 43.8),
LONG_WGS84 = runif(300, -79.5, -79.2))
res <- try(morie_tps_changepoint_detection(df, ds_name = "synthetic"))
if (!inherits(res, "try-error")) str(res, max.level = 1)
#> List of 13
#> $ title : chr "Change-point (Pettitt) -- synthetic"
#> $ call : chr "morie_tps_changepoint_detection(df=<300r>, year_col=OCC_YEAR)"
#> $ summary_lines :List of 8
#> $ warnings : chr(0)
#> $ interpretation : chr "Estimated structural break in 2014: pre-mean 30.0, post-mean 30.0. p=1.0000 -- not significant at alpha=0.05."
#> $ n : int 10
#> $ years : int [1:10] 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
#> $ counts : int [1:10] 30 30 30 30 30 30 30 30 30 30
#> $ changepoint_year: int 2014
#> $ K_statistic : num 0
#> $ p_value : num 1
#> $ pre_mean : num 30
#> $ post_mean : num 30
#> - attr(*, "class")= chr [1:3] "morie_tps_temporal_result" "morie_rich_result" "list"