% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/diagnostics.R
\name{partial_corr}
\alias{partial_corr}
\title{Compute intervenor-adjusted partial correlation matrix}
\usage{
partial_corr(y, test = FALSE, n_digits = 3)
}
\arguments{
\item{y}{Numeric matrix with n_subjects rows and n_time columns.}

\item{test}{Logical; if TRUE, returns significance flags based on approximate
threshold 2/sqrt(n_eff) where n_eff = n_subjects - (lag - 1). Default FALSE.}

\item{n_digits}{Integer; number of decimal places for rounding. Default 3.}
}
\value{
A list with components:
\item{correlation}{Matrix with correlations (upper triangle) and variances (diagonal)}
\item{partial_correlation}{Matrix with partial correlations (lower triangle) and variances (diagonal)}
\item{significant}{(If test=TRUE) Matrix flagging significant partial correlations (1 = significant)}
\item{n_subjects}{Number of subjects}
\item{n_time}{Number of time points}
}
\description{
Computes the partial correlation between \code{Y[i]} and \code{Y[j]} adjusting for the
"intervenor" variables \verb{Y[i+1], ..., Y[j-1]}. Under an antedependence model
of order p, partial correlations for |i-j| > p should be approximately zero.
}
\details{
The intervenor-adjusted partial correlation between \code{Y[i]} and \code{Y[j]} (i < j) is
computed as the correlation between the residuals from regressing \code{Y[i]} and \code{Y[j]}
on the intervenor set \verb{Y[i+1], ..., Y[j-1]}.

For adjacent time points (|i-j| = 1), the partial correlation equals the
ordinary correlation since there are no intervenors.

The diagonal of both returned matrices contains variances (not correlations).
This keeps scale information available alongside correlation structure.

The significance test uses an approximate threshold of 2/sqrt(n_eff), which
corresponds roughly to a 95\% confidence bound under normality. This is a
rough screening tool, not a formal hypothesis test.
}
\examples{
\donttest{
data("bolus_inad")
pc <- partial_corr(bolus_inad$y, test = TRUE)

# View partial correlations (lower triangle)
pc$partial_correlation

# Extract variances from the diagonal
variances <- diag(pc$partial_correlation)

# Check which are "significant" (rough screen for AD order)
pc$significant
}

}
\references{
Zimmerman, D. L. and Nunez-Anton, V. (2009). Antedependence Models for
Longitudinal Data. CRC Press.
}
\seealso{
\code{\link{plot_prism}} for visual diagnostics
}
