| partial_corr | R Documentation |
Computes the partial correlation between Y[i] and Y[j] adjusting for the
"intervenor" variables Y[i+1], ..., Y[j-1]. Under an antedependence model
of order p, partial correlations for |i-j| > p should be approximately zero.
partial_corr(y, test = FALSE, n_digits = 3)
y |
Numeric matrix with n_subjects rows and n_time columns. |
test |
Logical; if TRUE, returns significance flags based on approximate threshold 2/sqrt(n_eff) where n_eff = n_subjects - (lag - 1). Default FALSE. |
n_digits |
Integer; number of decimal places for rounding. Default 3. |
The intervenor-adjusted partial correlation between Y[i] and Y[j] (i < j) is
computed as the correlation between the residuals from regressing Y[i] and Y[j]
on the intervenor set 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.
A list with components:
correlation |
Matrix with correlations (upper triangle) and variances (diagonal) |
partial_correlation |
Matrix with partial correlations (lower triangle) and variances (diagonal) |
significant |
(If test=TRUE) Matrix flagging significant partial correlations (1 = significant) |
n_subjects |
Number of subjects |
n_time |
Number of time points |
Zimmerman, D. L. and Nunez-Anton, V. (2009). Antedependence Models for Longitudinal Data. CRC Press.
plot_prism for visual diagnostics
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.