slope_test: One-Tailed Slope Test Through the Origin

View source: R/changepoint.R

slope_testR Documentation

One-Tailed Slope Test Through the Origin

Description

Fits a no-intercept linear model y ~ x - 1 and performs a one-tailed t-test on the slope coefficient.

Usage

slope_test(x, y, lower.tail)

Arguments

x

Numeric vector. Predictor values, typically centred at the candidate changepoint so that the origin corresponds to the changepoint position.

y

Numeric vector. Response values, same length as x, typically centred at the changepoint y-value.

lower.tail

Logical. Passed to pt. Use FALSE to test H_0\!: \beta \ge 0 against H_1\!: \beta < 0 (left-slope test); use TRUE for the opposite direction (right-slope test).

Details

The model lm(y ~ x - 1) forces the regression line through the origin, which is appropriate after centring both x and y at the candidate changepoint. Under this parameterisation a positive left slope and a negative right slope correspond to the peak shape expected at a true association region.

The function is called by ras_detect on both sides of each Davies-significant candidate, using asymmetric thresholds (cp_slope_left = 1e-10, cp_slope_right = 1e-20 by default) to require a steeper descending edge than ascending edge.

Value

Numeric scalar. The one-tailed p-value for the slope coefficient.

See Also

get_break_points for the Davies test step that precedes this slope check. ras_detect for the full detection workflow.

Examples

# Left-side slope: x goes from negative to 0, y should be rising (positive slope)
x_left <- -10:0
y_left <- x_left * 0.8 + rnorm(11, sd = 0.3)
slope_test(x_left, y_left, lower.tail = FALSE)  # expect small p (slope > 0)

# Right-side slope: x goes from 0 to positive, y should be falling (negative slope)
x_right <- 0:10
y_right <- x_right * (-0.8) + rnorm(11, sd = 0.3)
slope_test(x_right, y_right, lower.tail = TRUE)  # expect small p (slope < 0)

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