如何遍历参数进行分析 [英] How to iterate through parameters to analyse
问题描述
有没有更好的方法来迭代给定数据集的一组参数?显然,我试图得到一个相关系数表:列是CI、CVP、平均 PAP、平均 SAP",行是ALAT、ASAT、GGT、Bili、LDH、FBG".对于每个组合,我想获得相关系数和显着性水平(p = ...).下面你会看到艰难的道路".但是有没有更优雅的方法,可能是一个可打印的表格?
Is there a better way to iterate through a set of parameters of a given dataset? Obviously, I try to get a table of correlation coefficients: columns are "CI, CVP, mean PAP, mean SAP", rows are "ALAT, ASAT, GGT, Bili, LDH, FBG". For each combination I´d like to get the correlation coefficient and the significance level (p=...). Below You see "the hard way". But is there a more elegant way, possibly with a printable table?
attach(Liver)
cor.test(CI, ALAT, method = "spearman")
cor.test(CI, ASAT, method = "spearman")
cor.test(CI, GGT, method = "spearman")
cor.test(CI, Bili, method = "spearman")
cor.test(CI, LDH, method = "spearman")
cor.test(CI, FBG, method = "spearman")
cor.test(CVP, ALAT, method = "spearman")
cor.test(CVP, ASAT, method = "spearman")
cor.test(CVP, GGT, method = "spearman")
cor.test(CVP, Bili, method = "spearman")
cor.test(CVP, LDH, method = "spearman")
cor.test(CVP, FBG, method = "spearman")
cor.test(meanPAP, ALAT, method = "spearman")
cor.test(meanPAP, ASAT, method = "spearman")
cor.test(meanPAP, GGT, method = "spearman")
cor.test(meanPAP, Bili, method = "spearman")
cor.test(meanPAP, LDH, method = "spearman")
cor.test(meanPAP, FBG, method = "spearman")
cor.test(meanSAP, ALAT, method = "spearman")
cor.test(meanSAP, ASAT, method = "spearman")
cor.test(meanSAP, GGT, method = "spearman")
cor.test(meanSAP, Bili, method = "spearman")
cor.test(meanSAP, LDH, method = "spearman")
cor.test(meanSAP, FBG, method = "spearman")
detach("Liver")
推荐答案
ltm
库中有一个函数rcor.test()
,可以制作相关系数表和p 值.例如使用的数据 iris
因为没有你的数据框.
There is a function rcor.test()
in library ltm
that makes table of correlation coefficients and p-values. For example used data iris
as do not have your data frame.
library(ltm)
rcor.test(iris[,1:4],method="spearman")
Sepal.Length Sepal.Width Petal.Length Petal.Width
Sepal.Length ***** -0.167 0.882 0.834
Sepal.Width 0.041 ***** -0.310 -0.289
Petal.Length <0.001 <0.001 ***** 0.938
Petal.Width <0.001 <0.001 <0.001 *****
upper diagonal part contains correlation coefficient estimates
lower diagonal part contains corresponding p-values
这篇关于如何遍历参数进行分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!