πŸ˜΅β€πŸ’« hypnoR

Hypnogram handling, plotting, and sleep architecture metrics for R β€” the staging-agnostic layer of the Circadia Lab ecosystem.

r-universe R License: MIT R CMD CHECK Coverage


⚠️ hypnoR is in early development and has not been formally tested. The API may change without notice, estimation results have not yet been validated against a reference implementation, and the package has not undergone peer review. Use with caution and verify outputs independently before using in any research context.


πŸ“– What is hypnoR?

hypnoR is the hypnogram layer of the Circadia Lab R ecosystem. It sits between raw signal sources and the integrated participant database, providing a common interface for sleep staging regardless of where the staging came from.

It accepts two staging resolutions:

All metric and plotting functions are resolution-agnostic: they compute every metric that is possible given the available stages and return NA (documented per-function) for metrics that need finer staging than what's available.

Downstream, hypnoR feeds into syncR::sync() as part of the unified participant-indexed database.

✨ Features

🚧 Coming soon

πŸ—‚οΈ Project Structure

hypnoR/
β”œβ”€β”€ R/
β”‚   β”œβ”€β”€ hypnoR-package.R        # package-level docs
β”‚   β”œβ”€β”€ new_hypnogram.R         # new_hypnogram() constructor
β”‚   β”œβ”€β”€ smooth.R                # smooth_hypnogram()
β”‚   β”œβ”€β”€ window_hypnogram.R      # window_hypnogram()
β”‚   β”œβ”€β”€ architecture.R          # compute_sleep_architecture()
β”‚   β”œβ”€β”€ cycles.R                # compute_cycles()
β”‚   β”œβ”€β”€ transitions.R           # compute_transitions()
β”‚   β”œβ”€β”€ read_hypnogram.R        # ingestion (not yet implemented)
β”‚   β”œβ”€β”€ plot.R                  # plot_hypnogram(), plot_architecture(),
β”‚   β”‚                           #   plot_transition_matrix()
β”‚   └── utils.R                 # internal helpers, stage colour palette
β”œβ”€β”€ tests/testthat/
β”œβ”€β”€ vignettes/
β”‚   β”œβ”€β”€ getting-started.Rmd
β”‚   └── articles/
β”‚       β”œβ”€β”€ mrpheus-integration.Rmd  # worked example: AASM/mrpheus
β”‚       └── zeitR-integration.Rmd    # worked example: coarse/zeitR
β”œβ”€β”€ man/figures/                # logo, favicon, card
β”œβ”€β”€ .github/workflows/          # R CMD CHECK + pkgdown/coverage CI
β”œβ”€β”€ _pkgdown.yml
└── DESCRIPTION

πŸš€ Getting Started

Prerequisites: R β‰₯ 4.1.

Install from r-universe (recommended β€” pre-built binaries):

install.packages(
  "hypnoR",
  repos = c("https://circadia-bio.r-universe.dev", "https://cloud.r-project.org")
)

Or install the development version from GitHub:

# install.packages("remotes")
remotes::install_github("circadia-bio/hypnoR")

To reproduce the vignettes with real evaluated output (rather than just the code), also install mrpheus and zeitR from their r-universe:

install.packages(
  c("mrpheus", "zeitR"),
  repos = c("https://circadia-bio.r-universe.dev", "https://cloud.r-project.org")
)

Basic workflow (see vignette("getting-started") for the full walkthrough, including where staging/result come from in each case):

library(hypnoR)

# From mrpheus (full AASM)
hyp <- new_hypnogram(mrpheus::export_hypnogram(staging, epoch_s = 30))

# ...or from zeitR (coarse) -- same functions from here on, either way
hyp <- new_hypnogram(zeitR::export_hypnogram(result))

hyp   <- smooth_hypnogram(hyp)          # optional cleanup
arch  <- compute_sleep_architecture(hyp)
trans <- compute_transitions(hyp)
cyc   <- compute_cycles(hyp)            # full AASM only

plot_hypnogram(hyp, cycles = cyc)
plot_architecture(arch)
plot_transition_matrix(trans$matrix)

πŸ“¦ Dependencies

Package Type Role
cli Imports User-facing messages and errors
stats Imports Faceting in plot_architecture()
tibble Imports Tidy output objects
utils Imports NSE variable declarations for ggplot2
ggplot2 Suggests Plotting β€” checked at runtime, not required to use the metric functions
mrpheus, zeitR Suggests Real-data vignettes (both on circadia-bio's r-universe)
covr, testthat Suggests Test coverage and the test suite
knitr, rmarkdown, pkgdown Suggests Vignettes and documentation site

πŸ‘₯ Authors

Role Name
Author, maintainer Lucas FranΓ§a
Author Mario Leocadio-Miguel

Circadia Lab, Northumbria University.

🀝 Related Tools

πŸ“„ Licence

Released under the MIT License.

Copyright Β© Lucas FranΓ§a, Mario Leocadio-Miguel, 2026