| Title: | Beta Regression Cosinor Models for Circadian Methylation Analysis |
|---|---|
| Description: | Fits beta cosinor models to methylation measurements using penalized quasi-likelihood (PQL), an optional subject random intercept, adjustment covariates, and an optional empirical Bayes (EB) prior on log precision. Tests rhythmicity with a null-model score test and estimates rhythm parameters from a separate full-model fit. |
| Authors: | Yixiang Hong [aut, cre] |
| Maintainer: | Yixiang Hong <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.99.3 |
| Built: | 2026-11-08 15:57:06 UTC |
| Source: | https://github.com/bioc/RhyME |
Fits beta cosinor models using PQL, with optional random intercepts, adjustment covariates, and an empirical Bayes (EB) prior on log precision. A null-model score test assesses rhythmicity; a full model estimates rhythm parameters.
fitCosinor( se, time_col = "time", subject_col = NULL, assay_name = NULL, period = 24, prior = c("auto", "none"), BPPARAM = BiocParallel::bpparam(), verbose = TRUE, covariates = NULL )fitCosinor( se, time_col = "time", subject_col = NULL, assay_name = NULL, period = 24, prior = c("auto", "none"), BPPARAM = BiocParallel::bpparam(), verbose = TRUE, covariates = NULL )
se |
A |
time_col |
Name of the collection-time column in |
subject_col |
Name of the subject column for a random-intercept
model, or |
assay_name |
Assay name, or |
period |
Oscillation period in hours. Default is 24. |
prior |
|
BPPARAM |
A |
verbose |
Whether to print fitting progress. |
covariates |
Names of numeric or categorical |
The input SummarizedExperiment with these rowData(se) columns:
RhyME_b0, RhyME_b_sin, RhyME_b_cos: logit-scale intercept and
sine/cosine coefficients.
RhyME_log_phi, RhyME_tau: log precision and random-intercept SD.
RhyME_score_chisq, RhyME_pvalue, RhyME_padj: score statistic, p-value, and
BH-adjusted p-value across all input CpGs.
RhyME_logit_amplitude, RhyME_amplitude: logit-scale amplitude and half the
marginal mean curve's peak-to-trough difference on the methylation scale.
RhyME_phase, RhyME_mesor: peak time in hours in
and the marginal mean curve averaged over one period.
RhyME_converged: whether both null and full fits converged.
Unusable null fits have NA p-values; unusable full fits have NA
parameter estimates. Usable results from either fit are retained.
Phase is undefined at zero amplitude. Existing row annotations are retained;
refitting replaces only the result columns listed above. Unprefixed columns
from earlier versions are retained as annotations.
metadata(se)$RhyME stores design, ebPrior, and fitSummary.
# Independent samples: default fixed-effects model and automatic EB prior. set.seed(123) n_cpg <- 1200 time <- rep(seq(0, 20, by = 4), 8) amplitude <- c(rep(0.6, 240), rep(0, 960)) mu <- plogis(outer(amplitude, sin(2 * pi * time / 24))) beta <- matrix(rbeta(length(mu), mu * 40, (1 - mu) * 40), nrow = n_cpg, dimnames = list(paste0("cg", seq_len(n_cpg)), paste0("sample", seq_along(time)))) se_independent <- SummarizedExperiment::SummarizedExperiment( assays = list(beta = beta), colData = S4Vectors::DataFrame(time = time)) fit_fixed <- fitCosinor(se_independent, BPPARAM = BiocParallel::SerialParam(), verbose = FALSE) S4Vectors::metadata(fit_fixed)$RhyME$ebPrior # Repeated measurements: disable EB for this small subset. ex <- readRDS(system.file("extdata", "example_data.rds", package = "RhyME")) fit <- fitCosinor(ex$se[seq_len(5), ], subject_col = "subject", prior = "none", verbose = FALSE) head(SummarizedExperiment::rowData(fit), 3)# Independent samples: default fixed-effects model and automatic EB prior. set.seed(123) n_cpg <- 1200 time <- rep(seq(0, 20, by = 4), 8) amplitude <- c(rep(0.6, 240), rep(0, 960)) mu <- plogis(outer(amplitude, sin(2 * pi * time / 24))) beta <- matrix(rbeta(length(mu), mu * 40, (1 - mu) * 40), nrow = n_cpg, dimnames = list(paste0("cg", seq_len(n_cpg)), paste0("sample", seq_along(time)))) se_independent <- SummarizedExperiment::SummarizedExperiment( assays = list(beta = beta), colData = S4Vectors::DataFrame(time = time)) fit_fixed <- fitCosinor(se_independent, BPPARAM = BiocParallel::SerialParam(), verbose = FALSE) S4Vectors::metadata(fit_fixed)$RhyME$ebPrior # Repeated measurements: disable EB for this small subset. ex <- readRDS(system.file("extdata", "example_data.rds", package = "RhyME")) fit <- fitCosinor(ex$se[seq_len(5), ], subject_col = "subject", prior = "none", verbose = FALSE) head(SummarizedExperiment::rowData(fit), 3)
Plots observed beta values and fitted marginal mean curves over the
observed time range, using the design saved by fitCosinor(). Curves
describe the mean covariate profile; points are not covariate-adjusted.
plotCosinorFit(se, cpgs = NULL, ncol = 3)plotCosinorFit(se, cpgs = NULL, ncol = 3)
se |
A |
cpgs |
CpG identifiers in panel order. |
ncol |
Number of panels per row. |
A ggplot2 object.
ex <- readRDS(system.file("extdata", "example_data.rds", package = "RhyME")) fit <- fitCosinor(ex$se[1, ], subject_col = "subject", prior = "none", verbose = FALSE) plotCosinorFit(fit)ex <- readRDS(system.file("extdata", "example_data.rds", package = "RhyME")) fit <- fitCosinor(ex$se[1, ], subject_col = "subject", prior = "none", verbose = FALSE) plotCosinorFit(fit)