detect_single_cp: Detecting single change-point

Description Usage Arguments Value Examples

View source: R/SingleChangePoint.R

Description

Detecting single change-point

Usage

1
detect_single_cp(X = NULL, D = NULL, 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.

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 integer value denoting estimated change-point location

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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 = 4, sd = 1), nrow = 15, ncol = 50)
X = rbind(X1, X2)

detect_single_cp(X = X)  # Detect single change-point with default average linkage
detect_single_cp(X = X, dist.method = "single") # Detect single change-point with single linkage

# Example 2
X1 = matrix(rnorm((15 * 50), mean = 0, sd = 1), nrow = 15, ncol = 50)
X2 = matrix(rnorm((15 * 50), mean = 4, sd = 1), nrow = 15, ncol = 50)
X = rbind(X1, X2)

# Calculate distance matrix
D_mat = as.matrix(stats::dist(X, method = "euclidean"))
# Only distance matrix is supplied
# Detect single change-point with default average linkage
detect_single_cp(D = D_mat)
# Detect single change-point with complete linkage
detect_single_cp(D = D_mat, dist.method = "complete")

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