@@ -2068,26 +2068,59 @@ clear_stan_model_cache <- function(cache_dir = sccomp_stan_models_cache_dir) {
2068
2068
}
2069
2069
}
2070
2070
2071
- # ' Calculate Proportional Fold Change for sccomp Data
2071
+ # ' Calculate Proportional Fold Change from sccomp Estimated Effects
2072
2072
# '
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.
2080
2077
# '
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
+ # ' }
2081
2098
# '
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.
2087
2099
# ' @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
+ # ' }
2091
2124
# ' }
2092
2125
# ' @export
2093
2126
sccomp_proportional_fold_change <- function (.data , formula_composition , from , to ) {
0 commit comments