estimate_rest: Estimate Sleep Stages and Respiratory Events with AcceleRest

View source: R/estimate_rest.R

estimate_restR Documentation

Estimate Sleep Stages and Respiratory Events with AcceleRest

Description

Runs the AcceleRest model on 30-second epochs of wrist-worn accelerometry. Predictions are made over context windows of 256 epochs (about 2.1 hours), so at least that much data is needed; predictions for an epoch are averaged across the overlapping windows covering it.

Usage

estimate_rest(
  file,
  model = NULL,
  cache_dir = ar_cache_dir(),
  repo_dir = cache_dir,
  weights_dir = cache_dir,
  context_window_shift = 1L,
  max_batch_size = 16L,
  device = NULL,
  ...
)

Arguments

file

a data.frame or file path, see ar_read(), or the output of ar_read()

model

the prediction heads to include, one or more of "linear_sleepstages", "lstm_sleepstages", and "linear_respevents". Defaults to all three.

cache_dir

directory with the downloaded code and weights, see ar_setup()

repo_dir

directory with the downloaded code, see ar_download_repo()

weights_dir

directory with the downloaded weights, see ar_download_weights()

context_window_shift

number of 30-second epochs to shift consecutive context windows. Smaller is slower but averages over more windows.

max_batch_size

number of context windows per forward pass. Higher is faster but uses more memory.

device

torch device, e.g. "cpu", "cuda", or "mps". If NULL, uses "cuda" if available, otherwise "cpu".

...

additional arguments passed to ar_read()

Value

A named list with a tibble for each head, with the epoch number, start time of the epoch (NA for .h5 files), the probability of each class, and the most probable class (prediction). Epochs with no valid data have NA values. Sleep stage classes are deep, light, rem, and wake; respiratory event classes are no_event and event. The actipy information about the data is in attr(x, "info").

References

Lorenzen NR, Brink-Kjaer A, Jennum PJ, Mignot E (2026). AcceleRest: A Physiology-Aware Masked Autoencoder for Wrist Accelerometer-based Sleep Staging and Apnea Evaluation. medRxiv. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.64898/2026.01.28.26345056")}

Examples


  # Runs only after ar_setup(), so Python is not set up otherwise
  if (ar_have_repo() && ar_have_weights("linear_sleepstages") &&
      ar_python_modules_installed()) {
    data = ar_example_data(n_hours = 2.5)
    out = estimate_rest(data, model = "linear_sleepstages",
                        context_window_shift = 32L)
    head(out$linear_sleepstages)
  }


rester documentation built on Nov. 13, 2026, 1:06 a.m.