The design¶
A Design joins the sample table, the fixed effects as an R formula, optional
random effects in lme4’s notation and named contrasts. The formula follows the notation
of Wilkinson & Rogers (1973) as R reads it Chambers & Hastie, 1992: ~ condition + batch adds terms, a:b
is an interaction, a * b is a + b + a:b, and ~ 0 + group has no intercept.
model_matrix codes it as R’s model.matrix does: a numeric column is a
covariate, a text or boolean column is a factor coded by treatment contrasts, indicators
of every level but the first.
Columns are named as R names them: the intercept (Intercept) (INTERCEPT), a
level after its factor (conditionstim), interactions joined by :, and names that are
not syntactic in R between backticks (quote_name). parse_formula expands a
formula into its terms (FormulaTerms), parse_random_effects reads random
effects (RandomEffect), and model_matrix returns the matrix with its
column names (ModelMatrix).
The first level of a factor is the reference, and every coefficient of that factor is a
difference from it. Without levels, the levels of a text column are sorted by code
point, which is R’s order only in the C locale; pass
levels={"condition": ["ctrl", "stim"]} whenever the reference matters, which is almost
always.
One model for every gene¶
Every gene of a samples x genes matrix of log-expression values is fitted with the
same design matrix (limma’s lmFit; Smyth (2004)):
where holds the gene’s precision weights (from voom, or sample weights) and is
the identity, or the correlation matrix of a known correlation between the samples of a
block Smyth et al., 2005. fit_linear_model returns a LinearModelFit with, for
every gene, the coefficients , the residual variance on residual
degrees of freedom, and the unscaled standard errors , so that the standard
error of coefficient is . A gene with missing values, or with weights of
its own, is fitted to its observed samples by a QR decomposition of its own
Golub & Van Loan, 2013; missing values and zero weights lower its .
Contrasts¶
A contrast is a combination of the coefficients, such as the difference between two
groups. make_contrasts reads named expressions such as "groupB - groupA" or
"(groupB + groupC)/2 - groupA" written in the design’s column names, as limma’s
makeContrasts does Ritchie et al., 2015, into Contrasts, a mapping of contrast names
to weights; Contrasts.select takes some of them by name, and
Design.with_contrasts returns the design with other contrasts.
contrasts_fit re-expresses each gene’s fit: the estimate is and its
unscaled variance , with the gene’s unscaled covariance matrix.
Contrasts are matched to the coefficients by name, never by position.
With weights that differ between genes, limma’s contrasts.fit approximates the
standard errors of contrasts of correlated coefficients from the covariance of the
unweighted design. CytePool computes them exactly by default; method="limma"
reproduces the approximation.
Designs that cannot answer the question¶
A contrast is estimable when it is a combination of the rows of , that is, when it is
orthogonal to the null space of Searle, 1971. In a design of full rank every
contrast is. Rank deficiency arises when a column is a combination of others, decided as
R’s qr() decides it: for example when two factors group the samples alike, or, within
one cell type, when every sample of a donor was left out. limma_voom then fits
the column space of the group’s design and tests only the contrasts its samples can
estimate, reporting the others.
Design.check reports such problems before anything is fitted, as a
DesignReport of DesignIssue entries (DesignReport.kinds lists their
kinds), each with what to do: aliased columns, no residual degrees of freedom,
confounded factors, empty levels, levels with one sample, samples fitted exactly
(leverage 1, the diagonal of the hat matrix; Hoaglin & Welsch (1978)), numeric codes that look like
batches, labels that look like missing values, contrasts that cannot be estimated, and
random effects whose variances cannot be estimated.
- Wilkinson, G. N., & Rogers, C. E. (1973). Symbolic description of factorial models for analysis of variance. Journal of the Royal Statistical Society: Series C (Applied Statistics), 22(3), 392–399. 10.2307/2346786
- Chambers, J. M., & Hastie, T. J. (1992). Statistical models. In J. M. Chambers & T. J. Hastie (Eds.), Statistical Models in S. Wadsworth & Brooks/Cole.
- Smyth, G. K. (2004). Linear models and empirical Bayes methods for assessing differential expression in microarray experiments. Statistical Applications in Genetics and Molecular Biology, 3(1), Article 3. 10.2202/1544-6115.1027
- Smyth, G. K., Michaud, J., & Scott, H. S. (2005). Use of within-array replicate spots for assessing differential expression in microarray experiments. Bioinformatics, 21(9), 2067–2075. 10.1093/bioinformatics/bti270
- Golub, G. H., & Van Loan, C. F. (2013). Matrix Computations (4th ed.). Johns Hopkins University Press.
- Ritchie, M. E., Phipson, B., Wu, D., Hu, Y., Law, C. W., Shi, W., & Smyth, G. K. (2015). limma powers differential expression analyses for RNA-sequencing and microarray studies. Nucleic Acids Research, 43(7), e47. 10.1093/nar/gkv007
- Searle, S. R. (1971). Linear Models. Wiley.
- Hoaglin, D. C., & Welsch, R. E. (1978). The hat matrix in regression and ANOVA. The American Statistician, 32(1), 17–22. 10.1080/00031305.1978.10479237