Beta vs M values: which scale to test methylation on

methylation
limma
simulation
effect size
Should differential methylation be tested on beta values or M values? A limma simulation by methylation level, and how to report delta-beta and thresholds.
Author

Pseudocount

Published

26 November 2026

Setup: packages and helper functions
suppressPackageStartupMessages({
  library(limma)
  library(ggplot2)
})
stopifnot(packageVersion("limma") >= "3.56", packageVersion("ggplot2") >= "3.4.0")

pct <- function(x, d = 1) sprintf(paste0("%.", d, "f%%"), 100 * x)
dec <- function(x, d = 2) sprintf(paste0("%.", d, "f"), x)
num <- function(x) format(round(x), big.mark = ",", scientific = FALSE, trim = TRUE)

logit2 <- function(b) log2(b / (1 - b))          # beta value -> M value
ilogit2 <- function(m) 2^m / (1 + 2^m)           # M value -> beta value

violet <- "#5a3fc0"; magenta <- "#d14fa6"; grey <- "#8a8797"; dark <- "#3b3947"
theme_pc <- theme_minimal(base_size = 12) +
  theme(plot.background = element_rect(fill = "white", colour = "white"),
        panel.grid.minor = element_blank(), legend.position = "bottom",
        strip.text = element_text(face = "bold"))

You have methylation array data, two groups to compare, and two numbers for every CpG: the beta value, between 0 and 1, and the M value, its logit. Which one should go into the test? The short answer is to test on M values with limma-trend (eBayes(trend = TRUE)), look at plotSA(), and report differences in beta values. In the simulation below, with most CpGs near 0 or 1 as on a real array and a variance that is constant on the M scale, limma on beta values gave p < 0.05 to 6.9% of unchanged CpGs in the middle of the methylation range, where a well-calibrated test gives 5%; on M values the rate was 5.0%. With a variance that behaves differently, plain limma on M values is the one that goes wrong: 2.1% in the middle, where it found 24% of the truly changed CpGs against 38% for limma-trend on M values. limma-trend on M values kept between 4.5% and 5.4% at every methylation level in every setting tried.

The post also shows which effect size belongs in the results table, and why a threshold on the M scale is not a threshold on delta-beta.

Two scales for the same measurement

A methylation array measures a methylated and an unmethylated signal for each CpG. The beta value is the methylated share of the total signal, so it reads roughly as the percentage of methylated copies in the sample. The M value is the log2 ratio of the methylated to the unmethylated signal. Apart from small offsets that keep both finite, the two are linked by the logit (Du et al. 2010):

M=log⁡2(β/(1−β))M = \log_2 (\beta / (1 - \beta))

The transformation is close to a straight line in the middle of the range and stretches the ends. A change of 0.05 in beta centred on 0.5 is 0.29 M units; the same change centred on 0.05 is 1.66 M units.

The reason to transform at all is the variance. A beta value cannot go below 0 or above 1, so a CpG that is almost fully methylated or unmethylated in every sample also varies little between samples, measured in beta. Du et al. (2010) called this severe heteroscedasticity (variance that changes with the mean) at the ends of the range. In their data, technical replicates of a titration series on the older 27K array, the standard deviation of M values was roughly constant across the whole range. Whether the between-person variation in a real 450K or EPIC study behaves the same way is a separate question, which is why this post uses two variance models and ends with a check.

Du et al. found the M-value advantage with plain per-site t-tests on two technical replicates per group, where the bounded, skewed beta values hurt the test itself. With more samples, a per-CpG t-test compares each CpG with its own variance and cares less about the scale. limma is different. Its moderated t-test (Smyth 2004) does not rely on each CpG’s variance alone, which is unstable with a handful of samples; it pulls every variance towards a common prior value estimated from all CpGs. That borrowing is where limma’s power comes from, and it works best when the true variances scatter around one typical value. On the beta scale they do not.

The setup

Each simulated data set has 6 samples per group and 20,000 CpGs. Of the CpGs, 10% truly differ between the groups, by a delta-beta (difference in mean beta value) drawn evenly between 0.01 and 0.2 in either direction; the rest are unchanged. Real arrays have far more CpGs near 0 and 1 than in the middle, so the mean methylation follows an array-like mix: 35% of CpGs below 0.1, 35% above 0.9, and the rest spread evenly in between. Unchanged CpGs stay between 0.02 and 0.98; changed CpGs keep both group means between 0.01 and 0.99. The ends of the range, below 0.1 or above 0.9, are called the extremes below, and 0.3 to 0.7 the middle; every result is reported by level of methylation. Because limma estimates its prior from all CpGs together, its rate at one level also depends on how many CpGs sit at the other levels, so the runs are repeated with means spread evenly as a check.

The variance model decides the answer, so there are two. In the logit-normal model each CpG is normally distributed on the M scale with its own standard deviation, scattered around 0.4: the pattern Du et al. observed in technical replicates. In the beta model each CpG follows a beta distribution with its own precision (median 50); its variance on the beta scale is μ(1−μ)/(1+ϕ)\mu(1-\mu)/(1+\phi), which shrinks towards the ends less steeply than in the first model, so that on the M scale the variance grows towards the ends instead. This is the between-sample part of the beta-binomial model used for bisulfite sequencing, without the read sampling. Before taking the logit, its beta values are clipped to the interval from 0.001 to 0.999. The true delta-beta of a CpG is the difference between the two group means of the beta values; under the logit-normal model it is computed numerically, because the mean of the back-transformed values is not the back-transformed mean.

n_cpg <- 20000        # CpGs per data set (array-like mix)
n_cpg_even <- 10000   # CpGs per data set in the check with evenly spread means
n_per <- 6            # samples per group
dm_frac <- 0.10       # share of CpGs that truly differ
db_range <- c(0.01, 0.20)   # true |delta-beta| of those CpGs, drawn uniformly
mean_range <- c(0.02, 0.98) # mean methylation of unchanged CpGs stays inside these
edges <- c(0.1, 0.9)        # array-like mix: a share of CpGs below edges[1], a share above edges[2],
mix_share <- c(0.35, 0.35)  # and the rest spread evenly in between
dm_bounds <- c(0.01, 0.99)  # both group means of a changed CpG stay inside these
m_sd <- 0.4           # logit-normal model: typical within-group SD on the M scale
phi_med <- 50         # beta model: typical precision (larger = less variable)
clip <- 0.001         # beta model: values are clipped to [clip, 1 - clip] before the logit

strata_breaks <- c(0, 0.1, 0.3, 0.7, 0.9, 1)
strata_labels <- c("0-0.1", "0.1-0.3", "0.3-0.7", "0.7-0.9", "0.9-1")
zq <- qnorm(ppoints(200))   # grid for the exact group means under the logit-normal model

# mean methylation between lo and hi: array-like (mostly near 0 or 1) or evenly spread
draw_mean <- function(lo, hi, mix) {
  n <- length(lo)
  if (mix == "even") return(runif(n, lo, hi))
  u <- runif(n)
  low <- runif(n, lo, pmax(lo, edges[1]))
  high <- runif(n, pmin(hi, edges[2]), hi)
  between <- pmin(pmax(runif(n, edges[1], edges[2]), lo), hi)
  ifelse(u < mix_share[1], low, ifelse(u < sum(mix_share), high, between))
}

simulate_cpgs <- function(model = c("logit-normal", "beta"), mix = c("array", "even"),
                          n_cpg = 20000) {
  model <- match.arg(model); mix <- match.arg(mix)
  is_dm <- seq_len(n_cpg) <= dm_frac * n_cpg
  db <- ifelse(is_dm, runif(n_cpg, db_range[1], db_range[2]), 0)
  # centre of the two groups
  lo <- ifelse(is_dm, dm_bounds[1] + db / 2, mean_range[1])
  hi <- ifelse(is_dm, dm_bounds[2] - db / 2, mean_range[2])
  mid <- draw_mean(lo, hi, mix)
  sgn <- sample(c(-1, 1), n_cpg, replace = TRUE)
  loc_a <- mid - sgn * db / 2
  loc_b <- mid + sgn * db / 2
  if (model == "logit-normal") {
    # each CpG gets its own SD on the M scale, scattered around m_sd
    s <- m_sd * sqrt(10 / rchisq(n_cpg, df = 10))
    m_a <- logit2(loc_a); m_b <- logit2(loc_b)
    M <- cbind(matrix(m_a, n_cpg, n_per), matrix(m_b, n_cpg, n_per)) +
      matrix(rnorm(n_cpg * 2 * n_per), n_cpg) * s
    beta <- ilogit2(M)
    mean_a <- rowMeans(ilogit2(m_a + outer(s, zq)))   # true mean beta of each group
    mean_b <- rowMeans(ilogit2(m_b + outer(s, zq)))
  } else {
    # beta distribution with mean loc and precision phi: variance loc (1 - loc) / (1 + phi)
    phi <- exp(rnorm(n_cpg, log(phi_med), 0.5))
    loc <- cbind(matrix(loc_a, n_cpg, n_per), matrix(loc_b, n_cpg, n_per))
    beta <- matrix(rbeta(n_cpg * 2 * n_per, loc * phi, (1 - loc) * phi), n_cpg)
    M <- logit2(pmin(pmax(beta, clip), 1 - clip))
    mean_a <- loc_a; mean_b <- loc_b
  }
  list(beta = beta, M = M, is_dm = is_dm, true_db = mean_b - mean_a,
       stratum = cut((mean_a + mean_b) / 2, strata_breaks, labels = strata_labels,
                     include.lowest = TRUE))
}
group <- factor(rep(c("A", "B"), each = n_per))
design <- model.matrix(~ group)
fdr <- 0.05
db_min <- 0.05                                  # the delta-beta a reader might care about
lfc_centre <- 0.5
lfc_M <- logit2(lfc_centre + db_min / 2) - logit2(lfc_centre - db_min / 2)   # its M equivalent at 50%

# ordinary two-sample t-test (equal variances) for every CpG, from the same linear model
ordinary_p <- function(fit) {
  t <- fit$coefficients[, 2] / (fit$stdev.unscaled[, 2] * fit$sigma)
  2 * pt(-abs(t), df = fit$df.residual)
}

analyse <- function(d) {
  fit_b <- lmFit(d$beta, design)
  fit_m <- lmFit(d$M, design)
  p <- list(
    "t-test, beta"      = ordinary_p(fit_b),
    "t-test, M"         = ordinary_p(fit_m),
    "limma, beta"       = eBayes(fit_b)$p.value[, 2],
    "limma, M"          = eBayes(fit_m)$p.value[, 2],
    "limma-trend, beta" = eBayes(fit_b, trend = TRUE)$p.value[, 2],
    "limma-trend, M"    = eBayes(fit_m, trend = TRUE)$p.value[, 2],
    "treat on M"        = treat(fit_m, lfc = lfc_M)$p.value[, 2],
    "treat on beta"     = treat(fit_b, lfc = db_min, trend = TRUE)$p.value[, 2])
  obs_db <- fit_b$coefficients[, 2]              # observed delta-beta, B minus A
  calls <- lapply(p, function(x) p.adjust(x, "BH") < fdr)
  calls[["limma, M, then |delta-beta| filter"]] <- calls[["limma, M"]] & abs(obs_db) >= db_min
  tiny <- abs(d$true_db) < db_min
  do.call(rbind, lapply(names(calls), function(m) {
    pv <- if (m %in% names(p)) p[[m]] else p[["limma, M"]]   # the filter keeps limma's p-values
    data.frame(method = m, stratum = strata_labels,
      null_n     = as.vector(tapply(!d$is_dm, d$stratum, sum)),
      null_p05   = as.vector(tapply(!d$is_dm & pv < 0.05, d$stratum, sum)),
      dm_n       = as.vector(tapply(d$is_dm, d$stratum, sum)),
      dm_call    = as.vector(tapply(d$is_dm & calls[[m]], d$stratum, sum)),
      big_n      = as.vector(tapply(!tiny, d$stratum, sum)),
      big_call   = as.vector(tapply(!tiny & calls[[m]], d$stratum, sum)),
      call_n     = as.vector(tapply(calls[[m]], d$stratum, sum)),
      call_null  = as.vector(tapply(calls[[m]] & !d$is_dm, d$stratum, sum)),
      call_tiny  = as.vector(tapply(calls[[m]] & tiny, d$stratum, sum)))
  }))
}

Every CpG is tested six ways: an ordinary two-sample t-test (equal variances), limma’s lmFit() followed by eBayes(), and limma-trend, which is eBayes(trend = TRUE), each on beta values and on M values. CpGs are called at a Benjamini-Hochberg adjusted p-value below 0.05. The t-test is computed for all CpGs at once from the same linear model fit, the way the example on the eBayes help page computes its ordinary t-statistic; the chunk below checks it against t.test(). It also checks that limma-trend’s covariate is the row mean, and that every CpG has the same residual degrees of freedom, so that limma 3.58 and 3.66 estimate the prior the same way (with missing values, and so unequal degrees of freedom, 3.66 switches to a newer estimator).

# the shortcut t-test above equals t.test() with equal variances
x <- example_ln$M[1:5, ]
all.equal(unname(ordinary_p(lmFit(x, design))),
          apply(x, 1, function(r) t.test(r[group == "B"], r[group == "A"], var.equal = TRUE)$p.value))
[1] TRUE
# limma-trend uses the row means (Amean) as the covariate, and every CpG has the same residual df
fm <- lmFit(example_ln$M, design)
c(amean_is_rowmean = isTRUE(all.equal(fm$Amean, rowMeans(example_ln$M))),
  equal_df = length(unique(fm$df.residual)) == 1)
amean_is_rowmean         equal_df 
            TRUE             TRUE 

Each combination of variance model and mix gets 10 data sets (the check with the even spread uses 10,000 CpGs per data set).

n_sets <- 10                                     # data sets per variance model and mix
set.seed(20260930)
runs <- list()
for (mix in c("array", "even")) {
  for (model in c("logit-normal", "beta")) {
    for (k in seq_len(n_sets)) {
      d <- simulate_cpgs(model, mix, if (mix == "array") n_cpg else n_cpg_even)
      if (k == 1 && model == "logit-normal") {
        if (mix == "array") example_ln <- d else example_even <- d
      }
      if (k == 1 && model == "beta" && mix == "array") example_bt <- d
      runs[[length(runs) + 1]] <- cbind(mix = mix, model = model, set = k, analyse(d))
    }
  }
}
runs <- do.call(rbind, runs)
Bookkeeping: rates by methylation level
# sums over data sets, by model x method x stratum
band_of <- function(st) ifelse(st %in% c("0-0.1", "0.9-1"), "extreme",
                                ifelse(st == "0.3-0.7", "middle", "between"))
runs$band <- band_of(runs$stratum)
cols <- "cbind(null_n, null_p05, dm_n, dm_call, big_n, big_call, call_n, call_null, call_tiny)"
S <- aggregate(as.formula(paste(cols, "~ mix + model + method + stratum")), data = runs, FUN = sum)
S$band <- band_of(S$stratum)
B <- aggregate(as.formula(paste(cols, "~ mix + model + method + band")), data = S, FUN = sum)
Tot <- aggregate(as.formula(paste(cols, "~ mix + model + method")), data = S, FUN = sum)
rate <- function(tab, mod, meth, col, den, band = NULL, mx = "array") {
  keep <- tab$mix == mx & tab$model == mod & tab$method == meth
  if (!is.null(band)) keep <- keep & tab$band %in% band
  r <- tab[keep, ]
  sum(r[[col]]) / sum(r[[den]])
}
per_set <- function(mod, meth, mx = "array")
  sum(Tot$call_n[Tot$mix == mx & Tot$model == mod & Tot$method == meth]) / n_sets

# residual SD and prior df, from the first logit-normal data set
fb1 <- lmFit(example_ln$beta, design); fm1 <- lmFit(example_ln$M, design)
eb1 <- eBayes(fb1); em1 <- eBayes(fm1)
sd_beta_ext <- median(fb1$sigma[example_ln$stratum %in% c("0-0.1", "0.9-1")])
sd_beta_mid <- median(fb1$sigma[example_ln$stratum == "0.3-0.7"])
sd_m_ext <- median(fm1$sigma[example_ln$stratum %in% c("0-0.1", "0.9-1")])
sd_m_mid <- median(fm1$sigma[example_ln$stratum == "0.3-0.7"])
d0_beta <- eb1$df.prior; d0_m <- em1$df.prior
s0_beta <- sqrt(eb1$s2.prior)

ext <- "extreme"; mid <- "middle"; other <- c("middle", "between")
t1 <- function(mod, meth, band, mx = "array") rate(B, mod, meth, "null_p05", "null_n", band, mx)
pw <- function(mod, meth, band, mx = "array") rate(B, mod, meth, "dm_call", "dm_n", band, mx)
tiny_share <- function(mod, meth, band = NULL) {
  tab <- if (is.null(band)) Tot else B
  rate(tab, mod, meth, "call_tiny", "call_n", band)
}
big_power <- function(mod, meth) rate(Tot, mod, meth, "big_call", "big_n")
# range of the type I error over the five strata
t1_range <- function(mod, meth, mx = "array") {
  r <- S[S$mix == mx & S$model == mod & S$method == meth, ]
  range(r$null_p05 / r$null_n)
}
# Monte Carlo error of a pooled rate, from the spread between data sets (CpGs within a data set
# share one estimated prior, so they are not independent)
mc_se <- function(mod, meth, bnd, mx = "array") {
  r <- runs[runs$mix == mx & runs$model == mod & runs$method == meth & runs$band == bnd, ]
  per <- tapply(r$null_p05, r$set, sum) / tapply(r$null_n, r$set, sum)
  sd(per) / sqrt(length(per))
}
null_mid_n <- sum(B$null_n[B$mix == "array" & B$model == "logit-normal" & B$method == "limma, M" &
                           B$band == mid])
mc_se_max <- max(sapply(c("array", "even"), function(mx) sapply(c("logit-normal", "beta"),
  function(mod) sapply(c("limma, beta", "limma, M", "limma-trend, beta", "limma-trend, M"),
    function(meth) sapply(c(ext, mid), function(bnd) mc_se(mod, meth, bnd, mx))))))
t_rng <- range(sapply(c("array", "even"), function(mx) sapply(c("logit-normal", "beta"), function(mod)
  sapply(c("t-test, beta", "t-test, M"), function(meth) t1_range(mod, meth, mx)))))
trend_m_rng <- range(sapply(c("array", "even"), function(mx)
  sapply(c("logit-normal", "beta"), function(mod) t1_range(mod, "limma-trend, M", mx))))

# how many M units a delta-beta of 0.05 is, near the edge and in the middle
dM_at <- function(m) logit2(m + db_min / 2) - logit2(m - db_min / 2)
edge_centre <- 0.05
dM_edge <- dM_at(edge_centre); dM_mid <- dM_at(lfc_centre)
# the delta-beta that the fixed M threshold lfc_M allows at a mean of m_edge
dM_at_db <- function(m, db) logit2(m + db / 2) - logit2(m - db / 2)
db_for_lfc <- function(m) uniroot(function(db) dM_at_db(m, db) - lfc_M, c(1e-6, 2 * m - 1e-6))$root
m_edge <- 0.03
db_edge_lfc <- db_for_lfc(m_edge)

# named scalars quoted in the text; ln = logit-normal model, bt = beta model
ln <- "logit-normal"; bt <- "beta"
t1_b_ext <- t1(ln, "limma, beta", ext);  t1_b_mid <- t1(ln, "limma, beta", mid)
t1_m_ext <- t1(ln, "limma, M", ext);     t1_m_mid <- t1(ln, "limma, M", mid)
pw_b_ext <- pw(ln, "limma, beta", ext);  pw_m_ext <- pw(ln, "limma, M", ext)
pw_b_mid <- pw(ln, "limma, beta", mid);  pw_m_mid <- pw(ln, "limma, M", mid)
bt_t1_m_ext <- t1(bt, "limma, M", ext);  bt_t1_m_mid <- t1(bt, "limma, M", mid)
bt_t1_b_ext <- t1(bt, "limma, beta", ext); bt_t1_b_mid <- t1(bt, "limma, beta", mid)
bt_pw_m_ext <- pw(bt, "limma, M", ext);  bt_pw_tm_ext <- pw(bt, "limma-trend, M", ext)
bt_pw_m_mid <- pw(bt, "limma, M", mid);  bt_pw_tm_mid <- pw(bt, "limma-trend, M", mid)
trend_b_rng <- range(sapply(c(ln, bt), function(mod) t1_range(mod, "limma-trend, beta")))
tb_t1_ext <- t1(ln, "limma-trend, beta", ext); tb_t1_mid <- t1(ln, "limma-trend, beta", mid)
tb_pw_mid <- pw(ln, "limma-trend, beta", mid); tm_pw_mid <- pw(ln, "limma-trend, M", mid)
calls_tb_bt <- per_set(bt, "limma-trend, beta")
# the check with evenly spread means (ev_)
ev_b_ext <- t1(ln, "limma, beta", ext, "even"); ev_b_mid <- t1(ln, "limma, beta", mid, "even")
ev_pw_b_ext <- pw(ln, "limma, beta", ext, "even"); ev_pw_m_ext <- pw(ln, "limma, M", ext, "even")
ev_bt_m_ext <- t1(bt, "limma, M", ext, "even"); ev_bt_m_mid <- t1(bt, "limma, M", mid, "even")
d0_beta_even <- eBayes(lmFit(example_even$beta, design))$df.prior
calls_m_ln <- per_set(ln, "limma, M");   calls_t_m_ln <- per_set(ln, "t-test, M")
calls_tm_bt <- per_set(bt, "limma-trend, M"); calls_m_bt <- per_set(bt, "limma, M")
fdp_rng <- range(sapply(c(ln, bt), function(mod) sapply(c("limma, beta", "limma, M"),
  function(meth) rate(Tot, mod, meth, "call_null", "call_n"))))
calls_t_b_ln <- per_set(ln, "t-test, beta"); calls_b_ln <- per_set(ln, "limma, beta")

tiny_m_ext <- tiny_share(ln, "limma, M", ext); tiny_m_oth <- tiny_share(ln, "limma, M", other)
tiny_trM_ext <- tiny_share(ln, "treat on M", ext); tiny_trM_oth <- tiny_share(ln, "treat on M", other)
filt <- "limma, M, then |delta-beta| filter"
tiny_filt <- tiny_share(ln, filt); tiny_trB <- tiny_share(ln, "treat on beta")
bt_tiny_filt <- tiny_share(bt, filt); bt_tiny_trB <- tiny_share(bt, "treat on beta")
big_filt <- big_power(ln, filt); big_trB <- big_power(ln, "treat on beta")
calls_filt <- per_set(ln, filt); calls_trB <- per_set(ln, "treat on beta")
calls_trM <- per_set(ln, "treat on M")
tiny_b_ext <- tiny_share(ln, "limma, beta", ext)
bx <- B[B$mix == "array" & B$model == ln & B$method == "limma, M" & B$band == ext, ]
real_tiny_ext <- (bx$call_tiny - bx$call_null) / bx$call_tiny   # true change, but below db_min

Beta or M with limma: the type I error by methylation level

For a well-calibrated test, an unchanged CpG gets p < 0.05 one time in twenty, wherever it sits. The Monte Carlo standard error of the pooled rates quoted below, estimated from the spread between data sets, is at most 0.25 percentage points; with the array-like mix there are 27,401 unchanged CpGs in the middle band per model.

show <- c("limma, beta", "limma, M", "limma-trend, beta", "limma-trend, M")
f1 <- S[S$mix == "array" & S$method %in% show, ]
f1$rate <- f1$null_p05 / f1$null_n
f1$model <- factor(ifelse(f1$model == "logit-normal", "logit-normal model (M SD constant)",
                          "beta model (beta precision constant)"),
                   levels = c("logit-normal model (M SD constant)",
                              "beta model (beta precision constant)"))
f1$method <- factor(f1$method, levels = show)
ggplot(f1, aes(stratum, rate, colour = method, shape = method, group = method)) +
  geom_hline(yintercept = 0.05, linetype = "dashed", colour = grey) +
  geom_line(aes(linetype = method), linewidth = 0.8) + geom_point(size = 2.6) +
  facet_wrap(~ model) +
  scale_colour_manual(values = c(magenta, violet, "#a3327f", dark), name = NULL) +
  scale_shape_manual(values = c(16, 17, 1, 2), name = NULL) +
  scale_linetype_manual(values = c("solid", "solid", "dashed", "dashed"), name = NULL) +
  scale_y_continuous(labels = function(x) paste0(100 * x, "%")) +
  labs(x = "true mean methylation of the CpG (beta)", y = "null CpGs with p < 0.05") +
  guides(colour = guide_legend(nrow = 2), shape = guide_legend(nrow = 2),
         linetype = guide_legend(nrow = 2)) +
  theme_pc
Two line charts. Left, logit-normal model: limma on beta values is a little below the grey dashed nominal line at both ends of the methylation range and well above it in the middle, limma-trend on beta values dips below the line in the middle, and both M-value lines sit on the line. Right, beta model: limma on M values is above the line at both ends and far below it in the middle, roughly the mirror image of limma on beta values, while limma-trend on M values stays close to the line throughout.
Figure 1: Share of unchanged CpGs with p < 0.05 by true mean methylation, array-like mix, for limma and limma-trend on beta and M values. The grey dashed line is the nominal rate. In the left panel the two M-value lines lie on top of each other.

Under the logit-normal model, limma on beta values gives too many small p-values in the middle (6.9%) and slightly too few at the extremes (3.8%); on M values it holds 5.0% and 4.9%. The cause is the shared prior. In the first data set, the median residual standard deviation on the beta scale was 0.015 at the extremes and 0.065 in the middle, 4.2 times larger; on the M scale it was 0.40 and 0.40. With most CpGs at the extremes, limma’s single prior value lands near their standard deviation (0.016 on the beta scale), so the extremes come out only a little conservative, while the variances in the middle are pulled far down and produce false positives. limma partly notices the misfit: each CpG has 10 residual degrees of freedom of its own, and the prior counted as 1.7 extra degrees of freedom on beta values against 9.5 on M values. Near the ends, limma on M values found 87% of the truly changed CpGs and limma on beta values 82%.

How large each error is depends on the mix. With the means spread evenly, the extremes are a smaller share of the CpGs, the prior moves up, and limma on beta values gave 1.1% at the extremes and 6.8% in the middle, finding 60% of the changed CpGs near the ends against 79% on M values. The excess in the middle is there under both mixes; the deficit at the ends is a property of the mix.

In this simulation the per-CpG t-test kept its type I error between 4.6% and 5.3% at every level, on both scales, under both models and both mixes, so the scale mattered mainly through limma’s shared prior. That sharing is worth having: under the logit-normal model limma on M values called 1,628 CpGs per data set against 1,533 for the t-test on M values, at the same false discovery rate. The overall false discovery proportion of limma stayed between 4.1% and 4.7% on both scales and under both models; the scale changes which CpGs are called more than how many of the calls are false.

When M values are the heteroscedastic scale

The right panel of the figure is the same analysis under the beta model, and there the pattern turns over. limma on M values gives 5.9% at the extremes and 2.1% in the middle, roughly the mirror image of limma on beta values (3.7% and 7.9%). Here the logit does not remove the heteroscedasticity; it reverses it, because a CpG near 0 with a little beta-scale noise becomes a CpG with a lot of M-scale noise. With the means spread evenly, plain limma on M values gave 7.7% at the extremes and 3.7% in the middle.

limma has an option for exactly this situation. With trend = TRUE, eBayes() estimates the prior variance as a smooth function of each CpG’s average value (Amean, the row mean of the matrix that was fitted) instead of as one number; this is limma-trend, which the limma help page attributes to Law et al. (2014), who used it for RNA-seq. On M values, limma-trend kept the type I error between 4.5% and 5.4% at every level, under both models and both mixes. Under the logit-normal model it changed almost nothing, since there was no trend to find. Under the beta model it called 1,323 CpGs per data set against 1,210 for plain limma on M values, and in the middle its power rose from 24% to 38%.

limma-trend on beta values is not far behind. With the array-like mix its type I error stayed between 3.8% and 6.2% under both models, and under the beta model it called 1,288 CpGs per data set. Its weak spot is the middle of the range under the logit-normal model, where it was conservative (3.8%) and found 34% of the changed CpGs against 40% for limma-trend on M values. With the trend switched on, the choice of scale matters much less than the choice between plain limma and limma-trend.

Which model describes your data is an empirical question, and plotSA() answers it: it plots each CpG’s residual standard deviation (on a square-root scale) against its average value, with the fitted trend.

op <- par(mfrow = c(1, 2), mar = c(4.2, 4.2, 2.2, 1))
plotSA(eBayes(lmFit(example_ln$M, design), trend = TRUE), main = "logit-normal model",
       xlab = "average M value", pch = 16, cex = 0.3, col = c(grey, magenta))
plotSA(eBayes(lmFit(example_bt$M, design), trend = TRUE), main = "beta model",
       xlab = "average M value", pch = 16, cex = 0.3, col = c(grey, magenta))
par(op)
Two scatter plots of the square root of the residual standard deviation against the average M value. Left, logit-normal model: a flat band of points with a flat blue line. Right, beta model: the band and the blue line rise towards both ends of the M range in a U shape.
Figure 2: limma’s plotSA() for limma-trend fits on M values, one data set from each variance model. Each point is a CpG; the blue line is the fitted trend of the prior variance.

A flat cloud means the variance does not depend on the methylation level on the scale you fitted, and trend = TRUE is harmless; a U or an arch means it does, and the trend is needed. The table collects all six analyses for the array-like mix; power is the share of truly changed CpGs that were called.

model analysis type I error, extremes type I error, middle power, extremes power, middle
logit-normal t-test, beta 4.8% 5.1% 81% 32%
logit-normal t-test, M 4.9% 5.0% 84% 32%
logit-normal limma, beta 3.8% 6.9% 82% 39%
logit-normal limma, M 4.9% 5.0% 87% 40%
logit-normal limma-trend, beta 4.7% 3.8% 86% 34%
logit-normal limma-trend, M 4.9% 5.0% 87% 40%
beta t-test, beta 4.7% 5.2% 58% 32%
beta t-test, M 4.9% 5.2% 58% 30%
beta limma, beta 3.7% 7.9% 63% 42%
beta limma, M 5.9% 2.1% 65% 24%
beta limma-trend, beta 4.8% 4.3% 67% 36%
beta limma-trend, M 4.9% 4.5% 69% 38%

What to report: delta-beta, not the M difference

An M-value difference is a log2 odds ratio: how much the ratio of methylated to unmethylated signal changed. How much methylation changed depends on where the CpG sits, which is why a list of significant CpGs sorted by M difference is hard to read. The effect size a reader understands is the delta-beta, the difference in mean beta value between the groups: fit the same design to the beta values and read the coefficient.

fit_b <- lmFit(example_ln$beta, design)
fit_m <- eBayes(lmFit(example_ln$M, design))
hit <- p.adjust(fit_m$p.value[, 2], "BH") < fdr
h <- data.frame(mean_beta = fit_b$Amean[hit], obs_db = fit_b$coefficients[hit, 2],
                truth = ifelse(abs(example_ln$true_db[hit]) < db_min,
                               paste("true |delta-beta| below", db_min),
                               paste("true |delta-beta|", db_min, "or more")))
n_hits <- nrow(h)
n_hits_small <- sum(abs(h$obs_db) < db_min)
n_hits_small_edge <- sum(abs(h$obs_db) < db_min & (h$mean_beta < 0.1 | h$mean_beta > 0.9))
ggplot(h, aes(mean_beta, obs_db, colour = truth)) +
  annotate("rect", xmin = 0, xmax = 1, ymin = -db_min, ymax = db_min,
           fill = grey, alpha = 0.15) +
  geom_point(size = 1.6, alpha = 0.8) +
  scale_colour_manual(values = c(violet, magenta), name = NULL) +
  labs(x = "average beta value of the CpG", y = "observed delta-beta (B minus A)") +
  theme_pc
A scatter plot shaped like a ring, with most points crowded near both ends of the methylation range. Called CpGs in the middle of the range have large positive or negative delta-beta, and a few of them are pink although they sit far from zero. Near both ends the points bend towards zero, and a dense group of pink points sits inside the grey band around zero.
Figure 3: CpGs called by limma on M values in one data set from the logit-normal model, by average beta value and observed delta-beta. The grey band marks observed delta-beta values smaller than the cutoff in absolute value; pink points are CpGs whose true change is smaller than the cutoff.

In this data set limma on M values called 1,610 CpGs. Of these, 186 had an observed delta-beta smaller than 0.05 in absolute value, and all but 2 of those had an average beta value below 0.1 or above 0.9. The few pink points in the middle of the range are the opposite case: small true changes, or none, that look large because of noise, and a filter on the observed delta-beta keeps them. Across all data sets, 20% of the CpGs called at the extremes had a true delta-beta below 0.05, against 5% elsewhere (these shares include the false positives). Most of them are real changes (75% of the small-change calls at the extremes were not null): near 0 or 1 a shift of a few percentage points is large compared with the variance, and M values detect it well. They are just smaller than most people expect from “significant”. The beta-value analysis has fewer of them (15% of its calls at the extremes) because its prior inflates the variance there a little, not because it knows they are small.

A threshold on M is not a threshold on delta-beta

If the claim you want is “methylation changed by at least 0.05”, the usual advice is to put the threshold into the test with limma’s treat() rather than filtering the list afterwards (McCarthy and Smyth 2009). The natural first attempt is treat() on the M-value fit, with the threshold set to the M difference that equals a delta-beta of 0.05 at 50% methylation, 0.289 M units. The figure shows why that does not express the claim.

m <- seq(0.03, 0.97, by = 0.005)
tr <- data.frame(mean_beta = m, dM = logit2(m + db_min / 2) - logit2(m - db_min / 2))
ggplot(tr, aes(mean_beta, dM)) +
  geom_hline(yintercept = lfc_M, linetype = "dashed", colour = magenta, linewidth = 0.8) +
  geom_line(colour = violet, linewidth = 1) +
  labs(x = "mean methylation (beta)", y = paste("M difference for a delta-beta of", db_min)) +
  theme_pc
A U-shaped violet curve that is lowest in the middle of the methylation range and rises steeply towards both ends. A flat dashed pink line touches the curve at its lowest point, so everywhere else the curve lies above the line.
Figure 4: The M-value difference that equals a fixed delta-beta, by mean methylation (violet), and a fixed M-value threshold chosen to match it at 50% methylation (dashed pink).

At a mean of 0.03, the same 0.289 M units correspond to a delta-beta of only 0.0058. In the simulation, 11.8% of the CpGs that treat() on M values called at the extremes had a true delta-beta below 0.05, against 0.9% elsewhere. A fixed M threshold asks for a fixed change in odds, which is a different question.

A threshold on delta-beta is most directly tested on the beta scale. On a fit to beta values, treat() measures its threshold in the units of the coefficient, so lfc = 0.05 means a delta-beta of 0.05; the chunk below rebuilds its p-values by hand to confirm that. That fit uses trend = TRUE, for the reason shown above: plain limma on beta values gets the variance wrong at some methylation levels.

# treat() measures its threshold in the units of the coefficient: on a beta-value fit,
# lfc = 0.05 is a delta-beta of 0.05. Rebuild its p-values by hand to confirm.
tf <- treat(fit_b, lfc = db_min, trend = TRUE)
se <- tf$stdev.unscaled[, 2] * sqrt(tf$s2.post)
a <- abs(tf$coefficients[, 2])
p_hand <- pt((a - db_min) / se, tf$df.total, lower.tail = FALSE) +
  pt((a + db_min) / se, tf$df.total, lower.tail = FALSE)
all.equal(unname(p_hand), unname(tf$p.value[, 2]))
[1] TRUE

With trend = TRUE for the variance, treat() on beta values called 972 CpGs per data set under the logit-normal model, and 0.07% of them had a true delta-beta below 0.05 (0.08% under the beta model). It is strict: it found 61% of the CpGs whose true delta-beta was at least 0.05. Filtering the limma M-value list afterwards at an observed delta-beta of 0.05 kept 1,440 CpGs per data set and found 87% of those CpGs, and 4.7% of its calls had a true delta-beta below the cutoff (4.0% under the beta model). The filter did well here, but nothing in it controls that share: it depends on how many true changes sit just below the cutoff, and in this simulation, with changes spread evenly up to 0.2, few do. The treat() help page warns that the test is much more conservative than a cutoff on the estimate, and advises choosing the threshold as a small value below which results should be ignored rather than as a target. For a formal claim, use treat() on beta values with a modest threshold; for a list, filter by delta-beta and say that you did. limma 3.66 (Bioconductor 3.22) adds treat(upshot = TRUE), which its help page describes as a more powerful test that still controls the error rate when the true changes inside the threshold interval have a unimodal distribution; the numbers here use the classic test, the default in both versions.

What to do in practice

Test on M values with limma-trend, and look at plotSA(): the trend costs little when there is none to fit. Report the delta-beta from a fit to the beta values next to the adjusted p-value from the M values. Put a delta-beta threshold into a test only when the claim needs it, and then most directly on the beta scale.

# beta: CpG x sample matrix of beta values; design: your model matrix
b <- pmin(pmax(beta, 0.001), 0.999)     # a beta of exactly 0 or 1 has no finite M value
M <- log2(b / (1 - b))                  # or the M values from your preprocessing
fit_m <- eBayes(lmFit(M, design), trend = TRUE)
plotSA(fit_m)                           # flat line: trend = TRUE changes little; curved: keep it
fit_b <- lmFit(beta, design)            # same design on beta values: coefficients are delta-beta
res <- data.frame(delta_beta = fit_b$coefficients[, 2],
                  p_value = fit_m$p.value[, 2],
                  adj_p = p.adjust(fit_m$p.value[, 2], "BH"))
# only if the claim is "changed by at least 0.05 in beta":
tr <- treat(fit_b, lfc = 0.05, trend = TRUE)
res$adj_p_treat <- p.adjust(tr$p.value[, 2], "BH")

One caveat about scope. Both variance models here are simple, with 6 samples per group and no other covariates. Real arrays add probe-type differences and cell-composition effects, which are separate problems and are not covered here.

References

Du P, Zhang X, Huang CC et al. 2010 BMC Bioinformatics 11(1):587 (doi:10.1186/1471-2105-11-587)

Smyth GK 2004 Statistical Applications in Genetics and Molecular Biology 3(1):1-25 (doi:10.2202/1544-6115.1027)

Law CW, Chen Y, Shi W et al. 2014 Genome Biology 15(2):R29 (doi:10.1186/gb-2014-15-2-r29)

McCarthy DJ, Smyth GK 2009 Bioinformatics 25(6):765-771 (doi:10.1093/bioinformatics/btp053)

The numbers on this page were computed with the versions below.

R version 4.5.3 (2026-03-11)
Bioconductor 3.22
ggplot2 4.0.4, limma 3.66.0
Download the R codeReport a problem

The R file runs the post top to bottom in a fresh session. Spotted an error, a broken number or code that no longer runs? The report link opens an email to contact@pseudocount.com.