| ras_detect | R Documentation |
Scans a -\log_{10}(p)-value sequence using a sliding window to
detect positions where the slope changes significantly from positive to
negative.
ras_detect(
x,
y,
p.values.threshold = 0.01,
min.length = 10,
skip = 1,
window_size = 3000,
slope_check_window_size = 30,
slope.p.values.threshold = 1e-08,
slope.p.values.threshold.left = 1e-10,
slope.p.values.threshold.right = 1e-20
)
x |
Numeric vector. Predictor sequence (e.g., SNP position indices). |
y |
Numeric vector. Response sequence (e.g., |
p.values.threshold |
Numeric. Davies test p-value threshold for
nominating a candidate changepoint. Default |
min.length |
Integer. Minimum number of observations required on each
side of a candidate changepoint. Default |
skip |
Integer. Step size when iterating the sliding window start
position. Default |
window_size |
Integer. Number of observations in each sliding window.
Default |
slope_check_window_size |
Integer. Half-width of the local region used
to verify slope direction via |
slope.p.values.threshold |
Numeric. Reserved combined slope threshold
(currently unused in filtering). Default |
slope.p.values.threshold.left |
Numeric. One-tailed p-value threshold
for the left-side slope test. A candidate is accepted only if the slope
to its left is significantly positive ( |
slope.p.values.threshold.right |
Numeric. One-tailed p-value threshold
for the right-side slope test. A candidate is accepted only if the slope
to its right is significantly negative ( |
At each window start position the function calls
get_break_points on the window to estimate and test a single
breakpoint. A candidate is retained when three conditions are all met:
The Davies test p-value is below p.values.threshold.
The left-side slope (estimated by segmented regression) is positive.
The right-side slope is negative.
Candidates passing these three filters are then subjected to one-tailed
slope tests (slope_test) using centred sub-sequences of
half-width slope_check_window_size. Only candidates that also pass
both slope p-value thresholds are recorded.
After the sliding-window loop, each accepted changepoint is refined to the
nearest local peak in y via get_local_maximum.
The function records all candidates examined (all.changepoints,
all.p.values) in addition to the accepted ones, so that downstream
functions can display the full candidate landscape.
A named list with eight elements:
tau_hatsInteger vector. Accepted changepoint indices (refined to local peaks).
p.valuesNumeric vector. Davies test p-values at accepted changepoints.
slope.leftNumeric vector. Left-side slopes at accepted changepoints.
slope.rightNumeric vector. Right-side slopes at accepted changepoints.
all.changepointsInteger vector. All candidate positions examined, including those that failed the slope tests.
all.p.valuesNumeric vector. Davies p-values for all
examined candidates; set to 1 for candidates that failed the
slope direction or slope significance filters.
slope.angleNumeric vector. Interior angle (degrees) at each accepted changepoint, computed from the left and right slope estimates.
previous_tau_hatsInteger vector. Copy of tau_hats
before any downstream modification; used by
ras_validate.
ras_validate for the second-pass validation step.
get_break_points for the per-window segmented regression.
slope_test for the one-tailed slope verification.
get_local_maximum for the peak-refinement step.
ras for the recommended end-to-end entry point.
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)
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
)
cat("Detected changepoints:", result$tau_hats, "\n")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.