Covariates
A covariate is a property of a sample known before the analysis: age, sex, batch, dose, time. If a table of covariates is given to create, the mean activity of each motif becomes a linear function of them. Two things come out of it. The influence of a covariate is no longer taken for random variation between samples. And each covariate gets an effect on each motif, with a standard error and a test. With age as a covariate, for instance, the results tell how the activity of every motif changes with age.
What does a covariate change in the model?
Without covariates, the activity of a motif in a sample is a sum of 2 parts: a mean shared by all samples and a deviation of the group of the sample. A covariate adds a third part:
The 2 highlighted parts are parameters of the model. They are estimated together with generalized least squares at the motif means stage of fit, and each estimate has a standard error. The covariate is given by a user. The deviation is random and is predicted later by predict, the same way as in a model without covariates.
In the notation of the How it works section, the mean of the activity matrix $U$ turns from $μ_m 1_s^T$ into $M X$. Here, $X$ is a matrix with a row of ones and a row per covariate, and $M$ has a column of means and a column of effects per covariate.
The table of covariates
The table goes to create with the --covariates option. Its first column holds sample names, and each of the other columns is a covariate:
sample age sex batch sample_1 34 F batch_1 sample_2 51 M batch_1 sample_3 47 F batch_2 sample_4 29 M batch_2
A column is treated according to what is in it:
| Column | What is done | Meaning of the effect |
|---|---|---|
| Numeric: all values are numbers | The values are z-scored: the mean is subtracted, and the result is divided by the standard deviation | The change of activity per one standard deviation of the covariate |
| Categorical: the values are text | The first level in the alphabetical order becomes a reference. Each of the other levels gets a covariate of zeros and ones, named after the column and the level, e.g. sex_M | The difference of activity between the level and the reference level |
All covariates are centered, so the mean of a motif stays what it was: its activity averaged over the samples of the project.
A few rules apply to the table:
- Every sample of the project has a row;
- An empty cell is imputed with a warning: the column mean for a numeric covariate, the most frequent level for a categorical one;
- A column of numbers is numeric even if the numbers are labels. Categories are better written as text: batch_1 in place of 1;
- A column mixing numbers and text is an error;
- A covariate constant over the samples is dropped with a warning;
- Covariates that are linear combinations of each other are an error.
Each covariate takes one degree of freedom from the samples. When too few are left for the variances of the groups, MARADONER warns about a singular Fisher information and names the cause. The way out is fewer covariates or larger groups.
Example
The generator of synthetic data can add covariates. Let's generate a dataset with one:
> maradoner generate demo --n-covariates 1 --cov-effect 0.3
Here, --cov-effect is the scale of the true effects. The demo folder gets a covariates.tsv table with a covariate named cov_1, and the true effects are saved to M_gt.tsv. For a livelier example we made a table by hand out of it. The values of cov_1 became an age in years (45 + 12 × cov_1, rounded), and a batch column was filled at random. The result is demo/samples.tsv:
sample age batch col_1 34 batch_2 col_2 22 batch_2 col_3 40 batch_2 col_4 50 batch_2
So age has a true effect on the 400 active motifs of the dataset, and batch has no effect at all. First, we create a project:
> maradoner create MyProject demo/expression.tsv demo/loadings.tsv --sample-groups demo/groups.json --loading-transform none --covariates demo/samples.tsv
Number of promoters: 1937, number of motifs: 500, number of samples: 57, number of groups: 10 Number of covariates (excl. intercept): 2 (age, batch_batch_2)
The second line lists the covariates as they enter the model. The batch column has 2 levels, batch_1 is the reference, and one covariate named batch_batch_2 is made of the other. Next come the usual commands:
> maradoner fit MyProject > maradoner predict MyProject > maradoner export MyProject results
Nothing in them is specific to covariates. The effects are in the results/params/covariates folder, one table per covariate: age.tsv, batch_batch_2.tsv and intercept.tsv. The first rows of age.tsv are
effect std z pvalue fdr motif_1 0.0395202674957732 0.045215572852554 0.8740410659983692 0.3820958901609635 0.4848932616255882 motif_2 -0.4832156891288582 0.0170929751054766 -28.26984103978677 8.11882851314425e-176 1.3531380855240416e-173 inactive_motif_3 0.017395894409502 0.0170719704147254 1.018974025077812 0.3082152982240479 0.4101852749342314
Here, effect is the estimate, std is its standard error, z is their ratio, pvalue is two-sided and fdr is that of Benjamini and Hochberg over the motifs. The standard deviation of age in this dataset is 12 years. Hence, the activity of motif_2 goes down by 0.48 with each 12 years of age.
At an FDR of 0.05, age has an effect on 303 motifs. All of them are among the 400 with a true effect, and the sign is right for each. Batch has an effect on no motif. That's fine: the batches were assigned at random.


An effect is a slope of a line. For 2 motifs of a moderate effect it looks as follows:


The scatter around a line is the deviation of the model. In this example the deviations are comparable to the effect of age in size, and the effect is still found.
Interactions
By default every column of the table is a covariate, and the effects of covariates add up. An interaction lets the effect of one covariate depend on another one, e.g. a change with age that differs between sexes. For the next 3 sections we made a richer dataset: the expression of the Quickstart example with added effects of a tissue (brain, liver or muscle), of an age, and of an interaction between age and sex. Sex alone has no effect. The table is
sample age sex tissue col_1 44 M muscle col_2 53 F liver col_3 62 M muscle
An interaction is requested with the --formula option of create:
> maradoner create MyProject demo/expression.tsv demo/loadings.tsv --sample-groups demo/groups.json --loading-transform none --covariates demo/samples.tsv --formula "tissue + age * sex"
Number of covariates (excl. intercept): 5 (tissue_liver, tissue_muscle, age, sex_M, age:sex_M)
Here, a formula lists columns of the table. Its notation is the one of R:
| Notation | Meaning |
|---|---|
a + b |
The covariates a and b |
a:b |
The interaction of a and b |
a * b |
The same as a + b + a:b |
(a + b) * c |
Parentheses group: the same as a + b + c + a:c + b:c |
A column absent from the formula is left out of the model. A column name with spaces or operators in it is quoted with backticks.
The covariate of an interaction is the product of the encoded covariates it is made of, centered. It is named after them with a colon. Here, the effect of age:sex_M is the difference between males and females in the change of activity per one standard deviation of age. Its table is results/params/covariates/age.sex_M.tsv: the colon is replaced by a dot in file names.
In this dataset 50 motifs have a true interaction. At an FDR of 0.05, 14 motifs are found, and 13 of them are among the 50. The correlation between the estimated and the true effects is 0.69, against 0.95 for age itself: in this dataset the interaction is estimated less precisely than the effect of age.
A few rules apply to interactions:
- A categorical covariate brings a covariate per level to an interaction, and 2 categorical ones bring a covariate per pair of levels;
- An interaction covariate that is constant, or is a linear combination of the covariates before it, is dropped with a warning. That is the case of a pair of levels met in no sample;
- An interaction without the covariates it is made of (
a:bwithouta) is allowed, andcreatewarns about it.
Does a covariate of several levels matter?
A categorical covariate of 3 levels turns into 2 covariates, and each of them compares a level to the reference one. Neither tells whether tissue matters for a motif at all. That question is answered by a joint test of all the covariates made of a column. The export command writes it to the tests/covariates folder for each column of more than 2 levels, and for each interaction of more than one covariate. The first rows of results/tests/covariates/tissue.tsv are
stat df pvalue fdr motif_1 2.6660147357808577 2 0.2636830756791781 0.48293603604245067 motif_2 6.157589510916761 2 0.04601468218621109 0.12436400590867862 inactive_motif_3 0.047050961959220185 2 0.976749085828209 0.9906177341056887
Here, stat is the Wald statistic of the hypothesis that all the effects are zero. Under that hypothesis it has a $χ^2$ distribution with df degrees of freedom. The covariance between the effects is taken into account.
Tissue has a true effect on 250 motifs of the dataset. At an FDR of 0.05 the joint test finds 157 motifs, and 151 of them are among the 250. The 2 tables of levels find 146 motifs between them.
How are 2 effects compared?
The tables of levels compare liver to brain and muscle to brain, as brain is the reference level. Liver is compared to muscle with the contrast command and its --covariates option:
> maradoner contrast MyProject "tissue_liver - tissue_muscle" results --covariates
Here, the expression is built of covariate names as create lists them. The command needs fit only, and it writes results/covariate_contrast.tsv:
effect std z pvalue fdr motif_1 -0.047641221132594974 0.0965949968372592 -0.4932058873904173 0.6218671183765363 0.7952491282358306 motif_2 0.11087563911908771 0.04998626438409695 2.2181221278532393 0.026546506445835973 0.08009732578782403 inactive_motif_3 0.0020720815494952513 0.04697243714244033 0.04411271110357383 0.9648145606530526 0.9813794596327438
The columns are those of a table of effects. The standard error accounts for the covariance between the 2 effects. Both are measured against the same brain samples, so they are positively correlated, and the error of their difference is smaller than that of 2 independent estimates (0.63 of it here, a median over motifs). At an FDR of 0.05, the difference is found for 149 motifs, and 145 of them have a true one.
Any linear combination is accepted, as with the contrasts of groups. A reference level can be named as well: tissue_brain stands for zero, so "tissue_liver - tissue_brain" repeats the table of tissue_liver. The --postfix option adds a postfix to the name of the table.
What if a covariate is left out?
We fitted the same data once more, this time without the table. Age does not vanish from the data. Its influence goes to the only random part there is, the deviations:
| With the table | Without it | |
|---|---|---|
| Fraction of variance explained by mean activities | 0.701 | 0.602 |
| Fraction of variance explained by the whole model | 0.953 | 0.954 |
| Rank correlation between the estimated and the true motif variances | 0.97 | 0.63 |
The model as a whole fits equally well, so gof does not give the omission away. The motif variances are what suffers. They take in the effect of age and no longer tell how much a motif varies between the groups.
A covariate that matters is better passed to the model. When it was not recorded at all, it can sometimes be recovered from the data. That is the subject of the next section.
What else is affected?
- The intercept.tsv table holds the mean activities, the same as params/motif_means.tsv, with a two-sided test against zero;
- The standard errors are computed for all covariates jointly, so a correlation between 2 covariates widens the errors of both;
- The tables of the activities folder hold the deviations, i.e. what is left of an activity once the mean and the covariates are taken away. A difference between groups that follows a covariate goes to the effect of the covariate. It is then absent from the activities and from the contrasts;
- The
grncommand has a--covariateoption. With it, the promoters are tested against the effect of a covariate on each motif; - The effects are estimated for all motifs, the ones left out by
predictincluded; - The expression exported with the
--log-countsoption ofexportincludes the covariates. The tables of the--loadings-productoption use the mean activity alone.
--covariate option of estimate-promoter-mean is a different thing. It takes properties of promoters and is covered in the Goodness of fit section.
