簡體   English   中英

和一起使用

[英]using by and mapply together

嗨,我正在嘗試使ICC的價值取決於一系列因素水平。 例如:

usr1<-data.frame(a1=1:5,a2=11:15,a3=21:25,bin=factor(c("a","b","a","a","b")))
usr2<-data.frame(a1=2:6,a2=12:16,a3=32:36)

我想要a1,a2和a3的ICC,其中bin是a和b。 在考慮因素之前,我使用了mapply

mapply(function(x,y){z<-data.frame(x,y);icc(z,model="t",type="a")},usr1[,-4],usr2)

我無法弄清楚如何針對每個級別的因素用by進行包裝。

mapply(function(x,y){z<-data.frame(x,y);icc(z,model="t",type="a")},usr1[c(1,3,4),-4],usr2[c(1,3,4),])

應該給您“ a”級的正確答案,並且

mapply(function(x,y){z<-data.frame(x,y);icc(z,model="t",type="a")},usr1[c(2,5),-4],usr2[c(2,5),])

應該給您“ b”級的正確答案。

這是我的問題的非常簡化的版本,其中我必須為20個級別計算200多個ICC。 我事先不知道哪些行具有哪些因素,除了我在data.frame中擁有它的事實。
謝謝

編輯

預期的輸出將是...。

usr1$bin:a
           a1          a2          a3          
subjects   3           3           3           
raters     2           2           2           
model      "twoway"    "twoway"    "twoway"    
type       "agreement" "agreement" "agreement" 
unit       "single"    "single"    "single"    
icc.name   "ICC(A,1)"  "ICC(A,1)"  "ICC(A,1)"  
value      0.8235294   0.8235294   0.03713528  
r0         0           0           0           
Fvalue     -5.2542e+15 -5.2542e+15 1.094625e+14
df1        2           2           2           
df2        1           1           1           
p.value    1           1           6.758531e-08
conf.level 0.95        0.95        0.95        
lbound     0.005803109 0.005803109 4.823719e-05
ubound     0.9944658   0.9944658   0.5976005   
------------------------------------------------------
usr1$bin:b
           a1          a2          a3          
subjects   2           2           2           
raters     2           2           2           
model      "twoway"    "twoway"    "twoway"    
type       "agreement" "agreement" "agreement" 
unit       "single"    "single"    "single"    
icc.name   "ICC(A,1)"  "ICC(A,1)"  "ICC(A,1)"  
value      0.9         0.9         0.06923077  
r0         0           0           0           
Fvalue     Inf         Inf         Inf         
df1        1           1           1           
df2        1           1           1           
p.value    0           0           0           
conf.level 0.95        0.95        0.95        
lbound     0.01370303  0.01370303  0.0001148084
ubound     0.9998285   0.9998285   0.9796676

您可以為不同的bin包裝lapply

res<-lapply(unique(usr1$bin),function(x){  
  mapply(function(x,y){z<-data.frame(x,y);icc(z,model="t",type="a")},usr1[usr1$bin==x,-4],usr2[usr1$bin==x,])
})
names(res)<-unique(usr1$bin)

暫無
暫無

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

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