ras_validate: Second-Pass Changepoint Validation

View source: R/changepoint.R

ras_validateR Documentation

Second-Pass Changepoint Validation

Description

Validates candidate changepoints from ras_detect by re-running local Davies tests in windows around each candidate.

Usage

ras_validate(
  this.result,
  x,
  y,
  this.start = 1,
  this.skip = 30,
  second_window_size = 50,
  p.value.threshold = 1e-10,
  min_signal = 2.5
)

Arguments

this.result

List. Output from ras_detect.

x

Numeric vector. Predictor sequence used in the original scan.

y

Numeric vector. Response sequence used in the original scan.

this.start

Integer. Genomic start position for index re-mapping to chromosome coordinates. Default 1.

this.skip

Integer. Step size used in the original scan (skip1), needed for index re-mapping. Default 30.

second_window_size

Integer. Half-window size for local Davies test re-validation. Default 50.

p.value.threshold

Numeric. Davies test p-value threshold for second-pass acceptance. A candidate is retained if either the right-side or left-side local Davies test passes. Default 1e-10.

min_signal

Numeric. Minimum -\log_{10}(p) scan value required to retain a validated changepoint. Candidates with y[tau_hat] <= min_signal are removed after the Davies filter. Default 2.5.

Details

For each candidate \hat{\tau} in this.result$tau_hats the function fits two local linear models and applies the Davies test to each: one on the window [\hat{\tau},\; \min(\hat{\tau} + \texttt{second\_window\_size},\, n)] and one on [\max(\hat{\tau} - \texttt{second\_window\_size},\, 1),\; \hat{\tau}]. If either Davies p-value is below p.value.threshold, the candidate is accepted; otherwise its all.p.values entry is set to zero to suppress it in downstream plots.

Windows with fewer than four observations are not tested (Davies test requires at least four points) and their p-value is set to 1.0.

After filtering, any remaining candidate with y[tau_hat] <= min_signal is removed, as such positions are below the minimum signal threshold.

Accepted changepoint indices and all candidate indices are re-mapped from the scan grid to genomic coordinates via \texttt{this.start} + (\text{index} - 1) \times \texttt{this.skip}.

Value

A named list with five elements:

tau_hats

Integer vector. Validated changepoint positions, re-mapped to genomic coordinates.

all.changepoints

Integer vector. All candidate positions examined, re-mapped to genomic coordinates.

all.p.values

Numeric vector. -\log_{10}(p) Davies values for each candidate; set to 0 for rejected candidates.

left.slopes

Numeric vector. Left-side slopes at accepted changepoints (carried over from first-pass output).

right.slopes

Numeric vector. Right-side slopes at accepted changepoints.

See Also

ras_detect for the first-pass detection step whose output this function takes as input. plot.ras for visualising the validated changepoints. ras for the recommended end-to-end entry point.

Examples


set.seed(42)
x <- 1:300
y <- c(seq(0, 8, length.out = 150),
       seq(8, 1, length.out = 150)) + rnorm(300, sd = 0.5)

cp_result <- ras_detect(
  x, y,
  window_size             = 150,
  slope_check_window_size = 20,
  slope.p.values.threshold.left  = 1e-3,
  slope.p.values.threshold.right = 1e-3
)

final <- ras_validate(
  cp_result, x = x, y = y,
  this.skip          = 1,
  second_window_size = 30,
  p.value.threshold  = 1e-3
)
cat("Validated changepoints:", final$tau_hats, "\n")


RAS documentation built on July 24, 2026, 5:06 p.m.