https://github.com/euanmcgonigle/cptnonpar
Development version of the CptNonPar R package
https://github.com/euanmcgonigle/cptnonpar
change-point-detection cran moving-sum nonparametric package r segmentation time-series
Last synced: 7 months ago
JSON representation
Development version of the CptNonPar R package
- Host: GitHub
- URL: https://github.com/euanmcgonigle/cptnonpar
- Owner: EuanMcGonigle
- Created: 2023-05-12T14:08:15.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-23T07:17:09.000Z (9 months ago)
- Last Synced: 2025-10-22T05:59:27.298Z (7 months ago)
- Topics: change-point-detection, cran, moving-sum, nonparametric, package, r, segmentation, time-series
- Language: R
- Homepage: https://CRAN.R-project.org/package=CptNonPar
- Size: 133 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# CptNonPar
[](https://github.com/EuanMcGonigle/CptNonPar/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/EuanMcGonigle/CptNonPar?branch=main)
Nonparametric change point detection for multivariate time series. Implements the NP-MOJO methodology proposed in [McGonigle and Cho (2025)](https://doi.org/doi:10.1093/biomet/asaf024).
## Installation
You can install the released version of `CptNonPar` from [CRAN](https://CRAN.R-project.org) with:
```
install.packages("CptNonPar")
```
You can install the development version of `CptNonPar` from [GitHub](https://github.com/) with:
```
devtools::install_github("https://github.com/EuanMcGonigle/CptNonPar")
```
## Usage
For further examples, see the help files within the package. We can generate an example for change point detection as follows.
We generate a univariate time series of length 1000, with a mean change at time 300, and an autocovariance (but not marginal) change at time 650. Then, we perform the multi-lag NP-MOJO algorithm with lags 0 and 1, and print the estimated change points and the associated clusters:
```{r example}
library(CptNonPar)
n <- 1000
set.seed(123)
noise1 <- stats::arima.sim(model = list(ar = -0.5), n = n, sd = sqrt(1 - 0.5^2))
noise2 <- stats::arima.sim(model = list(ar = 0.5), n = n, sd = sqrt(1 - 0.5^2))
noise <- c(noise1[1:650], noise2[651:n])
signal <- c(rep(0, 300), rep(0.7, 700))
x <- signal + noise
x.c <- np.mojo.multilag(x, G = 166, lags = c(0, 1))
x.c$cpts
x.c$cpt.clusters
```