Skip to content

Commit

Permalink
update communication
Browse files Browse the repository at this point in the history
  • Loading branch information
wolski committed May 13, 2024
1 parent 8f70a98 commit d1f365b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 13 deletions.
4 changes: 2 additions & 2 deletions R/tidyMS_R6_Modelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @family modelling
#' @export
#' @keywords internal
#' @example
#' @examples
#' mod <- build_models(model = " ~ Treatment * Background", weight_missing = 1)
#' stopifnot(dim(mod$modelDF) == c(10,9))
#'
Expand All @@ -26,7 +26,7 @@ build_models <- function(model = c("factors", "interaction"), Nprot = 10, with_m
#' @family modelling
#' @export
#' @keywords internal
#' @example path.R
#' @examples
#' m <- make_model()
make_model <- function(model = c("factors", "interaction")){
mod <- build_models(model = model, Nprot = 1, with_missing = FALSE)
Expand Down
26 changes: 23 additions & 3 deletions R/tidyMS_missigness_V2.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ MissingHelpers <- R6::R6Class(
config = NULL,
#' @field prob quantile of groups with one observed value to estimate LOD
prob = 0.5,
#' @field keep stats which might be time consuming to compute
#' @field stats data.frame with group statistics
stats = NULL,
#' @field weighted should we weight the LOD
weighted = TRUE,
Expand All @@ -54,29 +54,45 @@ MissingHelpers <- R6::R6Class(
self$prob = prob
self$weighted = weighted
},
#' @description
#' get data.frame with statistics
#' @return data.frame
get_stats = function(){
if (is.null(self$stats)) {
self$stats = prolfqua::summarize_stats_factors(self$data, self$config)
}
return(self$stats)
},
#' @description
#' determine limit of detection
#' computes quantile of abundances in groups with a single observation
#' @return integer LOD
get_LOD = function(){
LOD <- self$get_stats() |> dplyr::filter(nrMeasured == 1) |>
dplyr::summarize(LOD = quantile(meanAbundance, probs = self$prob ,na.rm = TRUE)) |>
pull()
return(LOD)
},
#' @description
#' compute group averages using weighted lod
#'
impute_weighted_lod = function(){
toimp <- self$get_stats()
toimp$meanAbundanceZero <- ifelse(is.na(toimp$meanAbundance), 0, toimp$meanAbundance)
impDat <- toimp |> mutate(meanAbundanceImp = (.data$nrMeasured * .data$meanAbundanceZero + .data$nrNAs * self$get_LOD()) / .data$nrReplicates )
return(impDat)
},
#' @description
#' if group average absent substitute with LOD
#'
impute_lod = function(){
toimp <- self$get_stats()
toimp$meanAbundanceImp <- ifelse(is.na(toimp$meanAbundance), self$get_LOD(), toimp$meanAbundance)
return(toimp)
},
#' @description
#' compute pooled var per protein
#' @param prob prob of sd from proteins where it can be computed
get_poolvar = function(prob = 0.75) {
if (self$weighted) {
impDat <- self$impute_weighted_lod()
Expand Down Expand Up @@ -105,7 +121,7 @@ MissingHelpers <- R6::R6Class(
#' get contrast estimates
#' @param Contrasts named array with contrasts
get_contrast_estimates = function(
Contrasts
Contrasts
){
if (self$weighted) {
lt <- self$impute_weighted_lod()
Expand Down Expand Up @@ -146,7 +162,11 @@ MissingHelpers <- R6::R6Class(

return(imputed2)
},

#' @description
#' compute contrasts
#' @param Contrasts vector with contrasts
#' @param confint compute confint
#' @param all return all columns, default FALSE
get_contrasts = function(Contrasts, confint = 0.95, all = FALSE) {
imputed <- self$get_contrast_estimates(Contrasts = Contrasts)
pooled <- self$get_poolvar()
Expand Down
40 changes: 32 additions & 8 deletions man/MissingHelpers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/build_models.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/make_model.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d1f365b

Please sign in to comment.