Browse code

replaced function for computing p-values

Nils Kurzawa authored on 29/01/2020 09:21:15
Showing4 changed files

... ...
@@ -20,5 +20,5 @@ URL: http://bioconductor.org/packages/TPP2D
20 20
 RoxygenNote: 6.1.1
21 21
 Depends: R (>= 3.6.0), stats, utils, dplyr, methods
22 22
 Imports: ggplot2, tidyr, foreach, doParallel, openxlsx, stringr, 
23
-  RCurl, parallel, MASS, sfsmisc, BiocParallel
23
+  RCurl, parallel, MASS, BiocParallel
24 24
 Suggests: knitr, testthat
... ...
@@ -8,7 +8,6 @@ export(competeModels)
8 8
 export(computeFStatFromParams)
9 9
 export(computeFdr)
10 10
 export(computeFstat)
11
-export(computePvalFromKernelDensity)
12 11
 export(configWide2Long)
13 12
 export(filterOutContaminants)
14 13
 export(findHits)
... ...
@@ -42,7 +41,6 @@ importFrom(methods,new)
42 41
 importFrom(openxlsx,read.xlsx)
43 42
 importFrom(parallel,makeCluster)
44 43
 importFrom(parallel,stopCluster)
45
-importFrom(sfsmisc,integrate.xy)
46 44
 importFrom(stats,approx)
47 45
 importFrom(stats,coef)
48 46
 importFrom(stats,density)
... ...
@@ -114,66 +114,6 @@ computeFdr <- function(df_out, df_null){
114 114
     return(out_df)
115 115
 }
116 116
 
117
-#' Compute p-values for given F statistics based on true and
118
-#' null dataset using a kernel density estimation of the 
119
-#' bootstrapped null distribution
120
-#' 
121
-#' @param df_out data frame containing results from analysis by
122
-#' fitAndEvalDataset
123
-#' @param df_null data frame containing results from analysis by
124
-#' bootstrapNull
125
-#' 
126
-#' @return data frame annotating each protein with a FDR based on 
127
-#' it's F statistic and number of observations
128
-#' 
129
-#' @examples 
130
-#' data("simulated_cell_extract_df")
131
-#' temp_df <- simulated_cell_extract_df %>% 
132
-#'   filter(clustername %in% paste0("protein", 1:3)) %>% 
133
-#'   group_by(representative) %>% 
134
-#'   mutate(nObs = n()) %>% 
135
-#'   ungroup 
136
-#' example_out <- fitAndEvalDataset(temp_df)
137
-#' example_null <- bootstrapNull(temp_df, B = 2)
138
-#' computePvalFromKernelDensity(
139
-#'   example_out, 
140
-#'   example_null)
141
-#'  
142
-#' @export
143
-#'
144
-#' @import dplyr
145
-#' @importFrom stats density
146
-#' @importFrom stats p.adjust
147
-#' @importFrom sfsmisc integrate.xy
148
-computePvalFromKernelDensity <- function(df_out, df_null){
149
-    
150
-    dataset <- nObs <- nObsRound <- F_statistic <- 
151
-        representative <- clustername <- dataset  <- NULL
152
-    
153
-    tmp_df <- bind_rows(df_out %>% mutate(dataset = "true"),
154
-                        df_null) %>%
155
-        mutate(nObsRound = round(nObs/10)*10) 
156
-    
157
-    out_df <- bind_rows(lapply(unique(tmp_df$nObsRound), function(nobs){
158
-        nobs_df <- filter(tmp_df, nObsRound == nobs)
159
-        density_est <- density(filter(nobs_df, dataset != "true")$F_statistic, 
160
-                               n = 1e6)
161
-        full_integral <- integrate.xy(density_est$x, density_est$y)
162
-        nobs_df %>% filter(dataset == "true") %>% 
163
-            group_by(representative) %>% 
164
-            mutate(p_value = 1 - (
165
-                integrate.xy(density_est$x[which(density_est$x < F_statistic)],
166
-                             density_est$y[which(density_est$x < F_statistic)])/
167
-                    full_integral)) %>% 
168
-            ungroup
169
-    })) %>% 
170
-        ungroup %>% 
171
-        within(p_value[p_value == 0] <- .Machine$double.eps) %>% 
172
-        mutate(p_adj = p.adjust(p_value, method = "BH"))
173
-    
174
-    return(out_df)
175
-}
176
-
177 117
 #' Compute p-values for given F statistics based on true and
178 118
 #' null dataset 
179 119
 #' 
180 120
deleted file mode 100644
... ...
@@ -1,40 +0,0 @@
1
-% Generated by roxygen2: do not edit by hand
2
-% Please edit documentation in R/fdr_funcs.R
3
-\name{computePvalFromKernelDensity}
4
-\alias{computePvalFromKernelDensity}
5
-\title{Compute p-values for given F statistics based on true and
6
-null dataset using a kernel density estimation of the 
7
-bootstrapped null distribution}
8
-\usage{
9
-computePvalFromKernelDensity(df_out, df_null)
10
-}
11
-\arguments{
12
-\item{df_out}{data frame containing results from analysis by
13
-fitAndEvalDataset}
14
-
15
-\item{df_null}{data frame containing results from analysis by
16
-bootstrapNull}
17
-}
18
-\value{
19
-data frame annotating each protein with a FDR based on 
20
-it's F statistic and number of observations
21
-}
22
-\description{
23
-Compute p-values for given F statistics based on true and
24
-null dataset using a kernel density estimation of the 
25
-bootstrapped null distribution
26
-}
27
-\examples{
28
-data("simulated_cell_extract_df")
29
-temp_df <- simulated_cell_extract_df \%>\% 
30
-  filter(clustername \%in\% paste0("protein", 1:3)) \%>\% 
31
-  group_by(representative) \%>\% 
32
-  mutate(nObs = n()) \%>\% 
33
-  ungroup 
34
-example_out <- fitAndEvalDataset(temp_df)
35
-example_null <- bootstrapNull(temp_df, B = 2)
36
-computePvalFromKernelDensity(
37
-  example_out, 
38
-  example_null)
39
- 
40
-}