ras_box_stat: Box-Scan Statistic for Every Window Start and Width

View source: R/box_scan.R

ras_box_statR Documentation

Box-Scan Statistic for Every Window Start and Width

Description

Computes the box-scan score T(i, w) of every window of every width in widths along a RAS scan profile. This is the building block of ras_box_detect; most users will call that function instead.

Usage

ras_box_stat(
  y,
  widths = .ras_box_default_widths(),
  level0 = NA_real_,
  gamma = 0.5,
  edge = c("open", "strict")
)

Arguments

y

Numeric vector. The scan profile (-\log_{10}(p) values from ras_scan or ras_scan_external). Must be free of NA.

widths

Integer vector. Window widths in grid points. Default c(5, 8, 11, 14, 17, 20, 24, 28, 34, 42, 55, 75, 100). Widths that do not fit the profile are dropped.

level0

Numeric. Typical median of a null profile (element level0 of a ras_box_calibrate result). NA (default) disables the level factor.

gamma

Numeric. Exponent of the level factor. Default 0.5.

edge

"open" (default) or "strict". With "strict" both flanks must lie inside the profile, so a region at a chromosome end can never be reported. With "open" a flank that runs off the profile is truncated, and dropped altogether when fewer than 3 points remain; the window then only has to stand above the side that exists (and above the background).

Details

For a window of w grid points starting at i, with flanks of f = \max(5, w/2) points on each side,

contrast = mean(window) - max(mean(left flank), mean(right flank))

height = mean(window) - median(y)

T = min(contrast, height) / max(1, median(y)/level0)^{gamma}.

All quantities are in the raw units of the profile; no noise scale is estimated. A window inside a plateau, on the shoulder of a peak, or spanning a cluster of neighbouring peaks scores about 0 because at least one flank is as high as the window.

Value

A data frame with one row per (start, width) pair and columns i (window start, grid index), w (width), contrast, height and T.

See Also

ras_box_detect, ras_box_calibrate.

Examples

y <- rep(1, 400); y[201:230] <- 8
S <- ras_box_stat(y)
S[which.max(S$T), ]          # the 30-point window starting at 201

RAS documentation built on Nov. 3, 2026, 1:07 a.m.