Wraps the 'AcceleRest' model from Lorenzen et al. (2026)
The goal of rester is to estimate sleep stages and respiratory events
from wrist-worn accelerometry. It wraps the AcceleRest model from
https://github.com/NielsRLorenzen/AcceleRest, which predicts, for each
30-second epoch:
"linear_sleepstages") or an LSTM head ("lstm_sleepstages"), and"linear_respevents").The model is described in Lorenzen et
al. (2026);
please cite it when using rester (see citation("rester")).
The Python requirements (torch, actipy, etc.) are declared with
reticulate::py_require() when the package is loaded, so reticulate
sets up the Python environment automatically.
You can install the development version of rester from GitHub with:
# install.packages("remotes")
remotes::install_github("jhuwit/rester")
The AcceleRest code and pretrained weights are downloaded (not bundled)
into ar_cache_dir(), which can be set with
options(rester.cache_dir = ) or the RESTER_CACHE_DIR environment
variable:
library(rester)
ar_setup()
which runs ar_download_repo() (downloading and extracting the code)
and ar_download_weights(). The raw weights can be extracted with
ar_load_weights().
AcceleRest uses context windows of 256 epochs (about 2.1 hours), so at
least that much data is needed. estimate_rest() takes a data.frame
or a file:
library(rester)
data = ar_example_data(n_hours = 3)
out = estimate_rest(data, context_window_shift = 16L)
out$linear_sleepstages
file = "/path/to/device_file.gt3x.gz"
out = estimate_rest(file, context_window_shift = 32L)
context_window_shift = 1L averages predictions over the most windows
but is much slower on a CPU.
Data are read and preprocessed by ar_read(), which estimate_rest()
calls:
.cwa, .gt3x, GENEActiv/Genea/Matrix .bin) are read
with actiread, CSV files with
readr, and .h5 files (already preprocessed, as described in the
AcceleRest README) with h5py. Compressed files (.gz, .bz2,
.xz) are read directly, or decompressed to a temporary file if the
reader cannot handle them.actibase. Any gap left in the
data makes the predictions for every window covering it missing.actipy Python
module. Use detect_nonwear = TRUE to set non-wear to NA; otherwise
a device lying still off the wrist may be scored as sleep.The Python requirements (torch, actipy, etc.) are declared with
reticulate::py_require() when the package is loaded. On Intel Macs,
the last available torch is 2.2.2, which rester supports. On macOS,
rester sets KMP_DUPLICATE_LIB_OK=TRUE (if unset) so torch and
OpenMP-using readers can run in the same R session. py_estimate_rest()
runs estimate_rest() in a separate R process.
citation("rester")
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. doi:10.64898/2026.01.28.26345056
The tests use mocks and download nothing. To also run the real model,
which downloads the code, weights, and torch, set:
Sys.setenv(RESTER_FULL_TEST = "true", RESTER_TEST_CACHE_DIR = "/path/to/cache")
devtools::test()
On GitHub Actions, the full test runs on the ubuntu-latest (release)
job.