diff --git a/R/tidyMS_R6_Modelling.R b/R/tidyMS_R6_Modelling.R index 0ad4a6ba..446ef680 100644 --- a/R/tidyMS_R6_Modelling.R +++ b/R/tidyMS_R6_Modelling.R @@ -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)) #' @@ -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) diff --git a/R/tidyMS_missigness_V2.R b/R/tidyMS_missigness_V2.R index b25fd00c..4cdb36f5 100644 --- a/R/tidyMS_missigness_V2.R +++ b/R/tidyMS_missigness_V2.R @@ -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, @@ -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() @@ -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() @@ -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() diff --git a/man/MissingHelpers.Rd b/man/MissingHelpers.Rd index aad5adb7..253751b3 100644 --- a/man/MissingHelpers.Rd +++ b/man/MissingHelpers.Rd @@ -44,19 +44,12 @@ mh$get_contrast_estimates(Contrasts) \item{\code{prob}}{quantile of groups with one observed value to estimate LOD} -\item{\code{keep}}{stats which might be time consuming to compute} +\item{\code{stats}}{data.frame with group statistics} \item{\code{weighted}}{should we weight the LOD} } \if{html}{\out{}} } -\section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{keep}}{stats which might be time consuming to compute} -} -\if{html}{\out{
}} -} \section{Methods}{ \subsection{Public methods}{ \itemize{ @@ -98,24 +91,34 @@ initialize \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-MissingHelpers-get_stats}{}}} \subsection{Method \code{get_stats()}}{ +get data.frame with statistics \subsection{Usage}{ \if{html}{\out{
}}\preformatted{MissingHelpers$get_stats()}\if{html}{\out{
}} } +\subsection{Returns}{ +data.frame +} } \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-MissingHelpers-get_LOD}{}}} \subsection{Method \code{get_LOD()}}{ +determine limit of detection +computes quantile of abundances in groups with a single observation \subsection{Usage}{ \if{html}{\out{
}}\preformatted{MissingHelpers$get_LOD()}\if{html}{\out{
}} } +\subsection{Returns}{ +integer LOD +} } \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-MissingHelpers-impute_weighted_lod}{}}} \subsection{Method \code{impute_weighted_lod()}}{ +compute group averages using weighted lod \subsection{Usage}{ \if{html}{\out{
}}\preformatted{MissingHelpers$impute_weighted_lod()}\if{html}{\out{
}} } @@ -125,6 +128,7 @@ initialize \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-MissingHelpers-impute_lod}{}}} \subsection{Method \code{impute_lod()}}{ +if group average absent substitute with LOD \subsection{Usage}{ \if{html}{\out{
}}\preformatted{MissingHelpers$impute_lod()}\if{html}{\out{
}} } @@ -134,10 +138,18 @@ initialize \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-MissingHelpers-get_poolvar}{}}} \subsection{Method \code{get_poolvar()}}{ +compute pooled var per protein \subsection{Usage}{ \if{html}{\out{
}}\preformatted{MissingHelpers$get_poolvar(prob = 0.75)}\if{html}{\out{
}} } +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{prob}}{prob of sd from proteins where it can be computed} +} +\if{html}{\out{
}} +} } \if{html}{\out{
}} \if{html}{\out{}} @@ -160,10 +172,22 @@ get contrast estimates \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-MissingHelpers-get_contrasts}{}}} \subsection{Method \code{get_contrasts()}}{ +compute contrasts \subsection{Usage}{ \if{html}{\out{
}}\preformatted{MissingHelpers$get_contrasts(Contrasts, confint = 0.95, all = FALSE)}\if{html}{\out{
}} } +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{Contrasts}}{vector with contrasts} + +\item{\code{confint}}{compute confint} + +\item{\code{all}}{return all columns, default FALSE} +} +\if{html}{\out{
}} +} } \if{html}{\out{
}} \if{html}{\out{}} diff --git a/man/build_models.Rd b/man/build_models.Rd index b5e539d2..5a061112 100644 --- a/man/build_models.Rd +++ b/man/build_models.Rd @@ -13,6 +13,11 @@ build_models( } \description{ build dataframe with models for testing +} +\examples{ +mod <- build_models(model = " ~ Treatment * Background", weight_missing = 1) +stopifnot(dim(mod$modelDF) == c(10,9)) + } \seealso{ Other modelling: diff --git a/man/make_model.Rd b/man/make_model.Rd index 133c8e5f..feff53c8 100644 --- a/man/make_model.Rd +++ b/man/make_model.Rd @@ -9,6 +9,9 @@ make_model(model = c("factors", "interaction")) \description{ make interaction model for examples } +\examples{ +m <- make_model() +} \seealso{ Other modelling: \code{\link{Contrasts}},