Linear Modeling

Here I will try to address the analysis workflow of studying DNA methylation with one or more independent variable, be it tissue, cell type, sex, age, tumor/normal, treatment/control or a combination of these factors. The DML (short for Differential Methylation Locus) function models beta values (DNA methylation levels) on known co-variates (e.g., case vs control) using linear modeling. This general supervised learning framework identifies CpG loci whose differential methylation is associated with known co-variates. Let’s first load needed packages

In the following, we will use 10 mouse array samples as our example dataset. This dataset contains mouse samples from different tissues and individuals of different ages and sexes. The dataset is stored in a SummarizedExperiment object, which contains a data matrix combined with column-wise metadata accessible with colData:

## DataFrame with 10 rows and 4 columns
##                                    IDAT      tissue         sex       age
##                             <character> <character> <character> <numeric>
## 204875570008_R06C01 204875570008_R06C01       Cecum      Female         1
## 204875570011_R02C02 204875570011_R02C02       Cecum        Male         1
## 204875570008_R02C02 204875570008_R02C02       Colon      Female         1
## 204875570008_R03C02 204875570008_R03C02       Colon      Female         1
## 204875570008_R05C01 204875570008_R05C01   Esophagus      Female        16
## 204875570011_R03C01 204875570011_R03C01   Esophagus        Male        16
## 204875570011_R01C01 204875570011_R01C01         Fat        Male        16
## 204875570022_R03C02 204875570022_R03C02         Fat      Female        16
## 204875570011_R04C01 204875570011_R04C01       Heart        Male        31
## 204875570014_R04C02 204875570014_R04C02       Heart        Male        31

CRITICAL: If your data is NA-masked (see the Basic Usage tutorial), it is critical to preclude CpGs with missing levels. For example, if a CpG does not contain any non-NA values for all male mice, one cannot assess sex-specific DNA methylation for this CpG. One needs to preclude such CpGs from the modeling of sex-specific differential methylation. This can be done using the checkLevels function.

In the following, we will test for both sex and tissue as co-variates using the checkLevels function:

## [1] 995

NOTE: If your model include discrete contrast variables like tissue and sex as in the current example, you should consider explicitly turning it into a factor variable with a reference level (we use treatment coding, see different coding systems).

For example, to use Colon as the reference tissue and Female as the reference sex, one can do the following

Then we will model DNA methylation variation treating tissue and sex as covariates. To do that we will call the DML function and specify the R formula ~tissue + sex. This function fits DNA methylation reading to a linear model and perform the corresponding slope test and goodness-of-fit test (F-test holding out each contrast variable). All these results are returned in an object of class DMLSummary;

## DMLSummary Object with 995 Loci, 10 samples.
## Contrasts: tissue sex

You can use mc.cores argument to parallelize the computing.

Test Interpretation

The DMLSummary object is a list of expanded summary.lm objects from the linear model (as would be returned by summary(lm()). The summaryExtractTest function abstracts a DMLSummary object into a data frame with rows corresponding to CpGs/loci and columns containing the slopes and p-values of each variable.

##  [1] "Est_`(Intercept)`"    "Est_tissueCecum"      "Est_tissueEsophagus" 
##  [4] "Est_tissueFat"        "Est_tissueHeart"      "Est_sexMale"         
##  [7] "Pval_`(Intercept)`"   "Pval_tissueCecum"     "Pval_tissueEsophagus"
## [10] "Pval_tissueFat"       "Pval_tissueHeart"     "Pval_sexMale"        
## [13] "FPval_tissue"         "FPval_sex"            "Eff_tissue"          
## [16] "Eff_sex"

With the exception of the Intercept, there are four groups of columns, each starting with “Est_”, “Pval_”, “FPval_”, and “Eff_” as prefix. Here are what they represent:

  • Est_
    The slope estimate (aka the beta coefficient) for continuous variable. DNA methylation difference of the current level with respect to the reference level for nominal contrast variables. Each suffix is concatenated from the contrast variable name (e.g., tissue, sex) and the level name if the contrast variable is discrete (e.g, Cecum, Esophagus, Fat). For example, Est_tissueFat should be interpreted as the estimated beta value difference of Fat compared to the reference tissue (which is Colon, as set above. If reference is not set, the first level in alphabetic order is used as the reference level). There are is a special column named Est_`(Intercept)`. They correspond to the beta value of the reference level (in this case a Female Colon sample).
  • Pval_
    The p-value of t-testing the slope (statistical significance of the difference). For example, Pval_tissueFat tests whether Fat is significantly different from Colon (the reference level) in DNA methylation. The Pval_`(Intercept)` tests whether the reference level is significantly different from zero.
  • FPval_
    The p-value of the F-test contrasting the full model against a reduced model with the labeled contrasting held out. Note that “Pval_” and “FPval_” are equivalent when the contrast variable is a 2-level factor, i.e., a pairwise comparison.
  • Eff_
    The effect size of each normial contrast variable. This is equivalent to the maximum slope subtracted by the minimum level including the reference level (0).

Goodness of fit

One may want to ask a question like whether the methylation of the probe is tissue-specific rather than the methylation of the probe is specifically hypermethylated in fat. The former question ask about the contrast variable as a whole instead of a specific level of the contrast variable. To answer this question, we can use a F-test contasting the full model with a reduced model with the target contrast variable held out. This information is captured in the FPval_ columns. For example, to get all CpGs that are methylated specific to sex,

Here we used 0.1 as the effect size threshold. This means DNA methylation difference under 0.1 (10%) is not considered a biologically meaningful difference. This is a valid assumption for homogenous cell composition as most cells would be either biallelically methylated, unmethylated or monoallelically methylated.

We can define CpG methylation as sex-specific, tissue-specific or both

##             tissue_specific
## sex_specific FALSE TRUE
##        FALSE   891   99
##        TRUE      5    0

As you can see from the result, two probes are sex-specific and one probe 13 probes are tissue-specific. There is no overlap between probes whose methylation reading is differential across both contrasts.

Pairwise Comparison

From the test result, we can also ask whether the DNA methylation might be different between two sexes or two tissues. For example, Est_sexMale compares male from females. The following code creates a volcano plot.

Likewise, we can ask whether DNA methylation might be different between fat and colon. We can do

Continuous Variable

DMR

Testing sex-specific differential methylation yields chrX-linked probes.

## Merging correlated CpGs ... Done.
## Generated 508 segments.
## Combine p-values ... 
##  - 29 significant segments.
##  - 3 significant segments (after BH).
## Done.