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.
Usage
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
)
Arguments
- data
An
impactr_data
object, as obtained with read_acc().- window1, window2
Windows size, in minutes, for the non-wear detection algorithm. Defaults to 60 and 15 minutes, respectively. Also,
window2
must be smaller thanwindow1
, andwindow1
must be a multiple ofwindow2
.- 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
FALSE
. Notice that the plot will only be displayed in your R session if you do not provide a path to save the plot (see the argumentsave_plot
).- 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
FALSE
. Provide a valid path to a file, ending with the ".pdf" extension for the plot or with the ".csv" extension to the summary, as a character string if you want the outputs to be saved.
The non-wear detection algorithm
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.
Data validation
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.
References
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 .
Examples
# \donttest{
# 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)
}
#> # Start time: 2016-01-20 00:01:00
#> # Sampling frequency: 100Hz
#> # Accelerometer placement: Back
#> # Subject body mass: 119kg
#> # Filter: No filter applied
#> # Data dimensions: 18,180,000 × 4
#> timestamp acc_X acc_Y acc_Z
#> <dttm> <dbl> <dbl> <dbl>
#> 1 2016-01-20 07:01:00 0.176 0.021 1.01
#> 2 2016-01-20 07:01:00 0.176 0.021 1.01
#> 3 2016-01-20 07:01:00 0.176 0.021 1.01
#> 4 2016-01-20 07:01:00 0.176 0.021 1.01
#> 5 2016-01-20 07:01:00 0.176 0.021 1.01
#> 6 2016-01-20 07:01:00 0.176 0.021 1.01
#> 7 2016-01-20 07:01:00 0.176 0.021 1.01
#> 8 2016-01-20 07:01:00 0.176 0.021 1.01
#> 9 2016-01-20 07:01:00 0.176 0.021 1.01
#> 10 2016-01-20 07:01:00 0.176 0.021 1.01
#> # … with 18,179,990 more rows
#> # ℹ Use `print(n = ...)` to see more rows
# }