sccomp_proportional_fold_change | R Documentation |
This function calculates the proportional fold change between two conditions using the estimated effects from a sccomp model. The fold changes are derived from the model's posterior predictions rather than raw counts, providing a more robust estimate that accounts for the model's uncertainty and covariate effects.
Note! This statistic is descriptive and should not be used to define significance - use sccomp_test() for that. While fold changes in proportions are easier to interpret than changes in logit space, they are not linear (the same proportional change has different meaning for rare vs abundant cell types). In contrast, the logit scale used internally by sccomp provides linear effects that are more appropriate for statistical inference.
sccomp_proportional_fold_change(.data, formula_composition, from, to)
.data |
A sccomp estimate object (of class 'sccomp_tbl') obtained from running sccomp_estimate(). This object contains the fitted model and estimated effects. |
formula_composition |
The formula specifying which model effects to use for calculating fold changes. This should match or be a subset of the formula used in the original sccomp_estimate() call. |
from |
Character string specifying the reference/control condition (e.g., "benign"). |
to |
Character string specifying the comparison condition (e.g., "cancer"). |
A tibble with the following columns:
cell_group - The cell group identifier
proportion_fold_change - The estimated fold change in proportions between conditions. Positive values indicate increases, negative values indicate decreases.
average_uncertainty - The average uncertainty in the fold change estimate, derived from the credible intervals
statement - A text description of the fold change, including the direction and the estimated proportions
if (instantiate::stan_cmdstan_exists()) {
# Load example data
data("counts_obj")
# First estimate the composition effects
estimate <- sccomp_estimate(
counts_obj,
~ type,
~1,
sample,
cell_group,
count,
cores = 1
)
# Calculate proportional fold changes from the estimated effects
estimate |>
sccomp_proportional_fold_change(
formula_composition = ~ type,
from = "benign",
to = "cancer"
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.