View source: R/Interaction_test.R
| test.interaction | R Documentation |
Fits a linear model of the form y ~ x * by to evaluate whether the
association between a continuous predictor and an outcome differs across
groups. Optionally produces a publication-ready visualization of
group-specific regression lines.
test.interaction(
x,
y,
by,
title = NULL,
xlab = NULL,
ylab = NULL,
plot = TRUE,
style = c("clean", "CI", "facet"),
conf.level = 0.95,
verbose = TRUE,
help = FALSE
)
## S3 method for class 'test.interaction'
print(x, ...)
x |
Numeric vector representing the continuous predictor. |
y |
Numeric vector representing the continuous outcome. |
by |
Grouping variable defining the interaction. Must be coercible to a factor with at least two levels. |
title |
Optional title title for the plot. |
xlab |
Optional x-axis label. |
ylab |
Optional y-axis label. |
plot |
Logical. Should a plot be generated? |
style |
Plot style. One of |
conf.level |
Confidence level for the interaction interval (default: 0.95). |
verbose |
Logical. If TRUE, prints detailed messages. Default: TRUE. |
help |
Logical. If TRUE, shows a detailed explanation of the function. Default: FALSE. |
... |
Additional arguments passed to other print methods (currently ignored) |
The interaction coefficient (\beta) represents the difference in
regression slopes between groups, conditional on the reference level
of by. The sign and magnitude of this coefficient depend on the
chosen reference group.
Confidence intervals are emphasized as the primary inferential quantity.
An object of class "test.interaction" containing:
model: the fitted linear model,
interaction: estimated interaction effects with confidence intervals,
plot: a ggplot object (if plot = TRUE).
# Simple example: different trends between groups
set.seed(123)
n <- 60
marker <- rnorm(n, 10, 2)
group <- rep(c("Control", "Treatment"), each = n/2)
# Same intercept, different slopes
response <- 2 +
ifelse(group == "Control", 0.5, 1.2) * marker +
rnorm(n, 0, 1)
test.interaction(marker, response, group)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.