How it works
This section is a summary of the paper for those curious about what happens inside fit. It has no proofs, and nothing in it is required for using MARADONER.
The model
The expression table $Y$ of $p$ promoters by $s$ samples is modeled as $$Y = 1_p μ_s^T + μ_p 1_s^T + B U + E.$$ Here, $B$ is the loading matrix of $p$ promoters by $m$ motifs, $U$ is a matrix of activities of $m$ motifs by $s$ samples, $E$ is noise, and $μ_s$ and $μ_p$ are sample-wise and promoter-wise means. Both $U$ and $E$ are random and follow matrix normal distributions: $$E \,~\, MN(0,\: I_p,\: D),\: U \,~\, MN(μ_m 1_s^T,\: Σ,\: G).$$ In this notation, the second argument is the covariance between rows and the third one is the covariance between columns. All 3 covariance matrices are diagonal: $D$ holds the error variance $σ$ of the group of each sample, $G$ holds the multiplier $ν$ of the group of each sample, and $Σ$ holds the variance $τ$ of each motif. So the noise of a promoter in a sample of group $g$ has a variance of $σ_g$, and the activity of motif $k$ there has a mean of $μ_{m,k}$ and a variance of $τ_k ν_g$.
Why not just center the data?
The means $μ_s$ and $μ_p$ are of no interest, and the classic way to be rid of them is to subtract row and column averages. Let's see what the subtraction does to 3 numbers $a$, $b$ and $c$, independent and with a variance of $σ$ each.
The centered numbers sum up to zero, so any 2 of them give away the third. They are no longer independent, and the variance of each is $2σ/3$. A method that goes on as if it had 3 independent numbers of variance $σ$ gets the variance wrong. For $n$ numbers the factor is $(n-1)/n$, and it matters when $n$ is small.
MARADONER replaces the 3 numbers with 2: $$x_1 = {a - b}/{√2},\: x_2 = {a + b - 2c}/{√6}.$$ A constant added to $a$, $b$ and $c$ changes neither of them, so the mean is gone as well. And this time $x_1$ and $x_2$ are independent and have the same variance $σ$ as the numbers we started with.
For $n$ numbers the same is done by a matrix $H_n$ of $n - 1$ rows. The rows are orthogonal to each other and to the vector of ones, and each has a unit length. It is the Helmert matrix without its row of ones. In the paper it is called an orthogonal complement to the vector of ones. When the variances of samples differ, the transformed noise is no longer independent, and its covariance matrix $H_n D H_n^T$ is not diagonal. Its inverse and its determinant still have closed forms that take a linear time to compute.
The order of estimation
We are after an order of steps in which every kind of parameters is estimated from data cleared of the kinds not yet known. Let's follow the equation of the model through them.
- $Y$ is multiplied by $H_p$ from the left. The sample means $μ_s$ vanish. All the later steps start from this product.
- The product is multiplied by $H_s^T$ from the right, and the terms with $μ_p$ and $μ_m$ vanish. Then it is multiplied from the left by $Q_N^T$, an orthogonal complement to the columns of the loading matrix. The term with $U$ vanishes too. Only the noise is left, and the error variances $σ$ are estimated from it. This is the REML: a likelihood of the part of the data that does not depend on the other parameters.
- $Q_N$ is put aside and $B$ is back. With $σ$ known, the variances $τ$ and $ν$ are estimated from $H_p Y H_s^T$.
- $Q_N^T$ is applied again, this time without $H_s$, and the promoter-wise means $μ_p$ are estimated. The solution is not unique, and the one of the minimal norm is taken.
- $μ_p$ is subtracted. With all the variances known, the mean activities $μ_m$ are estimated with generalized least squares. Their standard errors come from the Fisher information.
- The activities are predicted as described in the Motif activities section.
- The tests are computed from the standard errors of the parameters and from the posterior covariance of the activities.
In the picture, a matrix applied at the current step is coloured, and a crossed-out term is equal to zero. A parameter in a frame is the one being estimated, and a parameter in green is already known.
Steps 2 and 3 are numerical optimizations, and the others have closed-form solutions.
Why is it fast?
There are 2 places where a straightforward implementation would not fit into memory.
The first one is $Q_N$. It has $p$ rows and $p - r$ columns, with $r$ being the rank of $B$, and for 20000 promoters that is close to 20000 by 20000 numbers. MARADONER never forms it: the product of $Q_N^T$ with the data is computed through $r$ Householder reflections, and those take as much memory as $B$ does.
The second one is the covariance matrix of step 3. The data there are $(p - 1)(s - 1)$ numbers correlated with each other. The matrix has the structure of a Kronecker product plus an identity matrix, however. With the Woodbury identity its inverse is reduced to eigenvalue decompositions of 2 small matrices, one of $s$ by $s$ and one of $m$ by $m$. In the end, the likelihood and its gradient need no operation cubic in the number of promoters or samples.
The scale of variances
The variance of an activity is the product $τ_k ν_g$. If all $τ$ are multiplied by a constant and all $ν$ are divided by it, the model stays the same. That does no harm to the optimization, but the Fisher information of such a model is singular, and no standard errors can be had from it. MARADONER fixes the $ν$ of one group to remove the ambiguity.
What is not in the paper?
The package has grown a few features since the paper was written:
- Covariates: the mean of $U$ becomes $M X$, with $X$ being a matrix of sample covariates with a row of ones, and $M$ being a matrix of effects of the covariates on each motif;
- Low-rank corrections: $D$ becomes $D + W W^T$ and $G$ becomes $G + V V^T$;
- Motif families: $Σ$ becomes $Σ + F (Ω + L L^T) F^T$, with $F$ telling which motifs belong to which family;
- A prior on the motif means with variances estimated by REML;
- The likelihood-ratio test of the ANOVA;
- The single-sample model.
The paper, in turn, describes a REML estimator of promoter variances. The --promoter-variance option does a different thing at the moment.
