Skip to content

Commit d92f930

Browse files
authored
Merge pull request #185 from MangiolaLaboratory/improve-documentation-sccomp_proportional_fold_change
improve the documentation of sccomp_proportional_fold_change
2 parents 7f683a9 + d4929f4 commit d92f930

File tree

2 files changed

+96
-33
lines changed

2 files changed

+96
-33
lines changed

R/methods.R

+49-16
Original file line numberDiff line numberDiff line change
@@ -2068,26 +2068,59 @@ clear_stan_model_cache <- function(cache_dir = sccomp_stan_models_cache_dir) {
20682068
}
20692069
}
20702070

2071-
#' Calculate Proportional Fold Change for sccomp Data
2071+
#' Calculate Proportional Fold Change from sccomp Estimated Effects
20722072
#'
2073-
#' This function calculates the proportional fold change for single-cell composition data
2074-
#' from sccomp analysis, comparing two conditions.
2075-
#'
2076-
#' Note! This statistic is just descriptive and should not be used to define significance. Use sccomp_test() for that.
2077-
#' This statistics is just meant to help interpretation. While fold increase in proportion is easier to understand than
2078-
#' fold change in logit space, the first is not linear (the same change for rare cell types does not necessarily have the same weight
2079-
#' that for abundant cell types), while the latter is linear, and used to infer probabilities.
2073+
#' @description
2074+
#' This function calculates the proportional fold change between two conditions using the estimated effects from a sccomp model.
2075+
#' The fold changes are derived from the model's posterior predictions rather than raw counts, providing a more robust estimate
2076+
#' that accounts for the model's uncertainty and covariate effects.
20802077
#'
2078+
#' Note! This statistic is descriptive and should not be used to define significance - use sccomp_test() for that.
2079+
#' While fold changes in proportions are easier to interpret than changes in logit space, they are not linear
2080+
#' (the same proportional change has different meaning for rare vs abundant cell types). In contrast,
2081+
#' the logit scale used internally by sccomp provides linear effects that are more appropriate for statistical inference.
2082+
#'
2083+
#' @param .data A sccomp estimate object (of class 'sccomp_tbl') obtained from running sccomp_estimate().
2084+
#' This object contains the fitted model and estimated effects.
2085+
#' @param formula_composition The formula specifying which model effects to use for calculating fold changes.
2086+
#' This should match or be a subset of the formula used in the original sccomp_estimate() call.
2087+
#' @param from Character string specifying the reference/control condition (e.g., "benign").
2088+
#' @param to Character string specifying the comparison condition (e.g., "cancer").
2089+
#'
2090+
#' @return A tibble with the following columns:
2091+
#' \itemize{
2092+
#' \item cell_group - The cell group identifier
2093+
#' \item proportion_fold_change - The estimated fold change in proportions between conditions.
2094+
#' Positive values indicate increases, negative values indicate decreases.
2095+
#' \item average_uncertainty - The average uncertainty in the fold change estimate, derived from the credible intervals
2096+
#' \item statement - A text description of the fold change, including the direction and the estimated proportions
2097+
#' }
20812098
#'
2082-
#' @param .data A `sccomp_tbl` object containing single-cell composition data.
2083-
#' @param formula_composition The formula for the composition model.
2084-
#' @param from The label for the control group (e.g., "healthy").
2085-
#' @param to The label for the treatment group (e.g., "cancer").
2086-
#' @return A tibble with cell groups and their respective proportional fold change.
20872099
#' @examples
2088-
#' \dontrun{
2089-
#' # Example usage
2090-
#' result <- sccomp_proportional_fold_change(sccomp_data, formula_composition, "healthy", "cancer")
2100+
#' \donttest{
2101+
#' if (instantiate::stan_cmdstan_exists()) {
2102+
#' # Load example data
2103+
#' data("counts_obj")
2104+
#'
2105+
#' # First estimate the composition effects
2106+
#' estimate <- sccomp_estimate(
2107+
#' counts_obj,
2108+
#' ~ type,
2109+
#' ~1,
2110+
#' sample,
2111+
#' cell_group,
2112+
#' count,
2113+
#' cores = 1
2114+
#' )
2115+
#'
2116+
#' # Calculate proportional fold changes from the estimated effects
2117+
#' estimate |>
2118+
#' sccomp_proportional_fold_change(
2119+
#' formula_composition = ~ type,
2120+
#' from = "benign",
2121+
#' to = "cancer"
2122+
#' )
2123+
#' }
20912124
#' }
20922125
#' @export
20932126
sccomp_proportional_fold_change <- function(.data, formula_composition, from, to) {

man/sccomp_proportional_fold_change.Rd

+47-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)