| Title: | Baseline Functions for Actigraphy and Activity Processing and Analysis |
|---|---|
| Description: | Provides baseline functions for actigraphy and activity data. This package is intended to be extended by downstream overlays such as 'actiread', 'actimetrics', and 'stepcount'. |
| Authors: | John Muschelli [aut, cre] (ORCID: <https://orcid.org/0000-0001-6469-1750>) |
| Maintainer: | John Muschelli <[email protected]> |
| License: | GPL-3 |
| Version: | 0.2.0 |
| Built: | 2026-06-19 13:50:29 UTC |
| Source: | https://github.com/jhuwit/actibase |
Fill in Zeros
acti_fill_zeros(data) acti_fill_zeroes(data)acti_fill_zeros(data) acti_fill_zeroes(data)
data |
a data frame containing columns time, X, Y, Z |
the modified data frame with zeros replaced by NA
acti_fill_zeros(acti_raw_data) acti_fill_zeroes(acti_raw_data)acti_fill_zeros(acti_raw_data) acti_fill_zeroes(acti_raw_data)
Example Actigraphy/Activity Raw Data
acti_raw_dataacti_raw_data
A data.frame with the columns
time column
X-axis column
Y-axis column
Z-axis column
Resample 3-axial input signal to a specific sampling rate
acti_resample(data, sample_rate, method = "linear", ...) acti_resample_to_time(data, times, method = "linear", ...)acti_resample(data, sample_rate, method = "linear", ...) acti_resample_to_time(data, times, method = "linear", ...)
data |
A 'data.frame' with a column for time in 'POSIXct' (usually 'time'), and 'X', 'Y', 'Z' |
sample_rate |
sampling frequency, coercible to an integer. This is the sampling rate you're sampling the data *into*. |
method |
method for interpolation. Options are '"linear"/"constant"', which uses 'stats::approx', or one of '"fmm", "periodic", "natural", "monoH.FC", "hyman"', which uses 'stats::spline' |
... |
additional arguments to pass to [stats::approx()] or [stats::spline] |
times |
a vector of 'POSIXct' date/time values to interpolate the data to |
A 'data.frame'/'tibble' of 'time' and 'X', 'Y', 'Z'.
old = options(digits.secs = 3) x = acti_raw_data res = acti_resample(data = x, sample_rate = 80) res = acti_resample(data = x, sample_rate = 100) res = acti_resample(data = x, sample_rate = 1) res = acti_resample_to_time( data = x, times = lubridate::floor_date(x$time, unit = "1 sec"), ) res_nat = acti_resample_to_time( data = x, times = lubridate::floor_date(x$time, unit = "1 sec"), method = "natural" ) options(old)old = options(digits.secs = 3) x = acti_raw_data res = acti_resample(data = x, sample_rate = 80) res = acti_resample(data = x, sample_rate = 100) res = acti_resample(data = x, sample_rate = 1) res = acti_resample_to_time( data = x, times = lubridate::floor_date(x$time, unit = "1 sec"), ) res_nat = acti_resample_to_time( data = x, times = lubridate::floor_date(x$time, unit = "1 sec"), method = "natural" ) options(old)
Separate Times into Date, Hour, and Minute
acti_separate_time(data) acti_separate_times(data) acti_create_date(data) acti_create_hour(data) acti_create_minute(data)acti_separate_time(data) acti_separate_times(data) acti_create_date(data) acti_create_hour(data) acti_create_minute(data)
data |
a 'data.frame' with a 'time' column |
A 'data.frame' with date, hour, minute, and day columns
library(actibase) acti_separate_time(acti_raw_data) acti_create_date(acti_raw_data) acti_create_hour(acti_raw_data) acti_create_minute(acti_raw_data)library(actibase) acti_separate_time(acti_raw_data) acti_create_date(acti_raw_data) acti_create_hour(acti_raw_data) acti_create_minute(acti_raw_data)
Standardize the Accelerometry Data
acti_standardize_data( data, subset_xyz = TRUE, colname_time = "time", check_xyz = TRUE ) acti_standardise_data( data, subset_xyz = TRUE, colname_time = "time", check_xyz = TRUE )acti_standardize_data( data, subset_xyz = TRUE, colname_time = "time", check_xyz = TRUE ) acti_standardise_data( data, subset_xyz = TRUE, colname_time = "time", check_xyz = TRUE )
data |
A 'data.frame' with a column for time in 'POSIXct' (usually 'time'), and 'X', 'Y', 'Z' |
subset_xyz |
should only the 'time' (if available) and 'XYZ' be subset? |
colname_time |
column name of header for time |
check_xyz |
Check if X/Y/Z is in the data |
A 'data.frame' with 'X/Y/Z' and a time in 'time' (if available).
acti_standardize_data(acti_raw_data) acti_standardise_data(acti_raw_data)acti_standardize_data(acti_raw_data) acti_standardise_data(acti_raw_data)
Tidy axes to a long format
acti_tidy_axes(data, colname_time = "time")acti_tidy_axes(data, colname_time = "time")
data |
An object with columns a time column 'X', 'Y', and 'Z' or an object of class 'AccData' |
colname_time |
column name of header for time |
A long data set with 'time', 'axis', and 'value'
long = acti_tidy_axes(acti_raw_data)long = acti_tidy_axes(acti_raw_data)
Convert vectors ensuring no new NA
as_convert_safe(x, ..., func = lubridate::as_datetime) as_date_safe(x, ...) as_datetime_safe(x, ...)as_convert_safe(x, ..., func = lubridate::as_datetime) as_date_safe(x, ...) as_datetime_safe(x, ...)
x |
a vector |
... |
additional arguments to pass to 'func' |
func |
the function to use to transform the vector 'x' |
A converted 'vector' the same length as 'x' or errors if there are introduced NAs.
Create Day-Level Inclusion information
create_day_inclusion(data, min_required = 1368L) add_day_inclusion(data, ...)create_day_inclusion(data, min_required = 1368L) add_day_inclusion(data, ...)
data |
A 'data.frame' with the columns 'time' |
min_required |
Number of minutes required in a day to be called 'included' |
... |
arguments to pass to [create_day_inclusion] when using [add_day_inclusion] |
A 'data.frame' for each day with information of number of minutes observed and included
data = acti_raw_data |> dplyr::mutate(r = sqrt(X^2 + Y^2 + Z^2), time = lubridate::floor_date(time, "1 minute")) |> dplyr::group_by(time) |> dplyr::summarise(r = sum(r), .groups = "drop") |> dplyr::mutate(wear = r > 4000) res = create_day_inclusion(data)data = acti_raw_data |> dplyr::mutate(r = sqrt(X^2 + Y^2 + Z^2), time = lubridate::floor_date(time, "1 minute")) |> dplyr::group_by(time) |> dplyr::summarise(r = sum(r), .groups = "drop") |> dplyr::mutate(wear = r > 4000) res = create_day_inclusion(data)
Flag Quality Control Values
flag_qc( df, dynamic_range = NULL, verbose = TRUE, flags = c("all", "spike", "interval_jump", "spike_second", "same_value", "device_limit", "all_zero", "impossible") ) flag_qc_all( df, dynamic_range = NULL, verbose = TRUE, flags = c("all", "spike", "interval_jump", "spike_second", "same_value", "device_limit", "all_zero", "impossible") )flag_qc( df, dynamic_range = NULL, verbose = TRUE, flags = c("all", "spike", "interval_jump", "spike_second", "same_value", "device_limit", "all_zero", "impossible") ) flag_qc_all( df, dynamic_range = NULL, verbose = TRUE, flags = c("all", "spike", "interval_jump", "spike_second", "same_value", "device_limit", "all_zero", "impossible") )
df |
A data set of actigraphy |
dynamic_range |
dynamic range of the device, used to find the device limit. |
verbose |
print diagnostic messages |
flags |
the flags to run for QC. If you set this to |
A data set with a 'flags' column ('flag_qc') or a number of columns starting with 'flag_*' ('flag_qc_all')
res = acti_raw_data out = flag_qc(res)res = acti_raw_data out = flag_qc(res)
Flag Spikes
flag_spike(df, spike_size = 11) flag_interval_jump(df, verbose = FALSE) flag_spike_second(df, spike_size = 11) flag_device_limit(df, dynamic_range = NULL, epsilon = 0.05) flag_contiguous_device_limit(df, dynamic_range = NULL, epsilon = 0.05) flag_same_value(df, min_length = 1) flag_all_zero(df, min_length = 3) flag_impossible(df, min_length = 6)flag_spike(df, spike_size = 11) flag_interval_jump(df, verbose = FALSE) flag_spike_second(df, spike_size = 11) flag_device_limit(df, dynamic_range = NULL, epsilon = 0.05) flag_contiguous_device_limit(df, dynamic_range = NULL, epsilon = 0.05) flag_same_value(df, min_length = 1) flag_all_zero(df, min_length = 3) flag_impossible(df, min_length = 6)
df |
A data set of actigraphy |
spike_size |
size of "spike" - which is the absolute difference in contiguous observations on a single axis |
verbose |
print diagnostic messages |
dynamic_range |
dynamic range of the device, used to find the device limit. |
epsilon |
A small adjustment so that if values are within the device limit, but minus epsilon, still flagged as hitting the limit. For example, if 'dynamic_range = c(-6, 6)' and 'epsilon = 0.05', then any value <= '-5.95' or '>= 5.95' gravity units will be flagged |
min_length |
minimum length of the condition for contiguous samples. If 'min_length = 3', then at least 3 'TRUE's in a row is required, any stretches of single 'TRUE' values or 2 'TRUE' followed by 'FALSE', will be set to 'FALSE'. |
A data set back
'flag_spike' looks if 2 contiguous values, within each axis, are larger than a absolute size ('11' gravity units). The 'flag_spike_second' function groups the data by second, finds the range of values, within each axis, and determines if this range is greater than a specified size ('11' g).
https://wwwn.cdc.gov/Nchs/Nhanes/2011-2012/PAXMIN_G.htm
res = acti_raw_data res = flag_spike(res) res = flag_interval_jump(res) res = flag_spike_second(res) res = flag_same_value(res) res = flag_device_limit(res) res = flag_all_zero(res) res = flag_impossible(res)res = acti_raw_data res = flag_spike(res) res = flag_interval_jump(res) res = flag_spike_second(res) res = flag_same_value(res) res = flag_device_limit(res) res = flag_all_zero(res) res = flag_impossible(res)
Get Dynamic Range
get_dynamic_range(data, dynamic_range = NULL)get_dynamic_range(data, dynamic_range = NULL)
data |
An |
dynamic_range |
the dynamic range. If this is not |
A length-2 numeric vector, or the original dynamic range (no checking done)
Get Sample Rate
get_sample_rate(data, sample_rate = NULL)get_sample_rate(data, sample_rate = NULL)
data |
A data set of actigraphy/activity data |
sample_rate |
the sample rate. If this is not |
A length-1 numeric vector
Get Transformations
get_transformations(data) prefix_transformations(transformations, prefix = NULL) set_transformations(data, transformations, add = TRUE, prefix = NULL)get_transformations(data) prefix_transformations(transformations, prefix = NULL) set_transformations(data, transformations, add = TRUE, prefix = NULL)
data |
data set of data, usually time and X/Y/Z. |
transformations |
character string of transformations |
prefix |
if not 'NULL', the prefix plus ':' would be pasted to the transformations. |
add |
Add the transformations to those already there in 'data' |
set_transformations returns the data, with the
'transformations' attribute updated and set_transformations
returns the attribute 'transformations'
Is the object of class 'AccData'
is.AccData(x)is.AccData(x)
x |
object to test |
Logical(1)
is.AccData(mtcars)is.AccData(mtcars)
Mark a Condition of a Specified Minimum Length
mark_condition(x, min_length = 1)mark_condition(x, min_length = 1)
x |
A logical vector |
min_length |
minimum length, contiguous |
A logical vector
x = c(FALSE, TRUE, TRUE, FALSE, FALSE, rep(TRUE, 10), FALSE, rep(TRUE, 20)) mark_condition(x) mark_condition(x, 2) mark_condition(x, 5) mark_condition(x, 15)x = c(FALSE, TRUE, TRUE, FALSE, FALSE, rep(TRUE, 10), FALSE, rep(TRUE, 20)) mark_condition(x) mark_condition(x, 2) mark_condition(x, 5) mark_condition(x, 15)
Strip Hour Shift from Character Time Vector
strip_hour_shift(x, max_index = 2L)strip_hour_shift(x, max_index = 2L)
x |
character vector with times that may include hour shifts (e.g., "2019-01-01 12:00+03:00") |
max_index |
maximum index to grab the shift from after splitting on spaces, default is 2 (e.g., "2019-01-01 12:00") |
A character vector with the '+'/'-' hour shift removed
strip_hour_shift(c("2019-01-01 12:00+03:00", "2019-01-01 12:00-04:00"))strip_hour_shift(c("2019-01-01 12:00+03:00", "2019-01-01 12:00-04:00"))
Vector of X, Y, Z, and maybe time
xyz xyzt txyzxyz xyzt txyz
A vector with 3 or 4 elements, which are:
value to extract X column
value to extract Y column
value to extract Y column
value to extract time column
An object of class character of length 4.
An object of class character of length 4.