算法手册/ 进阶方法/ 偏相关

偏相关

计算公式

符号

符号含义
x、y两个分析变量
Z控制变量矩阵(n×k)
Z̃在 Z 前加一列常数项(n×(k+1))
ex、ey对控制变量回归后的残差
rxy·Z控制 Z 后 x 与 y 的偏相关系数
k控制变量个数
df检验自由度 n−k−2
t偏相关显著性检验统计量

核心公式

公式 (1.1):对控制变量取残差
\[ \tilde Z=\left(\mathbf{1},Z\right),\qquad e_x=x-\tilde Z\left(\tilde Z'\tilde Z\right)^{-1}\tilde Z'x,\qquad e_y=y-\tilde Z\left(\tilde Z'\tilde Z\right)^{-1}\tilde Z'y \]
公式 (1.2):残差相关(即偏相关)
\[ r_{xy\cdot Z}=\frac{e_x'e_y}{\sqrt{e_x'e_x}\sqrt{e_y'e_y}} \]
公式 (1.3):显著性检验
\[ t=r_{xy\cdot Z}\sqrt{\frac{df}{1-r_{xy\cdot Z}^{2}}},\qquad df=n-k-2 \]
公式 (1.4):Fisher z 置信区间
\[ z=\operatorname{arctanh}\left(r_{xy\cdot Z}\right),\qquad \mathrm{CI}=\tanh\left(z\pm z_{1-\alpha/2}\sqrt{\frac{1}{n-k-3}}\right) \]

参考文献

  1. Fisher, R. A. (1924). The distribution of the partial correlation coefficient. Metron, 3, 329–332.
  2. Kim, S. (2015). ppcor: An R package for a fast calculation to semi-partial correlation coefficients. Communications for Statistical Applications and Methods, 22(6), 665–674.
  3. Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied Multiple Regression/Correlation Analysis for the Behavioral Sciences (3rd ed.). Lawrence Erlbaum Associates.

算法参数

本方法没有需要额外选择的算法参数:变量的选择属于分析设置,全部计算按上式的定义直接完成。

验证报告

数据与 R 包

样本与变量 N = 100;X1、X2、X3 为分析变量,C1、C2 为控制变量
R 包 ppcor 1.1

提示词

控制 C1、C2,计算 X1、X2、X3 两两之间的偏相关系数与 p 值。

R 代码

library(ppcor)
d <- read.csv("partial_correlation.csv")
z <- d[, c("C1", "C2")]
r12 <- pcor.test(d$X1, d$X2, z)
r13 <- pcor.test(d$X1, d$X3, z)
r23 <- pcor.test(d$X2, d$X3, z)
cat(sprintf("r(X1,X2|C) = %.15f  p = %.15f\n", r12$estimate, r12$p.value))
cat(sprintf("r(X1,X3|C) = %.15f  p = %.15f\n", r13$estimate, r13$p.value))
cat(sprintf("r(X2,X3|C) = %.15f  p = %.15f\n", r23$estimate, r23$p.value))
cat("n =", r12$n, " gp =", r12$gp, "\n")

对比结果

指标SPSSAUR差值
r(X1, X2 | C1, C2)0.14330053820.14330053824.46e−11
r(X1, X3 | C1, C2)0.19592122860.19592122864.93e−11
r(X2, X3 | C1, C2)0.14688910530.14688910537.5e−14
p(X1, X2 | C1, C2)1.592264e−11.592264e−11.02e−10
p(X1, X3 | C1, C2)5.318475e−25.318475e−25.44e−11
p(X2, X3 | C1, C2)1.489325e−11.489325e−11.06e−10
零阶相关 r(X1, X2)0.58165729830.58165729831.91e−11

结论:三个偏相关系数与三个 p 值均与 R 的 ppcor 包一致(最大差 <1e−9)。两边都把分析变量对 C1、C2 同时做最小二乘回归取残差,再算残差的 Pearson 相关;检验自由度都是 n−k−2 = 96。

操作手册 问题反馈

引用SPSSAU. 偏相关:计算公式与参数[EB/OL]. SPSSAU算法手册, 2026-11-20. https://www.spssau.com/algorithm/advanced/partial_correlation.html.