在R中进行偏相关分析

利用R语言进行偏相关分析

这里推荐两个R包进行该分析:ggm和ppcor
但ggm只能提供偏相关系数,无法提供 p 值;ppcor能提供相关系数和p值,并能选择相关系数计算方法。

  • ggm使用方法
    pcor(u, S),
    u, a vector of integers of length > 1. The first two integers are the indices of variables the correlation of which must be computed. The rest of the vector is the conditioning set.
    S, a symmetric positive definite matrix, a sample covariance matrix.
    即u为数量矩阵,其前两个变量为所求偏相关性的变量,剩余变量为控制变量,可以为一个或多个。
    例子:data(marks)
    The correlation between vectors and algebra given analysis and statistics
    pcor(c(“vectors”, “algebra”, “analysis”, “statistics”), var(marks))
    本例子中,所求为vectors和algebra偏相关性,其他两个是控制变量。var(marks)为“a sample covariance matrix”
  • ppcor
    pcor.test(x = marks[,1], y = marks[,2], z = marks[,3:4], method = ‘spearman’)

你可能感兴趣的:(数据分析,偏相关,数据分析)