detect_multiple_cp: Detecting multiple change-point locations for known number of...

Description Usage Arguments Value Examples

View source: R/MultipleChangePoint_NumKnown.R

Description

Detecting multiple change-point locations for known number of change-points

Usage

1
detect_multiple_cp(X = NULL, D = NULL, numcp, dist.method = "average")

Arguments

X

Data matrix (n X p) where n denotes number of observations. Each row is a p dimensional observation vector. n observations are arranged in chronological order.

D

Distance matrix (n X n) corresponding to the data matrix. Either the data matrix or the distance matrix should be supplied. Default is the Euclidean distance to construct the distance matrix when data matrix is supplied.

numcp

Number of change-points to detect

dist.method

Linkage method to use in hierarchical clustering for calculating the distances between consecutive clusters. This must be one of "single", "average" or "complete". Default is "average".

Value

Returns a numeric vector denoting estimated change-point locations

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Example 1
set.seed(1)
# Generate data matrix
X1 = matrix(rnorm((15 * 50), mean = 0, sd = 1), nrow = 15, ncol = 50)
X2 = matrix(rnorm((15 * 50), mean = 1, sd = 1), nrow = 15, ncol = 50)
X3 = matrix(rnorm((15 * 50), mean = 2, sd = 1), nrow = 15, ncol = 50)
X = rbind(X1, X2, X3)

# Detect two change-points with default average linkage
detect_multiple_cp(X = X, numcp = 2)

# Detect four change-points with default complete linkage
detect_multiple_cp(X = X, numcp = 4, dist.method = "complete")

# Example 2
set.seed(1)
# Generate data matrix
X1 = matrix(rnorm((15 * 50), mean = 0, sd = 1), nrow = 15, ncol = 50)
X2 = matrix(rnorm((15 * 50), mean = 1, sd = 1), nrow = 15, ncol = 50)
X3 = matrix(rnorm((15 * 50), mean = 2, sd = 1), nrow = 15, ncol = 50)
X = rbind(X1, X2, X3)

# Calculate distance matrix
D_mat = as.matrix(stats::dist(X, method = "euclidean"))

# Only distance matrix is supplied
# Detect multiple change-points (here 2) with default average linkage
detect_multiple_cp(D = D_mat, numcp = 2)  # correct change-points are detected

DawnTrisha/hclustHDCP documentation built on Dec. 17, 2021, 4:10 p.m.