cpt.Rmd
library("cpt")
library("trackframe")cpt package currently supports xyt matrices (a matrix or data frame with columns for x-coordinates, y-coordinates, and timestamps) and trackframes (see pkg trackframe) as input formats.
Detect change points
## [1] "trackframe" "data.frame"
set.seed(2025L)
cpt <- change_point_test_xyt(
easting = path_trackframe[, "easting"],
northing = path_trackframe[, "northing"],
time = path_matrix[, "time"],
alpha = 0.05,
q = 3,
N = 500
)
class(cpt)## [1] "change_point_test" "data.frame"
Extract the change points into a summarized format
summary(cpt)## first last east north
## 1 1760487752 1760487752 -0.0072061100 0.003763871
## 2 1760535812 1760535812 -0.0027773379 0.011703586
## 3 1760551592 1760551652 0.0002694329 0.009003683
## 4 1760554172 1760554172 0.0013820211 0.017076390
## 5 1760563952 1760563952 -0.0049726251 0.016002070
## 6 1760571812 1760571812 0.0005152087 0.015387244
## 7 1760584772 1760584772 -0.0059711263 0.017819524
## 8 1760588972 1760588972 -0.0038805680 0.014830813
## 9 1760597192 1760598752 -0.0032596397 0.019189124
## 10 1760598992 1760598992 -0.0048342032 0.021118660
## 11 1760634152 1760636012 -0.0029274680 0.012569104
## 12 1760651552 1760651552 -0.0050339505 0.004651530
## 13 1760653652 1760653772 -0.0031042727 0.008906007
## 14 1760676212 1760676212 -0.0053506489 0.005985680
Get probability values instead of binary indicators
data("cpttestdata_tiny")
pvalues <- change_point_test_pvalue(cpttestdata_tiny, q_max = 5, N = 500)## Warning in as.trackframe.data.frame(structure(list(x = c(587986.6398,
## 588001.6398, : No id column found. Adding placeholder "track_id" column
tail(pvalues)## $`<id>`
## q=1 q=2 q=3 q=4 q=5
## [1,] 1.0000 1.0000 0.7450 0.4034 0.3256
## [2,] 0.6730 0.6701 0.1997 0.2039 0.1440
## [3,] 1.0000 0.8011 0.8090 0.6953 0.8096
## [4,] 0.8049 0.8727 0.8592 0.8283 0.8359
## [5,] 1.0000 0.7134 0.6416 0.4426 0.4888
## [6,] 1.0000 0.9633 0.5807 0.5878 0.6027
## [7,] 0.7428 0.0555 0.1268 0.0882 0.0683
## [8,] 0.1075 0.1062 0.1195 0.0753 0.0256
## [9,] 0.6962 0.0621 0.0276 0.0076 0.0044
## [10,] 0.0929 0.0600 0.0129 0.0065 0.0056
## [11,] 0.8344 0.1780 0.1689 0.1580 0.1807
## [12,] 0.1516 0.1341 0.1481 0.1688 0.1599
## [13,] 0.5730 0.5420 0.6170 0.5937 0.6610
## [14,] 0.8009 0.7926 0.8189 0.9062 0.7609
## [15,] 0.9389 0.9354 0.8867 0.9053 0.8967
## [16,] 0.7071 0.7323 0.8526 0.6579 0.9073
## [17,] 0.9493 0.8473 0.8566 0.9325 0.9162
## [18,] 0.7351 0.7860 0.8509 0.9352 NA
## [19,] 0.6446 0.8905 0.7309 NA NA
## [20,] 0.9550 0.8926 NA NA NA
## [21,] NA NA NA NA NA
## [22,] 0.6296 NA NA NA NA
## [23,] NA NA NA NA NA
## [24,] NA NA NA NA NA
## attr(,"class")
## [1] "change_point_test_pvalue" "matrix"
## [3] "array"