簡體   English   中英

R:跨兩個數據幀中的多列計算ICC

[英]R: calculating ICC across multiple columns in two dataframes

我正在計算 2 個讀者的 301 個變量的 ICC。 結果保存在兩個文件中,每個文件有 301 列。 file1的第一列(reader1$Var1)對應file2的第一列(reader2$Var302)。 我可以手動執行 ICC(見下文),但我需要幫助來使用應用或循環來自動化此過程。 謝謝你。

library(irr)
irr::icc()
a= data.frame(reader1$Var1)
b= data.frame(reader2$Var302)
X= data.frame (a,b)
function.ICC <- function (X) {irr::icc(X, model =c("oneway"), type = c("consistency"), unit =("single"), r0 = 0, conf.level = 0.95)}
Results <- function.ICC(X)
Results[7]

lapplydo.call組合lapply您的需求(盡管有很多選擇)。 您沒有提供數據樣本,因此我假設您首先對 2 個數據幀進行cbind一個cbind一個的cbind ,以便在這個玩具示例中

> X = data.frame(cbind(1:10, 11:20, 21:30, 21:30))
> X
   X1 X2 X3 X4
1   1 11 21 21
2   2 12 22 22
3   3 13 23 23
4   4 14 24 24
5   5 15 25 25
6   6 16 26 26
7   7 17 27 27
8   8 18 28 28
9   9 19 29 29
10 10 20 30 30

您想運行 X1 與 X3 和 X2 與 X4 的icc 它類似於以下內容,依賴於您定義的function.ICC

> do.call(cbind, lapply(1:2, function(i) function.ICC(X[,c(i, i+2)])))
           [,1]          [,2]         
subjects   10            10           
raters     2             2            
model      "oneway"      "oneway"     
type       "consistency" "consistency"
unit       "single"      "single"     
icc.name   "ICC(1)"      "ICC(1)"     
value      -0.8320611    -0.4634146   
r0         0             0            
Fvalue     0.09166667    0.3666667    
df1        9             9            
df2        10            10           
p.value    0.9993158     0.926668     
conf.level 0.95          0.95         
lbound     -0.9526347    -0.8231069   
ubound     -0.4669701    0.1848105  

因此,對於具有 301 列的 cbind'ed 數據框,類似於此的內容應該可以工作:

do.call(cbind, lapply(1:301, function(i) function.ICC(X[,c(i, i+301)])))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM