get_local_maximum: Find the Local Maximum Within a Window

View source: R/utils.R

get_local_maximumR Documentation

Find the Local Maximum Within a Window

Description

Returns the index of the maximum value of y within a symmetric window of half-width window.size centred at x0.

Usage

get_local_maximum(y, x0, window.size = 50)

Arguments

y

Numeric vector. Values to search (e.g., -\log_{10}(p) values from the RAS scan).

x0

Integer. Centre index of the search window.

window.size

Integer. Half-width of the search window. The search covers indices max(1, x0 - window.size) to min(length(y), x0 + window.size). Default 50.

Details

This function is used by ras_detect after the sliding-window loop to snap each accepted changepoint index to the nearest local peak in the -\log_{10}(p) profile. Snapping to the peak ensures that reported positions correspond to the most significant SNP in the association region rather than to the mathematical breakpoint of the piecewise linear fit, which may be slightly offset.

Value

Integer. The index (into y) of the local maximum within the window centred at x0. If multiple positions tie for the maximum, which.max returns the first.

See Also

ras_detect which calls this function to refine detected changepoint positions.

Examples

y <- c(1, 3, 7, 5, 2, 8, 4, 1)

## Peak within a window of half-width 2 centred at index 3
get_local_maximum(y, x0 = 3, window.size = 2)  # returns 3 (value = 7)

## Peak within a window of half-width 3 centred at index 3
## covers indices 1:6; max is at index 6 (value = 8)
get_local_maximum(y, x0 = 3, window.size = 3)  # returns 6

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