【发布时间】:2025-11-30 18:20:04
【问题描述】:
我有两个长度相同的对称矩阵(一个包含相关系数,另一个包含 p 值)。
我正在尝试制作一个矩阵,使得 upper.tri 包含相关系数,而 lower.tri 包含相关的 p 值。
【问题讨论】:
我有两个长度相同的对称矩阵(一个包含相关系数,另一个包含 p 值)。
我正在尝试制作一个矩阵,使得 upper.tri 包含相关系数,而 lower.tri 包含相关的 p 值。
【问题讨论】:
假设您的矩阵是 correl 和 pval
# create a new matrix that is the pvalues
new <- pval
# not sure what you want the diagonal to be, lets make it NA
diag(new) <- NA
# replace the upper triangle of this new matrix with the
# upper triangle of the correlation matrix
new[upper.tri(new)] <- correl[upper.tri(correl)]
【讨论】:
upper.tri 只返回一堆逻辑 TRUE/FALSEes,上三角为真。试试upper.tri(matrix(1:9,ncol=3))