| Title: | Create Metrics Actigraphy and Activity Analysis |
|---|---|
| Description: | Provides functions for calibrating, counting, and summarizing actigraphy and activity data into specific metrics and sleep measures. The metrics include activity counts, step counts, activity index, Monitor Independent Movement Summary Unit (MIMS), mean amplitude deviation (MAD), and provides wrappers for sleep estimation from activity counts using Tudor-Locke (2014) <doi:10.1139/apnm-2013-0173> and Sadeh (1994) <doi:10.1093/sleep/17.3.201>. |
| Authors: | John Muschelli [aut, cre] (ORCID: <https://orcid.org/0000-0001-6469-1750>) |
| Maintainer: | John Muschelli <[email protected]> |
| License: | GPL-3 |
| Version: | 0.7.0 |
| Built: | 2026-10-15 21:03:32 UTC |
| Source: | https://github.com/jhuwit/actimetrics |
Delegates to actigraph.sleepr::apply_tudor_locke(). Input must be
60-second epoch data with activity counts and a sleep state. Data from
acti_apply_cole_kripke() is accepted directly. Data labeled by
acti_apply_tudor_locke_diary() is also accepted: its logical sleep
column is converted to the S/W states expected downstream.
acti_apply_tudor_locke(data, ...)acti_apply_tudor_locke(data, ...)
data |
Epoch-level data containing activity counts and sleep state. |
... |
Arguments passed to |
A data frame summarizing detected sleep periods.
Adds a logical sleep column to epoch data from diary onset and wakeup times.
The result can be passed to acti_apply_tudor_locke() when it also has
activity counts and represents 60-second epochs. The wrapper converts the
logical diary labels to the S/W states required downstream.
acti_apply_tudor_locke_diary( data, sleep_diary, time_col = "time", diary_onset_col = "onset", diary_wakeup_col = "wakeup", sleep_col = "sleep" )acti_apply_tudor_locke_diary( data, sleep_diary, time_col = "time", diary_onset_col = "onset", diary_wakeup_col = "wakeup", sleep_col = "sleep" )
data |
Epoch-level data containing a POSIXct timestamp column. |
sleep_diary |
A data frame with POSIXct sleep onset and wakeup columns. Each interval may span midnight; multiple days are supported. |
time_col |
Name of the POSIXct timestamp column in |
diary_onset_col |
Name of the diary onset column. |
diary_wakeup_col |
Name of the diary wakeup column. |
sleep_col |
Name of the logical sleep column to add or replace. |
data with a logical sleep_col, TRUE from onset (inclusive) to
wakeup (exclusive).
Process Count Data
Process Count Data
acti_calculate_counts( data, epoch = 60L, resample = TRUE, lfe_select = FALSE, verbose = TRUE, fix_first_second = TRUE ) acti_calculate_wear( data, method = c("choi", "troiano"), use_magnitude = TRUE, ... ) acti_calculate_nonwear( data, method = c("choi", "troiano"), use_magnitude = TRUE, ... ) acti_apply_cole_kripke(data) acti_apply_sadeh(data, ...)acti_calculate_counts( data, epoch = 60L, resample = TRUE, lfe_select = FALSE, verbose = TRUE, fix_first_second = TRUE ) acti_calculate_wear( data, method = c("choi", "troiano"), use_magnitude = TRUE, ... ) acti_calculate_nonwear( data, method = c("choi", "troiano"), use_magnitude = TRUE, ... ) acti_apply_cole_kripke(data) acti_apply_sadeh(data, ...)
data |
A |
epoch |
epoch length in seconds. Default is 60 seconds.
See |
resample |
(recommended) resample the data to 30Hz using actibase::acti_resample vs. using the resampling method from agcounts::calculate_counts. |
lfe_select |
Apply the Actigraph Low Frequency Extension filter.
See |
verbose |
print diagnostic messages. Either logical or integer, where |
fix_first_second |
Fix the first second bug in |
method |
Method for detecting non-wear, either "choi" or "troiano",
corresponding to |
use_magnitude |
If |
... |
additional arguments to pass to |
A data.frame of transformed data
A data.frame of transformed data with columns axis1-3,
counts, and counts_log10.
A data.frame of transformed data
This calls the downstream wear-processing helpers used by
actigraph.sleepr
path = actiread::acti_example_gt3x() ac = actiread::acti_read_gt3x(path) out = acti_calculate_counts(ac) data = actimetrics::acti_count_data wear = actimetrics::acti_calculate_wear(data) tro_wear = actimetrics::acti_calculate_wear(data, method = "troiano") ck = actimetrics::acti_apply_cole_kripke(data) tl = actimetrics::acti_apply_tudor_locke(ck) sadeh = actimetrics::acti_apply_sadeh(ck)path = actiread::acti_example_gt3x() ac = actiread::acti_read_gt3x(path) out = acti_calculate_counts(ac) data = actimetrics::acti_count_data wear = actimetrics::acti_calculate_wear(data) tro_wear = actimetrics::acti_calculate_wear(data, method = "troiano") ck = actimetrics::acti_apply_cole_kripke(data) tl = actimetrics::acti_apply_tudor_locke(ck) sadeh = actimetrics::acti_apply_sadeh(ck)
Calculate Step Counts via Oak/Forest
acti_calculate_forest(data, ...)acti_calculate_forest(data, ...)
data |
A |
... |
Additional arguments passed to |
A tibble with minute-level time, steps columns.
Sys.setenv("SSQ_PARALLEL" = 0) if (reticulate::py_module_available("forest")) { data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = acti_calculate_forest(data, sample_rate = 100) }Sys.setenv("SSQ_PARALLEL" = 0) if (reticulate::py_module_available("forest")) { data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = acti_calculate_forest(data, sample_rate = 100) }
Calculate Summary Measures from Raw Accelerometer Data
acti_calculate_measures( data, unit = "1 min", fix_zeros = TRUE, dynamic_range = NULL, calculate_mims = TRUE, calculate_ac = TRUE, flag_data = TRUE, flags = NULL, ensure_all_time = TRUE, verbose = TRUE, sample_rate = NULL, ... ) acti_calculate_ai( data, unit = "1 min", ensure_all_time = TRUE, verbose = FALSE ) acti_calculate_activity_index( data, unit = "1 min", ensure_all_time = TRUE, verbose = FALSE ) acti_calculate_flags(data, unit = "1 min", ensure_all_time = TRUE) acti_calculate_n_idle(data, unit = "1 min", ensure_all_time = TRUE) acti_calculate_enmo(...) acti_calculate_ai_defined(...) acti_calculate_mad( data, unit = "1 min", ensure_all_time = TRUE, verbose = FALSE ) acti_calculate_auc( data, unit = "1 min", sample_rate = NULL, allow_truncation = FALSE, ensure_all_time = TRUE, verbose = TRUE ) acti_calculate_fast_mims( data, unit = "1 min", dynamic_range = NULL, sample_rate = NULL, allow_truncation = TRUE, ensure_all_time = TRUE, verbose = TRUE, ... ) acti_calculate_mims( data, unit = "1 min", dynamic_range = c(-6, 6), ensure_all_time = TRUE, ... )acti_calculate_measures( data, unit = "1 min", fix_zeros = TRUE, dynamic_range = NULL, calculate_mims = TRUE, calculate_ac = TRUE, flag_data = TRUE, flags = NULL, ensure_all_time = TRUE, verbose = TRUE, sample_rate = NULL, ... ) acti_calculate_ai( data, unit = "1 min", ensure_all_time = TRUE, verbose = FALSE ) acti_calculate_activity_index( data, unit = "1 min", ensure_all_time = TRUE, verbose = FALSE ) acti_calculate_flags(data, unit = "1 min", ensure_all_time = TRUE) acti_calculate_n_idle(data, unit = "1 min", ensure_all_time = TRUE) acti_calculate_enmo(...) acti_calculate_ai_defined(...) acti_calculate_mad( data, unit = "1 min", ensure_all_time = TRUE, verbose = FALSE ) acti_calculate_auc( data, unit = "1 min", sample_rate = NULL, allow_truncation = FALSE, ensure_all_time = TRUE, verbose = TRUE ) acti_calculate_fast_mims( data, unit = "1 min", dynamic_range = NULL, sample_rate = NULL, allow_truncation = TRUE, ensure_all_time = TRUE, verbose = TRUE, ... ) acti_calculate_mims( data, unit = "1 min", dynamic_range = c(-6, 6), ensure_all_time = TRUE, ... )
data |
An object with columns |
unit |
length of time to calculate measures over. a character string
specifying a time unit or a multiple of a unit to be rounded to.
Valid base units are |
fix_zeros |
Should |
dynamic_range |
Dynamic range of the device, in gravity units |
calculate_mims |
Should MIMS units be calculated? |
calculate_ac |
Should Activity Counts from the |
flag_data |
Should the downstream overlay |
flags |
the flags to calculate,
passed to the downstream overlay |
ensure_all_time |
if |
verbose |
print diagnostic messages |
sample_rate |
sample rate of data, if not specified in header of object |
... |
additional arguments to pass to |
allow_truncation |
truncate small values |
A data set with the calculated features
file = actiread::acti_example_gt3x() res = actiread::acti_read_gt3x(file, verbose = FALSE) res = res[1:12000, ] measures = acti_calculate_measures( res, dynamic_range = NULL, calculate_mims = FALSE, calculate_ac = FALSE, flag_data = FALSE ) auc = acti_calculate_auc(res) mims = acti_calculate_mims(res, dynamic_range = NULL) if (requireNamespace("data.table", quietly = TRUE)) { dt = data.table::as.data.table(res) out = acti_calculate_measures(dt, calculate_mims = FALSE, flag_data = FALSE, calculate_ac = FALSE) }file = actiread::acti_example_gt3x() res = actiread::acti_read_gt3x(file, verbose = FALSE) res = res[1:12000, ] measures = acti_calculate_measures( res, dynamic_range = NULL, calculate_mims = FALSE, calculate_ac = FALSE, flag_data = FALSE ) auc = acti_calculate_auc(res) mims = acti_calculate_mims(res, dynamic_range = NULL) if (requireNamespace("data.table", quietly = TRUE)) { dt = data.table::as.data.table(res) out = acti_calculate_measures(dt, calculate_mims = FALSE, flag_data = FALSE, calculate_ac = FALSE) }
Calculate Step Counts via Oak/Forest
acti_calculate_sdt(data, sample_rate = NULL, ...)acti_calculate_sdt(data, sample_rate = NULL, ...)
data |
A |
sample_rate |
Sample rate in Hz. If omitted, it is taken from the input object when available. |
... |
Additional arguments passed to |
A tibble with minute-level time, steps columns.
data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = acti_calculate_sdt(data)data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = acti_calculate_sdt(data)
stepcount
Use the stepcount package to estimate steps from raw accelerometer data
and summarize them to minute-level epochs (as opposed to 10s default)
acti_calculate_stepcount(data, sample_rate = NULL, ..., epoch = "1 minute")acti_calculate_stepcount(data, sample_rate = NULL, ..., epoch = "1 minute")
data |
A |
sample_rate |
Sample rate in Hz. If omitted, it is taken from the input object when available. |
... |
Additional arguments passed to |
epoch |
epoch unit to aggregate the data to, passed to
|
A tibble with minute-level time, steps, and walking
columns.
# reticulate::py_require("stepcount==3.11.0", python_version = "3.10", action = "add") # sc = try({ reticulate::import("stepcount") }) if (stepcount::have_stepcount()) { data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = acti_calculate_stepcount(data, sample_rate = 100) steps = acti_calculate_stepcount(data, model_type = "rf") }# reticulate::py_require("stepcount==3.11.0", python_version = "3.10", action = "add") # sc = try({ reticulate::import("stepcount") }) if (stepcount::have_stepcount()) { data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = acti_calculate_stepcount(data, sample_rate = 100) steps = acti_calculate_stepcount(data, model_type = "rf") }
Calculate Step Counts via Verisense
acti_calculate_verisense( data, resample_to_15hz = TRUE, method = c("original", "revised"), ... )acti_calculate_verisense( data, resample_to_15hz = TRUE, method = c("original", "revised"), ... )
data |
A |
resample_to_15hz |
resample data to 15Hz,
passed to |
method |
parameters to estimate walking, either original or revised,
passed to |
... |
Additional arguments passed to |
A tibble with minute-level time, steps columns.
data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = acti_calculate_verisense(data)data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = acti_calculate_verisense(data)
agcounts
This uses the van Hees calibration method typically exposed through GGIR,
implemented here via agcounts::agcalibrate().
acti_calibrate( data, verbose = TRUE, fill_zeroes = TRUE, round_after_calibration = TRUE, ... )acti_calibrate( data, verbose = TRUE, fill_zeroes = TRUE, round_after_calibration = TRUE, ... )
data |
Either a GT3X file, |
verbose |
print diagnostic messages, higher number result in higher verbosity |
fill_zeroes |
Should |
round_after_calibration |
Should the data be rounded after calibration? Will round to 3 digits |
... |
Additional arguments to pass to |
A calibrated dataset with the same columns as the input data,
but with the X/Y/Z values calibrated using the van Hees method.
res = acti_calibrate(data = actiread::acti_example_gt3x())res = acti_calibrate(data = actiread::acti_example_gt3x())
Example Actigraphy/Activity Count Data
acti_count_dataacti_count_data
A data.frame with the columns
time at the minute level
axis1 (Y) counts
axis2 (X) counts
axis3 (Z) counts
vector magnitude of all 3 axes column
This data was taken from running agcounts::calculate_counts via acti_calculate_counts on actibase::acti_raw_data.
Process Raw data to Counts
acti_process( data, lfe_select = FALSE, method = c("choi", "troiano"), use_magnitude = TRUE, calibrate = FALSE, verbose = TRUE, ..., min_required = 1368L )acti_process( data, lfe_select = FALSE, method = c("choi", "troiano"), use_magnitude = TRUE, calibrate = FALSE, verbose = TRUE, ..., min_required = 1368L )
data |
A |
lfe_select |
Apply the Actigraph Low Frequency Extension filter.
See |
method |
Method for detecting non-wear, either "choi" or "troiano",
corresponding to |
use_magnitude |
If |
calibrate |
Logical. If |
verbose |
print diagnostic messages. Either logical or integer, where |
... |
additional arguments to pass to |
min_required |
Number of minutes required in a day to be called |
A data frame containing activity counts and wear-time indicators.
For acti_process_gt3x, the ... argument are passed to
actiread::acti_read_gt3x()
Default MIMS worker functions
mims_default_extrapolation(data, dynamic_range = NULL) mims_default_interpolation(data) mims_default_filtering(data)mims_default_extrapolation(data, dynamic_range = NULL) mims_default_interpolation(data) mims_default_filtering(data)
data |
data set of data, usually time and X/Y/Z. Usually from
|
dynamic_range |
dynamic range of the data. Will be passed to
|
A data set of data
Default MIMS Pre-processing
mims_default_processing( data, use_extrapolation = TRUE, use_filtering = TRUE, verbose = TRUE, dynamic_range = NULL, round_after_processing = FALSE )mims_default_processing( data, use_extrapolation = TRUE, use_filtering = TRUE, verbose = TRUE, dynamic_range = NULL, round_after_processing = FALSE )
data |
Data set of raw accelerometry values, usually time and X/Y/Z.
Usually from |
use_extrapolation |
If |
use_filtering |
If |
verbose |
print diagnostic messages |
dynamic_range |
the dynamic ranges of the input signal. Passed to
|
round_after_processing |
Should the result be rounded to 3 decimal values after processing, to make similar to standard accelerometry? |
A processed data set
Perform step count calculation in a separate Python environment
py_acti_calculate_forest( ..., pyenv_function = function() { reticulate::import("forest") }, show = FALSE )py_acti_calculate_forest( ..., pyenv_function = function() { reticulate::import("forest") }, show = FALSE )
... |
arguments passed to |
pyenv_function |
function that loads the |
show |
Logical, whether to show the standard output on the
screen while the child process is running, passed to |
The output from acti_calculate_forest().
Sys.setenv("SSQ_PARALLEL" = 0) data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = py_acti_calculate_forest(data, sample_rate = 100)Sys.setenv("SSQ_PARALLEL" = 0) data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = py_acti_calculate_forest(data, sample_rate = 100)
Perform step count calculation in a separate Python environment
py_acti_calculate_stepcount( ..., pyenv_function = function() { stepcount::py_require_stepcount() }, show = FALSE )py_acti_calculate_stepcount( ..., pyenv_function = function() { stepcount::py_require_stepcount() }, show = FALSE )
... |
arguments passed to |
pyenv_function |
function that loads the |
show |
Logical, whether to show the standard output on the
screen while the child process is running, passed to |
The output from acti_calculate_stepcount().
A tibble with minute-level time, steps, and walking columns.
if (stepcount::have_stepcount()) { data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = py_acti_calculate_stepcount(data, sample_rate = 100) }if (stepcount::have_stepcount()) { data = actiread::acti_read_gt3x(actiread::acti_example_gt3x()) steps = py_acti_calculate_stepcount(data, sample_rate = 100) }