Title: | Mechanical Loading Prediction Through Accelerometer Data |
---|---|
Description: | Functions to read, process and analyse accelerometer data related to mechanical loading variables. This package is developed and tested for use with raw accelerometer data from triaxial 'ActiGraph' <https://actigraphcorp.com> accelerometers. |
Authors: | Lucas Veras [aut, cre] |
Maintainer: | Lucas Veras <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.4.1 |
Built: | 2025-02-19 06:00:50 UTC |
Source: | https://github.com/verasls/impactr |
Define the region of interest for data analysis based on the accelerometer data timestamp.
define_region(data, start_time, end_time)
define_region(data, start_time, end_time)
data |
An |
start_time , end_time
|
A character string with the start and end times of the region of interest in the "YYYY-MM-DD HH:MM:SS" format. |
An object of class impactr_data
.
data <- read_acc(impactr_example("hip-raw.csv")) define_region( data, start_time = "2021-04-06 15:45:00", end_time = "2021-04-06 15:46:00" )
data <- read_acc(impactr_example("hip-raw.csv")) define_region( data, start_time = "2021-04-06 15:45:00", end_time = "2021-04-06 15:46:00" )
Filter the acceleration signal using a butterworth digital filter.
filter_acc(data, order = 4, cutoff = 20, type = "lowpass")
filter_acc(data, order = 4, cutoff = 20, type = "lowpass")
data |
An |
order |
The order of the filter. Defaults to 4. |
cutoff |
The filter cut-off frequency in Hz. Defaults to 20. For low- and high-pass filters, must be a scalar. For band-pass and band- stop, a vector of length two. |
type |
The type of filter. Defaults to "lowpass". Can be "lowpass", "highpass", "bandpass" or "bandstop". |
The default values of the filter parameters are matching the filter used in the paper by Veras et al. that developed the mechanical loading prediction equations (see References).
An object of class impactr_data
.
Veras L, Diniz-Sousa F, Boppre G, Devezas V, Santos-Sousa H, Preto J, Machado L, Vilas- Boas JP, Oliveira J, Fonseca H. Accelerometer-based prediction of skeletal mechanical loading during walking in normal weight to severely obese subjects. Osteoporosis International. 2020. 31(7):1239- 1250. doi:10.1007/s00198-020-05295-2.
data <- read_acc(impactr_example("hip-raw.csv")) filter_acc(data)
data <- read_acc(impactr_example("hip-raw.csv")) filter_acc(data)
Find peaks in the acceleration signal.
find_peaks(data, vector, min_height = 1.3, min_dist = 0.4)
find_peaks(data, vector, min_height = 1.3, min_dist = 0.4)
data |
An |
vector |
A character string indicating in which acceleration vector to find the peaks. Can be "resultant", "vertical" or "all". |
min_height |
The minimum height of the peaks (in g). |
min_dist |
The minimum horizontal distance between peaks (in seconds). |
The default values of the filter parameters are matching the filter
used in the paper by Veras et al. that developed the mechanical loading
prediction equations (see References).
When the vector
parameter is set to "all", there may contain
NA
values in the resultant_peak_acc
and/or
vertical_peak_acc
at the timestamps in which a peak value for that
vector could not be identified.
The default values of min_height
and min_dist
are
matching the criteria used in the paper by Veras et al. that developed the
mechanical loading prediction equations (see References)
An object of class impactr_peaks
with the peaks magnitude
stored in the columns.
Veras L, Diniz-Sousa F, Boppre G, Devezas V, Santos-Sousa H, Preto J, Machado L, Vilas- Boas JP, Oliveira J, Fonseca H. Accelerometer-based prediction of skeletal mechanical loading during walking in normal weight to severely obese subjects. Osteoporosis International. 2020. 31(7):1239- 1250. doi:10.1007/s00198-020-05295-2.
data <- read_acc(impactr_example("hip-raw.csv")) data <- use_resultant(data) find_peaks(data, vector = "resultant")
data <- read_acc(impactr_example("hip-raw.csv")) data <- use_resultant(data) find_peaks(data, vector = "resultant")
impactr
comes with some example ActiGraph accelerometer raw data
files in its inst/extdata
directory. This function make them easy to
access.
impactr_example(file = NULL)
impactr_example(file = NULL)
file |
A character string with the file name. If |
If file = NULL
, it returns the file names of the example
data files, else it returns the path to the example data.
impactr_example() impactr_example("hip-raw.csv")
impactr_example() impactr_example("hip-raw.csv")
A helper function to import datasets from the accdata
package.
import_dataset(data)
import_dataset(data)
data |
A character string indicating which data to load. The currently available datasets are "daily_acc_3d" and "daily_acc_7d". |
To import these datasets you need to install the accdata
package. It can be installed by running install_accdata()
. The
datasets documentation can be accessed by ?accdata::`dataset_name`
(e.g., ?accdata::daily_acc_3d
.
An object of class impactr_data
.
# Ensure that {accdata} package is available before running the example. # If it is not, run install_accdata() to install the required package. if (requireNamespace("accdata", quietly = TRUE)) { data <- import_dataset("daily_acc_3d") data }
# Ensure that {accdata} package is available before running the example. # If it is not, run install_accdata() to install the required package. if (requireNamespace("accdata", quietly = TRUE)) { data <- import_dataset("daily_acc_3d") data }
A helper function to install the accdata
package from a
drat
repository. The accdata
package contains datasets that can be used to test the functionalities
from impactr
. Note that accdata
is a large package
(approximately 80 MB) and could take a while to download and install.
install_accdata()
install_accdata()
Test if the object is from the impactr package
is_impactr_data(x) is_impactr_peaks(x)
is_impactr_data(x) is_impactr_peaks(x)
x |
An object. |
TRUE
if the object inherits the class being evaluated.
Predict either ground reaction force or loading rate, or both, based on accelerometer data.
predict_loading(data, outcome, vector, model)
predict_loading(data, outcome, vector, model)
data |
An |
outcome |
A character string. Can be either "grf" (for ground reaction force), or "lr" (for loading rate) or "all" (for both mechanical loading variables). |
vector |
A character string indicating in which acceleration vector to find the peaks. Can be "resultant", "vertical" or "all". |
model |
A character string indicating which model to use to make the predictions. The values currently supported are "walking", "walking/running" and "jumping". |
An object of class impactr_peaks
with the ground reaction
force and/or loading rate peaks magnitude stored in the columns.
data <- read_acc(impactr_example("hip-raw.csv")) data <- specify_parameters(data, acc_placement = "hip", subj_body_mass = 78) data <- find_peaks(data, vector = "vertical") predict_loading( data, outcome = "grf", vector = "vertical", model = "walking/running" )
data <- read_acc(impactr_example("hip-raw.csv")) data <- specify_parameters(data, acc_placement = "hip", subj_body_mass = 78) data <- find_peaks(data, vector = "vertical") predict_loading( data, outcome = "grf", vector = "vertical", model = "walking/running" )
Reads raw accelerometer data files into an impactr_data
object.
read_acc(file)
read_acc(file)
file |
Path to a raw accelerometer data file. |
An object of class impactr_data
.
read_acc(impactr_example("hip-raw.csv"))
read_acc(impactr_example("hip-raw.csv"))
Detects the accelerometer non-wear time based on an algorithm developed by van Hees (see Details) and remove these periods from the raw data. This function can also draw a plot to better visualize the detected non-wear periods and generate a wear time daily summary.
remove_nonwear( data, window1 = 60, window2 = 15, threshold = 2, min_hour_crit = 0, min_day_crit = 0, plot = FALSE, save_plot = FALSE, save_summary = FALSE )
remove_nonwear( data, window1 = 60, window2 = 15, threshold = 2, min_hour_crit = 0, min_day_crit = 0, plot = FALSE, save_plot = FALSE, save_summary = FALSE )
data |
An |
window1 , window2
|
Windows size, in minutes, for the non-wear
detection algorithm. Defaults to 60 and 15 minutes, respectively.
Also, |
threshold |
Number of axes that need to meet the non-wear criteria. Defaults to 2. |
min_hour_crit |
The minimum number of hours marked as wear time in a day for it to be considered valid (see Data validation). Defaults to 0, meaning that every day is considered valid. |
min_day_crit |
The minimum number of valid days for the data of a given subject to be considered valid (see Data validation). Defaults to 0, meaning that all data is valid. |
plot |
A logical value indicating whether or not to display the
plot to visualize the detected non-wear periods. Defaults to |
save_plot , save_summary
|
Indicates whether of not to save the plot to
visualize the detected non-wear periods to a pdf file and the wear time
daily summary to a csv file, respectively. Defaults to |
An object of class impactr_data
and a plot if
plot = TRUE
and save_plot = FALSE
.
The current version of this algorithm is described in a paper by van Hees
et al (see References) and also in this
vignette from package GGIR.
Briefly, in a first stage it identifies non-wear time based on threshold
values of standard deviation (0.013g) and range (0.050g) of
raw acceleration from each axis. The classification is done per blocks of
window2
size (default 15 minutes) based on the characteristics of
a larger window1
(default 60 minutes) centred at the
window2
. In the second stage of the algorithm, the plausibility of
wear periods in between non-wear periods is tested based on the duration
and proportion of the duration relative to the surrounding non-wear
periods.
After the detection of non-wear periods through the algorithm, a data
validation step is applied. For each measurement day to be considered
valid, it has to present a minimum number of wear time hours determined
by the min_hour_crit
argument. If the number of wear time hours of
a given day falls below the threshold, the whole day is considered invalid
and is then removed from the subsequent analyses. The whole measurement
is also classified as valid or invalid based on the number of valid days
and a threshold given by min_day_crit
. If the number of valid days
is less than the value determined by the min_day_crit
argument,
the whole data is deleted and the remove_nonwear()
function
signals an error, stopping its execution. Nevertheless, this error does
not prevent the plot to be displayed or saved, or the wear time daily
summary to be saved, if the arguments are set to do so.
van Hees VT, Gorzelniak L, Dean León EC, Eder M, Pias M, Taherian S, Ekelund U, Renström F, Franks PW, Horsch A, Brage S. Separating movement and gravity components in an acceleration signal and implications for the assessment of human daily physical activity. PLoS One. 2013. Apr 23. doi:10.1371/journal.pone.0061691.
# Ensure that {accdata} package is available before running the example. # If it is not, run install_accdata() to install the required package. if (requireNamespace("accdata", quietly = TRUE)) { data <- import_dataset("daily_acc_3d") remove_nonwear(data) }
# Ensure that {accdata} package is available before running the example. # If it is not, run install_accdata() to install the required package. if (requireNamespace("accdata", quietly = TRUE)) { data <- import_dataset("daily_acc_3d") remove_nonwear(data) }
Specify the accelerometer placement used and the subject body mass. These data is needed in order to use the mechanical loading prediction models.
specify_parameters(data, acc_placement, subj_body_mass)
specify_parameters(data, acc_placement, subj_body_mass)
data |
An |
acc_placement |
A character string indicating the accelerometer placement. Can be either "ankle", "back", or "hip". |
subj_body_mass |
A double scalar indicating the subject body mass in kilograms. |
An object of class impactr_data
with the specified parameters
as attributes.
data <- read_acc(impactr_example("hip-raw.csv")) specify_parameters(data, acc_placement = "hip", subj_body_mass = 79.2)
data <- read_acc(impactr_example("hip-raw.csv")) specify_parameters(data, acc_placement = "hip", subj_body_mass = 79.2)
Creates a summary table of the selected mechanical loading variables including the number of peaks, the minimum, maximum, mean and standard deviation values of these peaks and also the number of peaks inside a given magnitude range. The summaries can be displayed by day or as a daily average.
summarise_loading( data, variable, vector, daily_average = TRUE, ranges_acc = NULL, ranges_grf = NULL, ranges_lr = NULL, save_summary = FALSE )
summarise_loading( data, variable, vector, daily_average = TRUE, ranges_acc = NULL, ranges_grf = NULL, ranges_lr = NULL, save_summary = FALSE )
data |
An |
variable |
A character vector indicating the variable to summarise. Can be either "acc" (for the acceleration peaks), "grf" (for the ground reaction force peaks), "lr" (for the loading rate peaks) or "all" (for all variables). |
vector |
A character string indicating which vector to use to create the summaries. Can be "resultant", "vertical" or "all". |
daily_average |
Create a daily average summary? Can be |
ranges_acc , ranges_grf , ranges_lr
|
A numeric vector to specify ranges in
which to count the peaks. E.g., If |
save_summary |
Indicates whether or not to save the summary to a csv
file(s). Defaults to |
A tibble (or a list of tibbles) with the requested summaries.
# Ensure that {accdata} package is available before running the example. # If it is not, run install_accdata() to install the required package. if (requireNamespace("accdata", quietly = TRUE)) { data <- import_dataset("daily_acc_3d") data <- remove_nonwear(data) data <- filter_acc(data) data <- find_peaks(data, vector = "vertical") summarise_loading( data, variable = "acc", vector = "vertical", ranges_acc = 1:5 ) }
# Ensure that {accdata} package is available before running the example. # If it is not, run install_accdata() to install the required package. if (requireNamespace("accdata", quietly = TRUE)) { data <- import_dataset("daily_acc_3d") data <- remove_nonwear(data) data <- filter_acc(data) data <- find_peaks(data, vector = "vertical") summarise_loading( data, variable = "acc", vector = "vertical", ranges_acc = 1:5 ) }
Computes the acceleration resultant vector.
use_resultant(data)
use_resultant(data)
data |
An |
An object of class impactr_data
with the acc_R
column
containing the acceleration resultant vector.
data <- read_acc(impactr_example("hip-raw.csv")) use_resultant(data)
data <- read_acc(impactr_example("hip-raw.csv")) use_resultant(data)