Skip to content

‘lmer’ method in Zlm function obviates first factor level #195

@juanmoriano

Description

@juanmoriano

I wonder whether the behavior of ‘lmer’ method in zlm can be explained to understand why, despite using the model form (~ 0 + …), the first level of a factor is missing. See below for a reproducible example. This prevents the design of specific contrasts later on while using for instance getLogFC function.

• [x] I have searched existing MAST issues
• [x] I’m using MAST version 1.30.0
• [x] I can provide a reproducible example

Reproducible example
library(muscat)
library(SingleCellExperiment)

# Load data
data(example_sce)
head(colData(example_sce))
# To SingleCellAssay
sca <- SceToSingleCellAssay(example_sce, class = "SingleCellAssay")
cdr2 <- colSums(assay(sca)>0)
colData(sca)$ngeneson <- scale(cdr2)
# Prepare metadata
colData(sca)$cluster_id  <- sub(" ", "_", sca$cluster_id)
colData(sca)$cluster_id  <- sub("T cells", "T_cells", sca$cluster_id)
table(colData(sca)$cluster_id)
colData(sca)$sample_id <- sub(" ", "_", sca$sample_id)
colData(sca)$cluster_id <-factor(colData(sca)$cluster_id)
colData(sca)$sample_id <-factor(colData(sca)$sample_id)

# Level order
#levels(colData(sca)$cluster_id) equals to "B_cells"  "CD14+_Monocytes" "CD4_T_cells"  "CD8_T_cells" "FCGR3A+_Monocytes"
colData(sca)$cluster_id <- factor(
  colData(sca)$cluster_id,
  levels = levels(colData(sca)$cluster_id)
)

# Fit the model
form = ~ 0  + cluster_id + ngeneson + (1|sample_id)
zlmCond <- zlm(formula = form, 
               sca=sca, 
               method='lmer', 
               ebayes=F,
               strictConvergence=F,
               fitArgsD=list(nAGQ = 0))

colnames(zlmCond@coefD) # B_cells excluded 

# Re-level order for comparison
colData(sca)$cluster_id <- factor(
  colData(sca)$cluster_id,
  levels = rev(levels(colData(sca)$cluster_id)) # FCGR3A+_Monocytes first (ref) level now
)

zlmCond2 <- zlm(formula = form, 
                           sca=sca, 
                           method='lmer', 
                           ebayes=F,
                           strictConvergence=F,
                           fitArgsD=list(nAGQ = 0))
colnames(zlmCond2@coefD) # FCGR3A+_Monocytes excluded

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions