TestMultivariateConvergence: Test Multivariate Convergence

View source: R/composite_score_function.R

TestMultivariateConvergenceR Documentation

Test Multivariate Convergence

Description

Fits a multivariate linear model (lm) to test a numeric convergence score against multiple covariates simultaneously, correcting for confounding factors.

Usage

TestMultivariateConvergence(
  seurat_obj,
  score_var,
  test_vars,
  level = c("cell", "patient"),
  patient_id_var = NULL
)

Arguments

seurat_obj

Seurat object whose meta.data holds the variables.

score_var

Character. Name of the meta.data column holding the numeric score.

test_vars

Character vector. Names of the meta.data columns to include in the model.

level

Character. Either "cell" (default) or "patient" (pseudobulk aggregation).

patient_id_var

Character. Name of the meta.data column identifying patients (required if level = "patient").

Value

The summary.lm() object (invisibly). A detailed message is printed summarizing the model.

Examples

seu_path <- system.file("extdata", "pbmc3k_subset.rds", package = "ConvergeR")
seu <- readRDS(seu_path)
set.seed(42)
seu$SS <- paste0("Patient_", sample(1:5, ncol(seu), replace = TRUE))
seu$age <- sample(20:70, ncol(seu), replace = TRUE)
seu$tumor_status <- sample(c("Primary", "Metastatic"), ncol(seu), replace = TRUE)
seu$treatment <- sample(c("Treated", "Untreated"), ncol(seu), replace = TRUE)
seu$Score_IFN <- rnorm(ncol(seu))
seu$Score_Inflam <- rnorm(ncol(seu))

seu <- CalculateConvergedScore(
  seurat_obj = seu,
  principal_score = "Score_IFN",
  other_scores = "Score_Inflam",
  output_colname = "Converged_Immune"
)

TestMultivariateConvergence(
  seurat_obj = seu,
  score_var = "Converged_Immune",
  test_vars = c("age", "tumor_status", "treatment"),
  level = "patient",
  patient_id_var = "SS"
)

ConvergeR documentation built on Oct. 10, 2026, 5:07 p.m.