Browse code

improved getFDR and findHits behavior in dealing with NA F statistics

Nils Kurzawa authored on 26/03/2020 11:17:24
Showing1 changed files

... ...
@@ -36,7 +36,6 @@ getFDR <- function(df_out, df_null){
36 36
                         df_null) %>%
37 37
         mutate(nObsRound = round(nObs/10)*10) %>%
38 38
         group_by(nObsRound) %>%
39
-        filter(!is.na(F_statistic)) %>% 
40 39
         arrange(desc(F_statistic)) %>%
41 40
         mutate(max_rank = n(),
42 41
                rank = dense_rank(desc(F_statistic)),
... ...
@@ -47,7 +46,8 @@ getFDR <- function(df_out, df_null){
47 46
                null_cumsum = cumsum(is_decoy)) %>% 
48 47
         mutate(pi = (all_true-true_cumsum)/((all_null-null_cumsum)/B)) %>% 
49 48
         mutate(FDR = pi * (null_cumsum/B)/true_cumsum) %>% 
50
-        ungroup()
49
+        ungroup() %>% 
50
+        within(FDR[is.na(F_statistic)] <- NA)
51 51
     
52 52
     return(out_df)
53 53
 }
... ...
@@ -200,6 +200,7 @@ findHits <- function(fdr_df, alpha){
200 200
       df_fil <- NULL
201 201
   
202 202
   hits_df <- fdr_df %>% 
203
+    filter(!is.na(F_statistic)) %>% 
203 204
     group_by(nObsRound) %>% 
204 205
     mutate(min_rank_true = min(rank[dataset == "true"])) %>% 
205 206
     filter(rank >= min_rank_true) %>% 
... ...
@@ -213,4 +214,4 @@ findHits <- function(fdr_df, alpha){
213 214
                   detected_effectH1, nObsRound, pi, FDR)
214 215
   
215 216
   return(hits_df)
216
-}
217 217
\ No newline at end of file
218
+}