如何 select r 中列之间匹配值的最高百分比?
How to select top percent of matching values between columns in r?
我有一个基因数据集,为此我比较了几个预测基因是否可能导致疾病的模型。我正在寻找 select 基因,这些基因出现在我所研究的所有机器学习方法中最有可能致病基因的前 25% 中。因此,获得所有模型都同意的可能疾病基因的最高百分比。
我的数据是这样的(虽然我实际上有更多的分数列):
Gene Score1 Score2
BRCA2 0.7 0.7
SLC25A20 0.2644568 0.486816
GLS 0.4560175 0.6631010
IKZF4 0.7468294 0.2189585
NRIP3 0.8446390 0.4570968
SENP1 0.5372014 0.1724868
SLC27A6 0.6321821 0.1218227
SRFBP1 0.2293986 0.2688244
OBFC1 0.2279012 0.2187441
STEAP2 0.2239941 0.2001475
所以在这个例子中,BRCA2
是唯一一个两个模型得分一致的基因,在这个例子中得分高,在前 25% 中,因此应该被剔除。
我不确定该怎么做,我一直在尝试使用 match()
和 if 语句,但还没有取得进展 - 任何帮助将不胜感激。
#Input data:
structure(list(Gene = c("BRCA2", "SLC25A20", "GLS", "IKZF4",
"NRIP3", "SENP1", "SLC27A6", "SRFBP1", "OBFC1", "STEAP2"), Score1 = c(0.7,
0.2644568, 0.4560175, 0.7468294, 0.844639, 0.5372014, 0.6321821,
0.2293986, 0.2279012, 0.2239941), Score2 = c(0.7, 0.486816, 0.663101,
0.2189585, 0.4570968, 0.1724868, 0.1218227, 0.2688244, 0.2187441,
0.2001475)), row.names = c(NA, -10L), class = c("data.table",
"data.frame"))
一个dplyr
选项可以是:
df %>%
filter(Reduce(`&`, across(starts_with("Score"), ~ cume_dist(.) >= 0.75)))
Gene Score1 Score2
1 BRCA2 0.7 0.7
这里有一个data.table
方法
#identify columns with score values
score_cols <- grep( "^Score", names(DT), value = TRUE )
#filter based on colwise quantile
DT[ rowSums( sapply( DT[, .SD, .SDcols = score_cols],
function(x) x > quantile(x, 0.75 ) ) ) >= length( score_cols), ]
# Gene Score1 Score2
# 1: BRCA2 0.7 0.7
我有一个基因数据集,为此我比较了几个预测基因是否可能导致疾病的模型。我正在寻找 select 基因,这些基因出现在我所研究的所有机器学习方法中最有可能致病基因的前 25% 中。因此,获得所有模型都同意的可能疾病基因的最高百分比。
我的数据是这样的(虽然我实际上有更多的分数列):
Gene Score1 Score2
BRCA2 0.7 0.7
SLC25A20 0.2644568 0.486816
GLS 0.4560175 0.6631010
IKZF4 0.7468294 0.2189585
NRIP3 0.8446390 0.4570968
SENP1 0.5372014 0.1724868
SLC27A6 0.6321821 0.1218227
SRFBP1 0.2293986 0.2688244
OBFC1 0.2279012 0.2187441
STEAP2 0.2239941 0.2001475
所以在这个例子中,BRCA2
是唯一一个两个模型得分一致的基因,在这个例子中得分高,在前 25% 中,因此应该被剔除。
我不确定该怎么做,我一直在尝试使用 match()
和 if 语句,但还没有取得进展 - 任何帮助将不胜感激。
#Input data:
structure(list(Gene = c("BRCA2", "SLC25A20", "GLS", "IKZF4",
"NRIP3", "SENP1", "SLC27A6", "SRFBP1", "OBFC1", "STEAP2"), Score1 = c(0.7,
0.2644568, 0.4560175, 0.7468294, 0.844639, 0.5372014, 0.6321821,
0.2293986, 0.2279012, 0.2239941), Score2 = c(0.7, 0.486816, 0.663101,
0.2189585, 0.4570968, 0.1724868, 0.1218227, 0.2688244, 0.2187441,
0.2001475)), row.names = c(NA, -10L), class = c("data.table",
"data.frame"))
一个dplyr
选项可以是:
df %>%
filter(Reduce(`&`, across(starts_with("Score"), ~ cume_dist(.) >= 0.75)))
Gene Score1 Score2
1 BRCA2 0.7 0.7
这里有一个data.table
方法
#identify columns with score values
score_cols <- grep( "^Score", names(DT), value = TRUE )
#filter based on colwise quantile
DT[ rowSums( sapply( DT[, .SD, .SDcols = score_cols],
function(x) x > quantile(x, 0.75 ) ) ) >= length( score_cols), ]
# Gene Score1 Score2
# 1: BRCA2 0.7 0.7