Learn R Programming

HDCD (version 1.0)

ESAC_test_calibrate: Generates empirical penalty function \(\gamma(t)\) for single change-point testing using Monte Carlo simulation

Description

R wrapper for C function choosing the penalty function \(\gamma(t)\) by Monte Carlo simulation, as described in Appendix B in moen2023efficient;textualHDCD, for testing for a single change-point.

Usage

ESAC_test_calibrate(
  n,
  p,
  bonferroni = TRUE,
  N = 1000,
  tol = 1/1000,
  fast = FALSE,
  rescale_variance = TRUE,
  debug = FALSE
)

Value

A list containing a vector of values of \(\gamma(t)\) for \(t \in \mathcal{T}\) decreasing (element #1), a vector of corresponding values of the threshold \(a(t)\) (element # 3), a vector of corresponding values of \(\nu_{a(t)}\)

A list containing

without_partial

a vector of values of \(\gamma(t)\) for \(t \in \mathcal{T}\) decreasing in \(t\)

with_partial

same as without_partial

as

vector of threshold values \(a(t)\) for \(t \in \mathcal{T}\) decreasing in \(t\)

nu_as

vector of conditional expectations \(\nu_{a(t)}\) of a thresholded Gaussian, for \(t \in \mathcal{T}\) decreasing in \(t\)

Arguments

n

Number of observations

p

Number time series

bonferroni

If TRUE, a Bonferroni correction applied and the empirical penalty function \(\gamma(t)\) is chosen by simulating leading constants of \(r(t)\) through Monte Carlo simulation.

N

Number of Monte Carlo samples used

tol

False positive probability tolerance

fast

If TRUE, ESAC only tests for a change-point at the midpoint of the interval \((0,\ldots,n]\)

rescale_variance

If TRUE, each row of the data is re-scaled by a MAD estimate using rescale_variance

debug

If TRUE, diagnostic prints are provided during execution

References

Examples

Run this code
library(HDCD)
n = 50
p = 50

set.seed(100)
thresholds_emp = ESAC_test_calibrate(n,p, bonferroni=TRUE,N=100, tol=1/100)
set.seed(100)
thresholds_emp_without_bonferroni = ESAC_test_calibrate(n,p, bonferroni=FALSE,N=100, tol=1/100)
thresholds_emp[[1]] # vector of \gamma(t) for t = p,...,1
thresholds_emp_without_bonferroni[[1]] # vector of \gamma(t) for t = p,...,1

# Generating data
X = matrix(rnorm(n*p), ncol = n, nrow=p)
Y = matrix(rnorm(n*p), ncol = n, nrow=p)

# Adding a single sparse change-point to X (and not Y):
X[1:5, 26:n] = X[1:5, 26:n] +2
resX = ESAC_test(X, thresholds = thresholds_emp[[1]])
resX
resY = ESAC_test(Y,  thresholds = thresholds_emp[[1]])
resY

Run the code above in your browser using DataLab