detect_estimated_cp: Detecting change-point location(s) for unknown number of...

Description Usage Arguments Value Examples

View source: R/DetectChangePoint_NumUnknown.R

Description

Detecting change-point location(s) for unknown number of change-points

Usage

1
2
3
4
5
6
7
detect_estimated_cp(
  X = NULL,
  D = NULL,
  p = NULL,
  dist.method = "average",
  lambda = 0.02
)

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.

p

Dimension of the observations. Should be supplied if distance matrix D is supplied instead of data matrix X.

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".

lambda

Penalty parameter. Default is 0.02.

Value

Returns a integer or a numeric vector denoting estimated change-point location(s) depending on single or multiple change-point(s) is/are detected. Returns the last observation number (time point) in case of non-detection.

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 * 200), mean = 0, sd = 1), nrow = 15, ncol = 200)
X2 = matrix(rnorm((15 * 200), mean = 5, sd = 1), nrow = 15, ncol = 200)
X3 = matrix(rnorm((15 * 200), mean = 10, sd = 1), nrow = 15, ncol = 200)
X = rbind(X1, X2, X3)

 # Detect change-points with default average linkage
detect_estimated_cp(X = X)

# Detect change-points with complete linkage
detect_estimated_cp(X = X, dist.method = "complete")

# Example 2
set.seed(1)
# Generate data matrix
X1 = matrix(rnorm((15 * 200), mean = 0, sd = 1), nrow = 15, ncol = 200)
X2 = matrix(rnorm((15 * 200), mean = 5, sd = 1), nrow = 15, ncol = 200)
X3 = matrix(rnorm((15 * 200), mean = 10, sd = 1), nrow = 15, ncol = 200)
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
detect_estimated_cp(D = D_mat, p = 200)  # correct change-points are detected

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