Bayesian Change Point Detection for High-Dimensional Data
Up-to-date development version of hdbcp can be obtained from github:
## install.packages("devtools")
## library(devtools)
::install_github("JaeHoonKim98/hdbcp") devtools
You can simply run the function using default parameters.
library(hdbcp)
library(MASS)
<- c(25, 60, 100) # A set of window sizes
nws <- seq(1,10,0.05) # A grid of alpha values
alps
# Mean method
<- rep(0,10)
mu1 <- rep(1,10)
mu2 <- diag(10)
sigma1 <- mvrnorm(500, mu1, sigma1)
X <- rbind(mvrnorm(250, mu1, sigma1), mvrnorm(250, mu2, sigma1))
Y <- mxPBF_mean(X, nws, alps)
res_mxPBF1 <- mxPBF_mean(Y, nws, alps)
res_mxPBF2 majority_rule_mxPBF(res_mxPBF1, nws, 500)
majority_rule_mxPBF(res_mxPBF2, nws, 500)
# Covariance method
<- diag(10)
sigma2 for (i in 1:10) {
for (j in i:10) {
if (i == j) {
next
else {
} <- rnorm(1, 1, 1)
cov_value <- cov_value
sigma1[i, j] <- cov_value
sigma1[j, i]
}
}
}<- rbind(mvrnorm(250, mu1, sigma1), mvrnorm(250, mu1, sigma2))
Z <- mxPBF_cov(X, nws, alps)
res_mxPBF3 <- mxPBF_cov(Z, nws, alps)
res_mxPBF4 majority_rule_mxPBF(res_mxPBF3, nws, 500)
majority_rule_mxPBF(res_mxPBF4, nws, 500)
# Combined method
<- rbind(mvrnorm(150,mu1,sigma1), mvrnorm(150,mu2,sigma1), mvrnorm(200,mu2,sigma2))
W mxPBF_combined(W, nws, alps)
Alternatively, we can generate data with mean changes and apply the method with specific parameters.
# Set the number of observation, dimension, type of precision matrix, and signals.
<- 500 # Number of observations
n <- 200 # Dimension
p <- 0.3 # Size of nonzero precision elements
pre_value <- 0.4 # Proportion of nonzero precision elements
pre_proportion <- 1 # Size of signals at change point
signal_size <- 250 # Location of change point in single change scenarios
single_point <- c(150, 300, 350) # Location of change points in multiple change scenarios
multiple_points
# Set parameters for mxPBF
<- 0.05 # Prespecified False Positive Rate when selecting hyperparameter alpha
FPR_want <- c(25, 60, 100)
nws <- seq(1,10,0.05)
alps <- 300 # Number of generating samples for calculating empirical FPR
n_sample <- 1 # Number of cores for parellelizing
n_cores
# Generate dataset with mean changes
<- generate_mean_datasets(n, p, signal_size, pre_proportion, pre_value, single_point, multiple_points, type = c(1,2,3,4,5))
given_datasets ## H0 data
<- matrix(given_datasets[,,1], n, p)
given_data <- mxPBF_mean(given_data, nws, alps, FPR_want, n_sample, n_cores)
res_mxPBF majority_rule_mxPBF(res_mxPBF, nws, n)
## H1 data
<- matrix(given_datasets[,,2], n, p)
given_data <- mxPBF_mean(given_data, nws, alps, FPR_want, n_sample, n_cores)
res_mxPBF majority_rule_mxPBF(res_mxPBF, nws, n)
We can generate data with covariance changes and run the test.
# Set the number of observation, dimension, type of precision matrix, and signals.
<- 500
n <- 200
p <- FALSE # Sparsity of covariance matrix
sparse <- 3
signal_size <- 250
single_point <- c(150, 300, 350)
multiple_points
# Set parameters for mxPBF
<- 0.05
FPR_want <- c(25, 60, 100)
nws <- seq(1,10,0.05)
alps <- 300
n_sample <- 1
n_cores <- b0 <- 0.01 # Hyperparameters for mxPBF
a0
# Generate dataset with covariance changes
<- generate_cov_datasets(n, p, signal_size, sparse, single_point, multiple_points, type = c(1,2,3,4,5))
given_datasets ## H0 data
<- matrix(given_datasets[,,1], n, p)
given_data <- mxPBF_cov(given_data, a0, b0, nws, alps, FPR_want, n_sample, n_cores, centering = "skip")
res_mxPBF majority_rule_mxPBF(res_mxPBF, nws, n)
## H1 data
<- matrix(given_datasets[,,2], n, p)
given_data <- mxPBF_cov(given_data, a0, b0, nws, alps, FPR_want, n_sample, n_cores, centering = "skip")
res_mxPBF majority_rule_mxPBF(res_mxPBF, nws, n)