| slope_test | R Documentation |
Fits a no-intercept linear model y ~ x - 1 and performs a
one-tailed t-test on the slope coefficient.
slope_test(x, y, lower.tail)
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 |
lower.tail |
Logical. Passed to |
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.
Numeric scalar. The one-tailed p-value for the slope coefficient.
get_break_points for the Davies test step that precedes this
slope check. ras_detect for the
full detection workflow.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.