% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Interaction_test.R
\name{test.interaction}
\alias{test.interaction}
\alias{print.test.interaction}
\title{Test for interaction between a continuous predictor and a grouping variable}
\usage{
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
)

\method{print}{test.interaction}(x, ...)
}
\arguments{
\item{x}{Numeric vector representing the continuous predictor.}

\item{y}{Numeric vector representing the continuous outcome.}

\item{by}{Grouping variable defining the interaction. Must be coercible
to a factor with at least two levels.}

\item{title}{Optional title title for the plot.}

\item{xlab}{Optional x-axis label.}

\item{ylab}{Optional y-axis label.}

\item{plot}{Logical. Should a plot be generated?}

\item{style}{Plot style. One of \code{"clean"}, \code{"CI"} or \code{"facet"}.}

\item{conf.level}{Confidence level for the interaction interval
(default: 0.95).}

\item{verbose}{Logical. If TRUE, prints detailed messages. Default: TRUE.}

\item{help}{Logical. If TRUE, shows a detailed explanation of the function.
Default: FALSE.}

\item{...}{Additional arguments passed to other print methods (currently ignored)}
}
\value{
An object of class \code{"test.interaction"} containing:
\itemize{
\item \code{model}: the fitted linear model,
\item \code{interaction}: estimated interaction effects with confidence intervals,
\item \code{plot}: a \code{ggplot} object (if \code{plot = TRUE}).
}
}
\description{
Fits a linear model of the form \code{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.
}
\details{
The interaction coefficient (\eqn{\beta}) represents the difference in
regression slopes between groups, conditional on the reference level
of \code{by}. The sign and magnitude of this coefficient depend on the
chosen reference group.

Confidence intervals are emphasized as the primary inferential quantity.
}
\examples{

# 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)

}
