FitLmerContrast - for data with pre post treatment and 2 response groups; within each cell type contrast difference in fold change between groups, baseline difference, and fold change across groups of module scores.
Source:R/SCGroupContrast_modulefunctions.r
FitLmerContrast.Rd
FitLmerContrast - for data with pre post treatment and 2 response groups; within each cell type contrast difference in fold change between groups, baseline difference, and fold change across groups of module scores.
Usage
FitLmerContrast(
module_data_frame,
celltype_column = "celltype",
metadata,
fixed_effects = NULL,
lmer_formula = NULL,
plotdatqc = TRUE,
figpath
)
Arguments
- module_data_frame
data for each cell to model -- designed to be scores for modules (columns) returned by scglmmr::WeightedModuleScore
- celltype_column
the column in metadata with the cluster / celltype designation for each cell
- lme4metadata
metadata for model fit
- f1
model furmula
- contrast_list
list of linear model contrasts.
- plot_savepath
path to save results
Examples
if (FALSE) {
# load data from single cell data object
Seurat = readRDS("my_seurat_object.rds")
# add cellwise module score for each signature
mod_scores = WeightedCellModuleScore(seurat_object = Seurat,
module_list = btm,
threshold = 0.1,
return_weighted = FALSE, cellwise_scaling = FALSE,
Seurat_version = "2")
Seurat = AddMetaData(Seurat,metadata = mod_scores)
module_n = names(sig_test)
# set up module data frame
module_df = Seurat@meta.data %>% select(barcode_check, celltype_joint, module_n)
# format metadata as factors group_id is order leveled for contrast_fit = contrast(emm1, method = list( (c21 - c20) - (c11 - c10) ))
md = Seurat@meta.data %>%
mutate(group_id = factor(treat_time, levels = c('pre_low', 'post_low', 'pre_high', 'post_high'))) %>%
mutate(sampleid = factor(sampleid)) %>%
select(barcode_check, celltype_joint, sampleid, age, group_id)
# Fit mixed model
plot_savepath = paste0(my_figure_save_path, "/marginalmeans/"); dir.create(plot_savepath)
# specify any random intercept model e.g.
f1 = 'modulescore ~ age + group_id + (1|sampleid)'
# fit sc mod mixed model on ewighted module scores.
mm_res = FitLmerContrast(module_data_frame = module_df,
celltype_column = 'celltype',
metadata = md,
fixed_effects = NULL,
lmer_formula = f1,
plotdatqc = TRUE,
figpath = 'your/file/path')
}