| Title: | Estimate Sleep Status from Accelerometry Data |
|---|---|
| Description: | Wraps the classifier from the Sundararajan (2021) <doi:10.1038/s41598-020-79217-x> to estimate sleep using a random forest. Users must download the model files from Sundararajan (2020) <doi:10.5281/zenodo.3752645> in order to use this method. |
| Authors: | John Muschelli [aut, cre] (ORCID: <https://orcid.org/0000-0001-6469-1750>) |
| Maintainer: | John Muschelli <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.5.0 |
| Built: | 2026-09-18 12:15:59 UTC |
| Source: | https://github.com/cran/sleeper |
estimate_sleep with PythonRun estimate_sleep with Python
py_estimate_sleep( ..., pyenv_function = function() { sleeper::py_require_sleeper() }, show = FALSE )py_estimate_sleep( ..., pyenv_function = function() { sleeper::py_require_sleeper() }, show = FALSE )
... |
arguments to pass to estimate_sleep |
pyenv_function |
function that loads the forest Python package.
By default, it uses py_require_sleeper to import
the package. If this function has an |
show |
Logical, whether to show the standard output on the
screen while the child process is running, passed to |
Output from estimate_sleep(),
a tibble of times and classification of sleep.
py_require for the full sleeper workflowCommand for py_require for the full sleeper workflow
py_require_sleeper(...)py_require_sleeper(...)
... |
arguments to pass to |
A logical value indicating whether the package is available.
Compact Example Sleep Models
sl_example_model( model_dir = file.path(tempdir(), "sleeper-example-models"), overwrite = FALSE )sl_example_model( model_dir = file.path(tempdir(), "sleeper-example-models"), overwrite = FALSE )
model_dir |
Directory in which to save the example models. |
overwrite |
Logical; overwrite files that are already present. |
The downloaded model paths, or NULL when a download fails.
models = sl_example_model()models = sl_example_model()
Get Sleep Features
sl_features(data)sl_features(data)
data |
A |
A tibble of times and classification of sleep.
file = system.file("extdata", "example_data.csv.gz", package = "sleeper") if (requireNamespace("readr", quietly = TRUE)) { data = readr::read_csv(file, n_max = 3600L) feat = sl_features(data) }file = system.file("extdata", "example_data.csv.gz", package = "sleeper") if (requireNamespace("readr", quietly = TRUE)) { data = readr::read_csv(file, n_max = 3600L) feat = sl_features(data) }
Check for Downloaded Sleep Models
sl_have_models(model_dir) sl_download_models( model_dir, quiet = FALSE, ..., overwrite = FALSE, folds = 1:5 )sl_have_models(model_dir) sl_download_models( model_dir, quiet = FALSE, ..., overwrite = FALSE, folds = 1:5 )
model_dir |
path to the folder with models from doi:10.5281/zenodo.3752645 |
quiet |
argument passed to curl::curl_download |
... |
additional arguments to pass to curl::curl_download |
overwrite |
logical, if |
folds |
should all model folds be downloaded? If only some folds, specify that (used almost exclusively for testing). |
A logical indicating all folds are downloaded.
Estimate Sleep from Wrist-Worn Accelerometry
sl_python_modules_installed(component = c("models", "features")) estimate_sleep(data, epoch = 30L, model_dir, cores = 1L)sl_python_modules_installed(component = c("models", "features")) estimate_sleep(data, epoch = 30L, model_dir, cores = 1L)
component |
Python dependency set to check. The default, |
data |
A |
epoch |
Time in seconds for the time interval estimate |
model_dir |
path to the folder with models from doi:10.5281/zenodo.3752645 |
cores |
Number of workers to use for model prediction. Any non-zero
integer accepted by Python |
A tibble of times and classification of category.
if (sl_python_modules_installed("models")) { models = sl_example_model() if (!is.null(models) && requireNamespace("readr", quietly = TRUE)) { file = system.file("extdata", "example_data.csv.gz", package = "sleeper") data = readr::read_csv(file, n_max = 3600L) # Two minutes is sufficient to demonstrate the workflow and avoids # applying the forest to the full 12-hour example recording. try({estimate_sleep(data, model_dir = dirname(models$binary[1]))}) } }if (sl_python_modules_installed("models")) { models = sl_example_model() if (!is.null(models) && requireNamespace("readr", quietly = TRUE)) { file = system.file("extdata", "example_data.csv.gz", package = "sleeper") data = readr::read_csv(file, n_max = 3600L) # Two minutes is sufficient to demonstrate the workflow and avoids # applying the forest to the full 12-hour example recording. try({estimate_sleep(data, model_dir = dirname(models$binary[1]))}) } }