sccomp_calculate_residuals | R Documentation |
sccomp_calculate_residuals
computes the residuals between observed cell group proportions and the predicted proportions from a fitted sccomp
model. This function is useful for assessing model fit and identifying cell groups or samples where the model may not adequately capture the observed data. The residuals are calculated as the difference between the observed proportions and the predicted mean proportions from the model.
sccomp_calculate_residuals(.data)
.data |
A tibble of class |
The function performs the following steps:
Extracts the predicted mean proportions for each cell group and sample using sccomp_predict()
.
Calculates the observed proportions from the original count data.
Computes residuals by subtracting the predicted proportions from the observed proportions.
Returns a tibble containing the sample, cell group, residuals, and exposure (total counts per sample).
A tibble (tbl
) with the following columns:
sample - A character column representing the sample identifiers.
cell_group - A character column representing the cell group identifiers.
residuals - A numeric column representing the residuals, calculated as the difference between observed and predicted proportions.
exposure - A numeric column representing the total counts (sum of counts across cell groups) for each sample.
if (instantiate::stan_cmdstan_exists() && .Platform$OS.type == "unix") {
# Load example data
data("counts_obj")
# Fit the sccomp model
estimates <- sccomp_estimate(
counts_obj,
formula_composition = ~ type,
formula_variability = ~1,
.sample = sample,
.cell_group = cell_group,
.count = count,
approximate_posterior_inference = "all",
cores = 1
)
# Calculate residuals
residuals <- sccomp_calculate_residuals(estimates)
# View the residuals
print(residuals)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.