Browse code

bug fix: moderated F-statistic uses now also moderated degrees of freedom df2

Nils Kurzawa authored on 20/06/2020 15:06:20
Showing2 changed files

... ...
@@ -1,7 +1,7 @@
1 1
 Package: TPP2D
2 2
 Title: Detection of ligand-protein interactions from 2D thermal 
3 3
     profiles (DLPTP)
4
-Version: 1.4.0
4
+Version: 1.4.1
5 5
 Authors@R: c(
6 6
     person("Nils", "Kurzawa", email = "nils.kurzawa@embl.de", 
7 7
         role = c("aut", "cre")),
... ...
@@ -61,28 +61,36 @@ getFDR <- function(df_out, df_null, squeezeDenominator = TRUE){
61 61
 
62 62
 #' @importFrom limma squeezeVar 
63 63
 .shrinkFstat <- function(inDf, trueOrNull = "true"){
64
-    rssH1 <- df2 <- rssH0 <- rssH1Squeezed <- df1 <- 
65
-        nObs <- nObsRound <- dataset <- NULL
66
-    if(trueOrNull == "true"){
67
-        outDf <- inDf %>% 
68
-            mutate(nObsRound = round(nObs/10)*10) %>% 
69
-            group_by(nObsRound) %>% 
70
-            mutate(rssH1Squeezed = limma::squeezeVar(
71
-                rssH1, df = df2)$var.post) %>% 
72
-            ungroup %>% 
73
-            mutate(F_statistic = (rssH0 - rssH1)/
74
-                       (rssH1Squeezed) * df2/df1)
75
-    }else if(trueOrNull == "null"){
76
-        outDf <- inDf %>% 
77
-            mutate(nObsRound = round(nObs/10)*10) %>% 
78
-            group_by(dataset, nObsRound) %>% 
79
-            mutate(rssH1Squeezed = limma::squeezeVar(
80
-                rssH1, df = df2)$var.post) %>% 
81
-            ungroup %>% 
82
-            mutate(F_statistic = (rssH0 - rssH1)/
83
-                       (rssH1Squeezed) * df2/df1)
84
-    }
85
-    return(outDf)
64
+  rssH1 <- df2 <- rssH0 <- rssH1Squeezed <- df1 <- 
65
+    df0 <- nObs <- nObsRound <- dataset <- NULL
66
+  if(trueOrNull == "true"){
67
+    outDf <- inDf %>% 
68
+      mutate(nObsRound = round(nObs/10)*10) %>% 
69
+      group_by(nObsRound) %>% 
70
+      mutate(
71
+        rssH1Squeezed = limma::squeezeVar(
72
+          rssH1, df = df2)$var.post,
73
+        df0 = limma::squeezeVar(
74
+          rssH1, df = df2)$df.prior) %>% 
75
+      within(df0[is.infinite(df0)] <- 0) %>% 
76
+      ungroup %>% 
77
+      mutate(F_statistic = (rssH0 - rssH1)/
78
+               (rssH1Squeezed) * (df0 + df2)/df1)
79
+  }else if(trueOrNull == "null"){
80
+    outDf <- inDf %>% 
81
+      mutate(nObsRound = round(nObs/10)*10) %>% 
82
+      group_by(dataset, nObsRound) %>% 
83
+      mutate(
84
+        rssH1Squeezed = limma::squeezeVar(
85
+          rssH1, df = df2)$var.post,
86
+        df0 = limma::squeezeVar(
87
+          rssH1, df = df2)$df.prior) %>% 
88
+      within(df0[is.infinite(df0)] <- 0) %>% 
89
+      ungroup %>% 
90
+      mutate(F_statistic = (rssH0 - rssH1)/
91
+               (rssH1Squeezed) * (df0 + df2)/df1)
92
+  }
93
+  return(outDf)
86 94
 }
87 95
 #' Compute FDR for given F statistics based on true and
88 96
 #' null dataset (old function)