Acceptable Inputs

Run cpt with a trackframe

check as.trackframe method for data.frame

?as.trackframe.data.frame

Transform data to a trackframe. Trackframe always use x/y coordinates as cartesian coordinates with easting and northing.

library(trackframe)
projected_crs <- "EPSG:32632"
tf <- as.trackframe(path_matrix, crs = projected_crs)
class(tf)
## [1] "trackframe" "data.frame"
library(cpt)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following object is masked from 'package:trackframe':
## 
##     time<-
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
set.seed(2025L)
cpt_tf <- change_point_test(tf, alpha = 0.05, q = 3, n = 500, min_move_dist = 0)
class(cpt_tf)
## [1] "change_point_test" "trackframe"        "data.frame"

Extract the change points into a summarized format

summary(cpt_tf)
##           first       last          east        north id
## 1.1  1760453852 1760453852 -0.0017172534  0.001813623  1
## 1.2  1760456912 1760457872 -0.0021601344 -0.003594477  1
## 1.3  1760472752 1760472752 -0.0011262684  0.002398976  1
## 1.4  1760487512 1760487512 -0.0068445404  0.002532938  1
## 1.5  1760535572 1760535572 -0.0024157683  0.010472653  1
## 1.6  1760550992 1760551412  0.0006310025  0.007772750  1
## 1.7  1760553932 1760553932  0.0017435907  0.015845457  1
## 1.8  1760561672 1760561672 -0.0046110555  0.014771137  1
## 1.9  1760571572 1760571572  0.0008767783  0.014156311  1
## 1.10 1760582132 1760582132 -0.0056095567  0.016588591  1
## 1.11 1760587532 1760587532 -0.0035189983  0.013599880  1
## 1.12 1760598752 1760598752 -0.0044726336  0.019887727  1
## 1.13 1760629292 1760629292 -0.0003405273  0.010288650  1
## 1.14 1760631212 1760631212 -0.0037328382  0.009815103  1
## 1.15 1760639312 1760639312  0.0006253397  0.008032317  1
## 1.16 1760651132 1760651432 -0.0044576082  0.003770870  1
## 1.17 1760651912 1760653532 -0.0027427031  0.007675074  1
## 1.18 1760675612 1760675612 -0.0049890793  0.004754747  1

Run cpt with a trackframe and multiple IDs

Generate 3 tracks with different sizes

data("paths_trackframe", package = "trackframe")
class(paths_trackframe)
## [1] "trackframe" "data.frame"
set.seed(2025L)
cpt_mt <- change_point_test(paths_trackframe, alpha = 0.05, q = 3, N = 500, min_move_dist = 0)
class(cpt_mt)
## [1] "change_point_test" "trackframe"        "data.frame"

Extract the change points into a summarized format

summary(cpt_mt)
##                          first                last     east    north      id
## track_1.1  2025-10-15 00:22:40 2025-10-15 00:22:40 16.36530 48.21212 track_1
## track_1.2  2025-10-15 13:43:40 2025-10-15 13:43:40 16.36973 48.22006 track_1
## track_1.3  2025-10-15 18:00:40 2025-10-15 18:07:40 16.37277 48.21736 track_1
## track_1.4  2025-10-15 18:49:40 2025-10-15 18:49:40 16.37389 48.22543 track_1
## track_1.5  2025-10-15 20:58:40 2025-10-15 20:58:40 16.36753 48.22436 track_1
## track_1.6  2025-10-15 23:43:40 2025-10-15 23:43:40 16.37302 48.22374 track_1
## track_1.7  2025-10-16 02:39:40 2025-10-16 02:39:40 16.36653 48.22617 track_1
## track_1.8  2025-10-16 04:09:40 2025-10-16 04:09:40 16.36862 48.22318 track_1
## track_1.9  2025-10-16 07:16:40 2025-10-16 07:16:40 16.36767 48.22947 track_1
## track_1.10 2025-10-16 16:55:40 2025-10-16 17:04:40 16.36958 48.22092 track_1
## track_1.11 2025-10-16 21:48:40 2025-10-16 21:48:40 16.36747 48.21301 track_1
## track_1.12 2025-10-16 22:02:40 2025-10-16 22:29:40 16.36940 48.21726 track_1
## track_1.13 2025-10-17 04:37:40 2025-10-17 04:37:40 16.36715 48.21434 track_1
## track_2.1  2025-10-14 14:04:40 2025-10-14 14:04:40 16.37672 48.20870 track_2
## track_2.2  2025-10-14 14:33:40 2025-10-14 14:33:40 16.37524 48.20294 track_2
## track_2.3  2025-10-14 16:03:40 2025-10-14 16:03:40 16.37660 48.20664 track_2
## track_2.4  2025-10-14 17:12:40 2025-10-14 17:12:40 16.37044 48.20977 track_2
## track_2.5  2025-10-14 19:23:40 2025-10-14 19:23:40 16.37391 48.21089 track_2
## track_2.6  2025-10-14 22:28:40 2025-10-14 22:28:40 16.36534 48.21166 track_2
## track_2.7  2025-10-14 23:30:40 2025-10-14 23:30:40 16.36343 48.21471 track_2
## track_2.8  2025-10-14 23:34:40 2025-10-14 23:34:40 16.36584 48.21382 track_2
## track_2.9  2025-10-14 23:55:40 2025-10-14 23:55:40 16.36351 48.21552 track_2
## track_2.10 2025-10-15 04:13:40 2025-10-15 04:36:40 16.36485 48.21012 track_2
## track_2.11 2025-10-15 05:27:40 2025-10-15 05:27:40 16.36750 48.20579 track_2
## track_2.12 2025-10-15 05:45:40 2025-10-15 05:45:40 16.36490 48.20721 track_2
## track_2.13 2025-10-15 07:01:40 2025-10-15 07:01:40 16.37014 48.20566 track_2
## track_2.14 2025-10-15 07:42:40 2025-10-15 07:42:40 16.36696 48.20606 track_2
## track_2.15 2025-10-15 08:14:40 2025-10-15 08:14:40 16.36829 48.19944 track_2
## track_2.16 2025-10-15 13:37:40 2025-10-15 13:37:40 16.35717 48.20569 track_2
## track_2.17 2025-10-15 17:48:40 2025-10-15 17:48:40 16.35596 48.20981 track_2
## track_2.18 2025-10-15 17:52:40 2025-10-15 18:00:40 16.35379 48.21028 track_2
## track_2.19 2025-10-15 18:19:40 2025-10-15 18:19:40 16.35348 48.20674 track_2
## track_2.20 2025-10-15 21:31:40 2025-10-15 21:35:40 16.35333 48.21209 track_2
## track_2.21 2025-10-15 23:45:40 2025-10-15 23:45:40 16.35830 48.20680 track_2
## track_2.22 2025-10-16 01:23:40 2025-10-16 01:23:40 16.35570 48.21118 track_2
## track_2.23 2025-10-16 01:47:40 2025-10-16 01:49:40 16.35555 48.20850 track_2
## track_2.24 2025-10-16 02:21:40 2025-10-16 02:21:40 16.35911 48.20953 track_2
## track_2.25 2025-10-16 03:18:40 2025-10-16 03:18:40 16.35860 48.20646 track_2
## track_2.26 2025-10-16 05:01:40 2025-10-16 05:22:40 16.35601 48.21053 track_2
## track_2.27 2025-10-16 05:27:40 2025-10-16 05:57:40 16.35361 48.20933 track_2
## track_2.28 2025-10-16 09:19:40 2025-10-16 09:25:40 16.35495 48.21959 track_2
## track_2.29 2025-10-16 11:16:40 2025-10-16 11:16:40 16.35245 48.21717 track_2
## track_2.30 2025-10-16 11:56:40 2025-10-16 11:56:40 16.34919 48.21514 track_2
## track_2.31 2025-10-16 16:56:40 2025-10-16 17:09:40 16.35256 48.21845 track_2
## track_2.32 2025-10-16 22:15:40 2025-10-16 22:15:40 16.35874 48.21593 track_2
## track_2.33 2025-10-17 03:28:40 2025-10-17 03:28:40 16.36352 48.21933 track_2
## track_2.34 2025-10-17 04:14:40 2025-10-17 04:14:40 16.36308 48.21337 track_2
## track_3.1  2025-10-14 18:59:40 2025-10-14 19:26:40 16.36679 48.20774 track_3
## track_3.2  2025-10-15 03:00:40 2025-10-15 03:00:40 16.37679 48.20198 track_3
## track_3.3  2025-10-15 03:30:40 2025-10-15 03:30:40 16.37226 48.20180 track_3
## track_3.4  2025-10-15 04:53:40 2025-10-15 04:53:40 16.37531 48.20204 track_3
## track_3.5  2025-10-15 05:16:40 2025-10-15 05:16:40 16.37620 48.19683 track_3
## track_3.6  2025-10-15 06:13:40 2025-10-15 06:13:40 16.37968 48.20056 track_3
## track_3.7  2025-10-15 07:42:40 2025-10-15 07:42:40 16.37414 48.19611 track_3
## track_3.8  2025-10-15 09:06:40 2025-10-15 09:06:40 16.37644 48.20000 track_3
## track_3.9  2025-10-15 10:12:40 2025-10-15 10:12:40 16.37759 48.19690 track_3
## track_3.10 2025-10-15 14:20:40 2025-10-15 14:20:40 16.36968 48.20013 track_3
## track_3.11 2025-10-15 14:58:40 2025-10-15 14:58:40 16.36961 48.19513 track_3
## track_3.12 2025-10-15 15:47:40 2025-10-15 16:09:40 16.36787 48.19673 track_3
## track_3.13 2025-10-15 16:29:40 2025-10-15 16:29:40 16.37350 48.19521 track_3
## track_3.14 2025-10-15 16:47:40 2025-10-15 16:47:40 16.37052 48.19890 track_3
## track_3.15 2025-10-15 21:25:40 2025-10-15 21:48:40 16.36621 48.19015 track_3
## track_3.16 2025-10-16 00:34:40 2025-10-16 01:09:40 16.36570 48.19650 track_3
## track_3.17 2025-10-16 03:18:40 2025-10-16 03:49:40 16.36720 48.20202 track_3
## track_3.18 2025-10-16 03:59:40 2025-10-16 03:59:40 16.36995 48.19849 track_3
## track_3.19 2025-10-16 05:32:40 2025-10-16 05:32:40 16.36687 48.20032 track_3
## track_3.20 2025-10-16 10:30:40 2025-10-16 10:30:40 16.36438 48.20783 track_3
## track_3.21 2025-10-16 11:54:40 2025-10-16 11:54:40 16.36124 48.21105 track_3
## track_3.22 2025-10-16 11:58:40 2025-10-16 12:24:40 16.36106 48.20817 track_3
## track_3.23 2025-10-16 13:02:40 2025-10-16 13:02:40 16.36277 48.21356 track_3
## track_3.24 2025-10-16 15:09:40 2025-10-16 15:38:40 16.35926 48.21115 track_3
## track_3.25 2025-10-16 15:53:40 2025-10-16 15:53:40 16.35855 48.21306 track_3
## track_3.26 2025-10-16 15:57:40 2025-10-16 15:57:40 16.36063 48.21134 track_3
## track_3.27 2025-10-16 17:21:40 2025-10-16 17:21:40 16.35838 48.21358 track_3
## track_3.28 2025-10-16 19:15:40 2025-10-16 19:15:40 16.36179 48.21730 track_3
## track_3.29 2025-10-16 19:26:40 2025-10-16 19:48:40 16.35954 48.21332 track_3
## track_3.30 2025-10-16 21:43:40 2025-10-16 21:43:40 16.35924 48.21691 track_3
## track_3.31 2025-10-17 00:08:40 2025-10-17 00:08:40 16.35556 48.21723 track_3
## track_3.32 2025-10-17 00:39:40 2025-10-17 00:39:40 16.35664 48.22160 track_3
head(select_id(cpt_mt, "track_1"))
##                  time northing  easting      id cp_id
## 1 2025-10-14 13:48:40 48.20835 16.37250 track_1     0
## 2 2025-10-14 13:49:40 48.20838 16.37246 track_1     0
## 3 2025-10-14 13:50:40 48.20839 16.37302 track_1     0
## 4 2025-10-14 13:51:40 48.20868 16.37227 track_1     0
## 5 2025-10-14 13:52:40 48.20958 16.37214 track_1     0
## 6 2025-10-14 13:53:40 48.20952 16.37119 track_1     0
tail(select_id(cpt_mt, "track_3"))
##                     time northing  easting      id cp_id
## 2995 2025-10-17 05:15:40 48.21445 16.35630 track_3     0
## 2996 2025-10-17 05:16:40 48.21376 16.35681 track_3     0
## 2997 2025-10-17 05:17:40 48.21461 16.35637 track_3     0
## 2998 2025-10-17 05:18:40 48.21437 16.35685 track_3     0
## 2999 2025-10-17 05:19:40 48.21417 16.35599 track_3     0
## 3000 2025-10-17 05:20:40 48.21484 16.35508 track_3     0

Run cpt with xyt data.frame

Detect change points

data("path_data_frame", package = "trackframe")
class(path_data_frame)
## [1] "data.frame"
set.seed(2025L)
cpt <- change_point_test(path_data_frame, alpha = 0.05, q = 3, N = 500)
class(cpt)
## [1] "change_point_test" "trackframe"        "data.frame"

Alternatively, in order to remove the warning coerce to trackframe first by setting crs.

projected_crs <- "EPSG:32632"
tf <- as.trackframe(path_matrix, crs = projected_crs)
set.seed(2025L)
cpt_tf <- change_point_test(tf, alpha = 0.05, q = 3, N = 500)
all.equal(cpt$cp_id, cpt_tf$cp_id)
## [1] "Mean relative difference: 2.065574"

Extract the change points into a summarized format

summary(cpt)
##                          first                last          east       north
## track_1.1  2025-10-15 00:22:34 2025-10-15 00:22:34 -0.0072061100 0.003763871
## track_1.2  2025-10-15 13:43:34 2025-10-15 13:43:34 -0.0027773379 0.011703586
## track_1.3  2025-10-15 18:00:34 2025-10-15 18:07:34  0.0002694329 0.009003683
## track_1.4  2025-10-15 18:49:34 2025-10-15 18:49:34  0.0013820211 0.017076390
## track_1.5  2025-10-15 20:58:34 2025-10-15 20:58:34 -0.0049726251 0.016002070
## track_1.6  2025-10-15 23:43:34 2025-10-15 23:43:34  0.0005152087 0.015387244
## track_1.7  2025-10-16 02:39:34 2025-10-16 02:39:34 -0.0059711263 0.017819524
## track_1.8  2025-10-16 04:09:34 2025-10-16 04:09:34 -0.0038805680 0.014830813
## track_1.9  2025-10-16 05:59:34 2025-10-16 06:49:34 -0.0032596397 0.019189124
## track_1.10 2025-10-16 07:16:34 2025-10-16 07:16:34 -0.0048342032 0.021118660
## track_1.11 2025-10-16 16:55:34 2025-10-16 17:04:34 -0.0029274680 0.012569104
## track_1.12 2025-10-16 21:48:34 2025-10-16 21:48:34 -0.0050339505 0.004651530
## track_1.13 2025-10-16 22:02:34 2025-10-16 22:29:34 -0.0031042727 0.008906007
## track_1.14 2025-10-17 04:37:34 2025-10-17 04:37:34 -0.0053506489 0.005985680
##                 id
## track_1.1  track_1
## track_1.2  track_1
## track_1.3  track_1
## track_1.4  track_1
## track_1.5  track_1
## track_1.6  track_1
## track_1.7  track_1
## track_1.8  track_1
## track_1.9  track_1
## track_1.10 track_1
## track_1.11 track_1
## track_1.12 track_1
## track_1.13 track_1
## track_1.14 track_1

Run cpt with move2

Detect change points

data("path_move2", package = "trackframe")
class(path_move2)
## [1] "move2"      "sf"         "data.frame"
set.seed(2025L)
path_move2 <- sf::st_transform(path_move2, projected_crs)
class(path_move2) <- c("move2", "sf", "data.frame")
cpt <- change_point_test(path_move2, alpha = 0.05, q = 3, N = 100)
class(cpt)
## [1] "change_point_test" "move2"             "sf"               
## [4] "data.frame"

Extract the change points into a summarized format

tail(summary(cpt), n = 5)
##                  first                last         east       north
## 10 2025-10-16 07:16:34 2025-10-16 07:16:34 -0.004834203 0.021118660
## 11 2025-10-16 16:55:34 2025-10-16 17:04:34 -0.002927468 0.012569104
## 12 2025-10-16 21:48:34 2025-10-16 21:48:34 -0.005033951 0.004651530
## 13 2025-10-16 22:02:34 2025-10-16 22:29:34 -0.003104273 0.008906007
## 14 2025-10-17 04:37:34 2025-10-17 04:37:34 -0.005350649 0.005985680

Run cpt with sftrack

Detect change points

data("path_sftrack", package = "trackframe")
class(path_sftrack)
## [1] "sftrack"    "sf"         "data.frame"
path_sftrack <- sf::st_transform(path_sftrack, projected_crs)
class(path_sftrack) <- c("sftrack", "sf", "data.frame")
set.seed(2025L)
cpt <- change_point_test(path_sftrack, alpha = 0.05, q = 3, N = 500)
class(cpt)
## [1] "change_point_test" "sftrack"           "sf"               
## [4] "data.frame"

Extract the change points into a summarized format

summary(cpt)
##                  first                last          east       north
## 1  2025-10-15 00:22:34 2025-10-15 00:22:34 -0.0072061100 0.003763871
## 2  2025-10-15 13:43:34 2025-10-15 13:43:34 -0.0027773379 0.011703586
## 3  2025-10-15 18:00:34 2025-10-15 18:07:34  0.0002694329 0.009003683
## 4  2025-10-15 18:49:34 2025-10-15 18:49:34  0.0013820211 0.017076390
## 5  2025-10-15 20:58:34 2025-10-15 20:58:34 -0.0049726251 0.016002070
## 6  2025-10-15 23:43:34 2025-10-15 23:43:34  0.0005152087 0.015387244
## 7  2025-10-16 02:39:34 2025-10-16 02:39:34 -0.0059711263 0.017819524
## 8  2025-10-16 04:09:34 2025-10-16 04:09:34 -0.0038805680 0.014830813
## 9  2025-10-16 05:59:34 2025-10-16 06:49:34 -0.0032596397 0.019189124
## 10 2025-10-16 07:16:34 2025-10-16 07:16:34 -0.0048342032 0.021118660
## 11 2025-10-16 16:55:34 2025-10-16 17:04:34 -0.0029274680 0.012569104
## 12 2025-10-16 21:48:34 2025-10-16 21:48:34 -0.0050339505 0.004651530
## 13 2025-10-16 22:02:34 2025-10-16 22:29:34 -0.0031042727 0.008906007
## 14 2025-10-17 04:37:34 2025-10-17 04:37:34 -0.0053506489 0.005985680

Run cpt with cocomo format

Create cocomo format data

padding <- 25
n_times <- 20 + 3 * padding
n <- 2

xs <- matrix(
  c(
    rep(-1, padding),
    c(-1, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1),
    rep(0, padding),
    c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1),
    rep(1, padding),
    rep(0, n_times)
  ),
  n, n_times, byrow = TRUE
)
ys <- matrix(
  rep(0, n * n_times),
  n, n_times, byrow = TRUE
)
timestamps <- as.POSIXct(1:n_times)

ids <- rbind.data.frame(
  list("id_code" = 'VCVM001', "age" = 10, "sex" = "m"),
  list("id_code" = 'WRTH', "age" = 5, "sex" = "f")
)

Transform to trackframe

cocomo_tf <- cocomo_as_tf(xs, ys, timestamps, ids)
head(cocomo_tf)
##                  time easting northing      id age sex
## 1 1970-01-01 00:00:01      -1        0 VCVM001  10   m
## 2 1970-01-01 00:00:02      -1        0 VCVM001   5   f
## 3 1970-01-01 00:00:03      -1        0 VCVM001  10   m
## 4 1970-01-01 00:00:04      -1        0 VCVM001   5   f
## 5 1970-01-01 00:00:05      -1        0 VCVM001  10   m
## 6 1970-01-01 00:00:06      -1        0 VCVM001   5   f
class(cocomo_tf)
## [1] "trackframe" "data.frame"

Detect change points

set.seed(2025L)
cpt <- change_point_test(cocomo_tf, alpha = 0.05, q = 3, N = 500)
class(cpt)
## [1] "change_point_test" "trackframe"        "data.frame"

Extract the change points into a summarized format (no change points found)

summary(cpt)
## NULL