![](/img/trans.png)
[英]FDR calculation using True positive, negative and False positive negative in R?
[英]False positive and false negative without loop in R
我有以下數據框(簡化示例)
y.true yhat
1 U E
2 E U
3 U E
4 E U
5 E U
6 U E
7 E U
8 E E
9 U U
10 E E
我需要計算假陰性( y.true==U,yhat==E
)和假陽性( y.true==E,yhat==U
)的數量,其中 E=0, U=1 在我的情況下。 當然,我可以糾正這種類型的 for 循環:
FP<-0
FN<-0
for (i in 1:dim(df.b)[1]) {
if (df.b[i,1]=='U' & df.b[i,2]=='E') {
FN<-FN+1
}
else if (df.b[i,1]=='E' & df.b[i,2]=='U') {
FP<-FP+1
}
}
但是:是否有更有效的方法來使用邏輯索引而不是循環來完成此任務?
如果df.b
是您的 data.frame,則根本不需要使用 for 循環。
FP <- sum(df.b$y.true == 'U' & df.b$yhat == 'E')
FN <- sum(df.b$y.true == 'E' & df.b$yhat == 'U')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.