Title: | Physical Activity with Accelerometers |
---|---|
Description: | Functions to process, format and store ActiGraph GT1M and GT3X accelerometer data. |
Authors: | Marco Geraci |
Maintainer: | Marco Geraci <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.2.3 |
Built: | 2024-11-10 05:45:12 UTC |
Source: | https://github.com/cran/pawacc |
This package provides processing and summary functions.
Package: | pawacc |
Type: | Package |
Version: | 1.2.3 |
Date: | 2024-02-11 |
License: | GPL (>= 2) |
LazyLoad: | yes |
Marco Geraci
Maintainer: Marco Geraci <[email protected]>
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
This function aggregates count values
aggAccFile(object, by, which = "counts", x = NULL, keep.error = FALSE)
aggAccFile(object, by, which = "counts", x = NULL, keep.error = FALSE)
object |
an object of class |
by |
epoch by which count and steps are aggregated. Note: it cannot be less that the accelerometer epoch ( |
which |
either 'counts' or 'steps' for |
x |
optional argument. If |
keep.error |
logical flag. Should errors be omitted? |
outcome |
aggregated values |
ts_agg |
time stamping |
Marco Geraci
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
data(gt1m_sample) # aggregate by 30-second epochs aggAccFile(gt1m_sample, by = 30) # aggregate by 5-minute epochs aggAccFile(gt1m_sample, by = 300, keep.error = FALSE)
data(gt1m_sample) # aggregate by 30-second epochs aggAccFile(gt1m_sample, by = 30) # aggregate by 5-minute epochs aggAccFile(gt1m_sample, by = 300, keep.error = FALSE)
This function collapses accelerometer data into a dataframe with summary statistics.
collapse(...) ## S3 method for class 'accfile' collapse(object, which = "counts", palist = list(value = c(0, 100, 1000, 5000, 13000), rescale.epoch = 60, labels = NULL, extreme = NULL), mwlist = list(value = 20, nz = 0, rescale.epoch = 60), collapse.by = "%Y-%m-%d", collapse.epoch = 60, aggregate.by = NULL, FUN.list = list(mean = function(x) mean(x, na.rm = TRUE)), keep.extreme = FALSE, keep.error = FALSE, ...)
collapse(...) ## S3 method for class 'accfile' collapse(object, which = "counts", palist = list(value = c(0, 100, 1000, 5000, 13000), rescale.epoch = 60, labels = NULL, extreme = NULL), mwlist = list(value = 20, nz = 0, rescale.epoch = 60), collapse.by = "%Y-%m-%d", collapse.epoch = 60, aggregate.by = NULL, FUN.list = list(mean = function(x) mean(x, na.rm = TRUE)), keep.extreme = FALSE, keep.error = FALSE, ...)
object |
an object of class |
which |
either 'counts' or 'steps' for |
palist |
list of arguments for |
mwlist |
list of arguments for |
collapse.by |
dataset aggregation level. See argument |
collapse.epoch |
epoch by which time spent in different physical activity modes is summarized. See details. |
aggregate.by |
pre-collapsing aggregation level for accelerometer values. See argument |
FUN.list |
a named list of functions. See |
keep.extreme |
logical flag. If |
keep.error |
logical flag. If |
... |
arguments for |
A data frame containing the following variables
collapse.by |
aggregation factor |
fileid |
file identifier |
... |
named columns according to arguments |
Marco Geraci
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
markpa.accfile
, markwear.accfile
, fun.collapse
## Not run: data(gt1m_sample) collapse(gt1m_sample, palist = list(value = c(0, 100, 2000, 4000, 11000), rescale.epoch = 60, labels = c("sedentary","light","moderate","vigorous","extreme_values"), extreme = "last"), mwlist = list(value = 20, nz = 0), collapse.by = "%Y-%m-%d", collapse.epoch = 60, FUN.list = list(mean = function(x) round(mean(x, na.rm = TRUE),2)), keep.extreme = FALSE, keep.error = FALSE) $outcome collapse.by fileid outcome.mean sedentary light moderate vigorous 1 2011-12-08 test 117.63 293.75 243.75 29.75 4.00 2 2011-12-09 test 157.83 349.75 143.25 33.50 24.50 3 2011-12-10 test 79.75 468.25 177.25 24.25 6.25 4 2011-12-11 test 57.96 355.50 126.00 8.50 3.25 5 2011-12-12 test 70.05 455.50 157.25 19.50 6.00 6 2011-12-13 test 72.99 475.50 181.50 15.25 8.00 7 2011-12-14 test 79.94 476.25 210.50 20.25 8.50 8 2011-12-15 test 232.50 0.00 0.50 0.00 0.00 9 2011-12-16 test NaN 0.00 0.00 0.00 0.00 extreme_values non-wear 1 0.00 388.75 2 6.00 883.00 3 0.50 763.50 4 0.25 946.50 5 0.00 801.75 6 0.25 759.50 7 1.50 723.00 8 0.00 1439.50 9 0.00 187.50 $call collapse.accfile(object = gt1m_sample, palist = list(value = c(0, 100, 2000, 4000, 11000), rescale.epoch = 60, labels = c("sedentary", "light", "moderate", "vigorous", "extreme_values"), extreme = "last"), mwlist = list(value = 20, nz = 0), collapse.by = " collapse.epoch = 60, FUN.list = list(mean = function(x) round(mean(x, na.rm = TRUE), 2)), keep.extreme = FALSE, keep.error = FALSE) attr(,"class") [1] "accfile.collapse" Warning message: In collapse.accfile(gt1m_sample, palist = list(value = c(0, 100, : NAs imputed where extreme counts found ## End(Not run) ## Not run: collapse(gt1m_sample, palist = list(value = c(0, 100, 2000, 4000, 11000), rescale.epoch = 60, labels = c("sedentary","light","moderate","vigorous","extreme_values"), extreme = "last"), mwlist = list(value = 20, nz = 0), collapse.by = "%Y-%m-%d", collapse.epoch = 60, FUN.list = list(mean = function(x) round(mean(x, na.rm = TRUE),2), sd = function(x) round(sd(x, na.rm = TRUE),2), "95th" = function(x) round(quantile(x, probs = .95, na.rm = TRUE),2)), keep.extreme = TRUE, keep.error = FALSE) $outcome collapse.by fileid outcome.mean outcome.sd outcome.95th sedentary light 1 2011-12-08 test 117.63 216.12 529.40 293.75 243.75 2 2011-12-09 test 201.10 567.65 1085.60 349.75 143.25 3 2011-12-10 test 81.97 221.33 465.50 468.25 177.25 4 2011-12-11 test 59.80 172.08 320.35 355.50 126.00 5 2011-12-12 test 70.05 188.49 401.00 455.50 157.25 6 2011-12-13 test 74.08 207.55 386.85 475.50 181.50 7 2011-12-14 test 87.42 275.27 415.30 476.25 210.50 8 2011-12-15 test 232.50 222.74 374.25 0.00 0.50 9 2011-12-16 test NaN NA NA 0.00 0.00 moderate vigorous extreme_values non-wear 1 29.75 4.00 0.00 388.75 2 33.50 24.50 6.00 883.00 3 24.25 6.25 0.50 763.50 4 8.50 3.25 0.25 946.50 5 19.50 6.00 0.00 801.75 6 15.25 8.00 0.25 759.50 7 20.25 8.50 1.50 723.00 8 0.00 0.00 0.00 1439.50 9 0.00 0.00 0.00 187.50 $call collapse.accfile(object = gt1m_sample, palist = list(value = c(0, 100, 2000, 4000, 11000), rescale.epoch = 60, labels = c("sedentary", "light", "moderate", "vigorous", "extreme_values"), extreme = "last"), mwlist = list(value = 20, nz = 0), collapse.by = " collapse.epoch = 60, FUN.list = list(mean = function(x) round(mean(x, na.rm = TRUE), 2), sd = function(x) round(sd(x, na.rm = TRUE), 2), `95th` = function(x) round(quantile(x, probs = 0.95, na.rm = TRUE), 2)), keep.extreme = TRUE, keep.error = FALSE) attr(,"class") [1] "accfile.collapse" ## End(Not run)
## Not run: data(gt1m_sample) collapse(gt1m_sample, palist = list(value = c(0, 100, 2000, 4000, 11000), rescale.epoch = 60, labels = c("sedentary","light","moderate","vigorous","extreme_values"), extreme = "last"), mwlist = list(value = 20, nz = 0), collapse.by = "%Y-%m-%d", collapse.epoch = 60, FUN.list = list(mean = function(x) round(mean(x, na.rm = TRUE),2)), keep.extreme = FALSE, keep.error = FALSE) $outcome collapse.by fileid outcome.mean sedentary light moderate vigorous 1 2011-12-08 test 117.63 293.75 243.75 29.75 4.00 2 2011-12-09 test 157.83 349.75 143.25 33.50 24.50 3 2011-12-10 test 79.75 468.25 177.25 24.25 6.25 4 2011-12-11 test 57.96 355.50 126.00 8.50 3.25 5 2011-12-12 test 70.05 455.50 157.25 19.50 6.00 6 2011-12-13 test 72.99 475.50 181.50 15.25 8.00 7 2011-12-14 test 79.94 476.25 210.50 20.25 8.50 8 2011-12-15 test 232.50 0.00 0.50 0.00 0.00 9 2011-12-16 test NaN 0.00 0.00 0.00 0.00 extreme_values non-wear 1 0.00 388.75 2 6.00 883.00 3 0.50 763.50 4 0.25 946.50 5 0.00 801.75 6 0.25 759.50 7 1.50 723.00 8 0.00 1439.50 9 0.00 187.50 $call collapse.accfile(object = gt1m_sample, palist = list(value = c(0, 100, 2000, 4000, 11000), rescale.epoch = 60, labels = c("sedentary", "light", "moderate", "vigorous", "extreme_values"), extreme = "last"), mwlist = list(value = 20, nz = 0), collapse.by = " collapse.epoch = 60, FUN.list = list(mean = function(x) round(mean(x, na.rm = TRUE), 2)), keep.extreme = FALSE, keep.error = FALSE) attr(,"class") [1] "accfile.collapse" Warning message: In collapse.accfile(gt1m_sample, palist = list(value = c(0, 100, : NAs imputed where extreme counts found ## End(Not run) ## Not run: collapse(gt1m_sample, palist = list(value = c(0, 100, 2000, 4000, 11000), rescale.epoch = 60, labels = c("sedentary","light","moderate","vigorous","extreme_values"), extreme = "last"), mwlist = list(value = 20, nz = 0), collapse.by = "%Y-%m-%d", collapse.epoch = 60, FUN.list = list(mean = function(x) round(mean(x, na.rm = TRUE),2), sd = function(x) round(sd(x, na.rm = TRUE),2), "95th" = function(x) round(quantile(x, probs = .95, na.rm = TRUE),2)), keep.extreme = TRUE, keep.error = FALSE) $outcome collapse.by fileid outcome.mean outcome.sd outcome.95th sedentary light 1 2011-12-08 test 117.63 216.12 529.40 293.75 243.75 2 2011-12-09 test 201.10 567.65 1085.60 349.75 143.25 3 2011-12-10 test 81.97 221.33 465.50 468.25 177.25 4 2011-12-11 test 59.80 172.08 320.35 355.50 126.00 5 2011-12-12 test 70.05 188.49 401.00 455.50 157.25 6 2011-12-13 test 74.08 207.55 386.85 475.50 181.50 7 2011-12-14 test 87.42 275.27 415.30 476.25 210.50 8 2011-12-15 test 232.50 222.74 374.25 0.00 0.50 9 2011-12-16 test NaN NA NA 0.00 0.00 moderate vigorous extreme_values non-wear 1 29.75 4.00 0.00 388.75 2 33.50 24.50 6.00 883.00 3 24.25 6.25 0.50 763.50 4 8.50 3.25 0.25 946.50 5 19.50 6.00 0.00 801.75 6 15.25 8.00 0.25 759.50 7 20.25 8.50 1.50 723.00 8 0.00 0.00 0.00 1439.50 9 0.00 0.00 0.00 187.50 $call collapse.accfile(object = gt1m_sample, palist = list(value = c(0, 100, 2000, 4000, 11000), rescale.epoch = 60, labels = c("sedentary", "light", "moderate", "vigorous", "extreme_values"), extreme = "last"), mwlist = list(value = 20, nz = 0), collapse.by = " collapse.epoch = 60, FUN.list = list(mean = function(x) round(mean(x, na.rm = TRUE), 2), sd = function(x) round(sd(x, na.rm = TRUE), 2), `95th` = function(x) round(quantile(x, probs = 0.95, na.rm = TRUE), 2)), keep.extreme = TRUE, keep.error = FALSE) attr(,"class") [1] "accfile.collapse" ## End(Not run)
This function provides a date summary for Actigraph GT1M accelerometer files.
dateSummary(object, wear, timestamp, minval = 0, rescale.epoch = 60, keep.error = FALSE)
dateSummary(object, wear, timestamp, minval = 0, rescale.epoch = 60, keep.error = FALSE)
object |
an object of class |
wear |
a vector that classifies wear and non-wear time. See |
timestamp |
a timestamp vector for accelerometer values that can be provided by |
minval |
threshold defining the minimum number of minutes to identify first and last days. See details. |
rescale.epoch |
epoch expressed in the same unit as acceleromenter's epoch to determine minutes of wear time (default is 60 and assumed to be in seconds). |
keep.error |
logical flag. If |
Based on total wear time (in minutes) for each day, the theshold minval
is applied to identify the first and last days. For example, if accelerometers are sent by post to collect survey data, the first and last days in which the accelerometer was worn might not be known. Days before the first and those after the last day (truncated
days) are discarded by collapse.accfile
.
A data frame containing the following variables
fileid |
file identifier |
days |
dates by calendar day |
freq |
frequency of accelerometer observations in each day |
hour_day |
total hours of accelerometer observations in each day |
start_day |
starting time of accelerometer observations |
end |
end time of accelerometer observations |
valid_mins |
wear time (minutes) |
IsStartDate |
dummy variable to define starting date (1 = yes) |
IsEndDate |
dummy variable to define end date (1 = yes) |
IsTruncated |
dummy variable to define truncated date (1 = yes) |
Marco Geraci
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
data(gt1m_sample) mw <- markwear.accfile(gt1m_sample, 20) tsf <- tsFormat(gt1m_sample) dateSummary(gt1m_sample, mw, tsf) ## Not run: fileid days freq hour_day start_day end_day valid_mins IsStartDate 1 test 2011-12-08 3840 16.000 08 23 571.25 1 2 test 2011-12-09 5760 24.000 00 23 557.00 0 3 test 2011-12-10 5760 24.000 00 23 676.50 0 4 test 2011-12-11 5760 24.000 00 23 493.50 0 5 test 2011-12-12 5760 24.000 00 23 638.25 0 6 test 2011-12-13 5760 24.000 00 23 680.50 0 7 test 2011-12-14 5760 24.000 00 23 717.00 0 8 test 2011-12-15 5760 24.000 00 23 0.50 0 9 test 2011-12-16 750 3.125 00 03 0.00 0 IsEndDate IsTruncated 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 1 0 ## End(Not run) # at least 600 minutes per day to determine first and last day dateSummary(gt1m_sample, mw, tsf, minval = 600) ## Not run: fileid days freq hour_day start_day end_day valid_mins IsStartDate 1 test 2011-12-08 3840 16.000 08 23 571.25 0 2 test 2011-12-09 5760 24.000 00 23 557.00 0 3 test 2011-12-10 5760 24.000 00 23 676.50 1 4 test 2011-12-11 5760 24.000 00 23 493.50 0 5 test 2011-12-12 5760 24.000 00 23 638.25 0 6 test 2011-12-13 5760 24.000 00 23 680.50 0 7 test 2011-12-14 5760 24.000 00 23 717.00 0 8 test 2011-12-15 5760 24.000 00 23 0.50 0 9 test 2011-12-16 750 3.125 00 03 0.00 0 IsEndDate IsTruncated 1 0 1 2 0 1 3 0 0 4 0 0 5 0 0 6 0 0 7 1 0 8 0 1 9 0 1 ## End(Not run)
data(gt1m_sample) mw <- markwear.accfile(gt1m_sample, 20) tsf <- tsFormat(gt1m_sample) dateSummary(gt1m_sample, mw, tsf) ## Not run: fileid days freq hour_day start_day end_day valid_mins IsStartDate 1 test 2011-12-08 3840 16.000 08 23 571.25 1 2 test 2011-12-09 5760 24.000 00 23 557.00 0 3 test 2011-12-10 5760 24.000 00 23 676.50 0 4 test 2011-12-11 5760 24.000 00 23 493.50 0 5 test 2011-12-12 5760 24.000 00 23 638.25 0 6 test 2011-12-13 5760 24.000 00 23 680.50 0 7 test 2011-12-14 5760 24.000 00 23 717.00 0 8 test 2011-12-15 5760 24.000 00 23 0.50 0 9 test 2011-12-16 750 3.125 00 03 0.00 0 IsEndDate IsTruncated 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 1 0 ## End(Not run) # at least 600 minutes per day to determine first and last day dateSummary(gt1m_sample, mw, tsf, minval = 600) ## Not run: fileid days freq hour_day start_day end_day valid_mins IsStartDate 1 test 2011-12-08 3840 16.000 08 23 571.25 0 2 test 2011-12-09 5760 24.000 00 23 557.00 0 3 test 2011-12-10 5760 24.000 00 23 676.50 1 4 test 2011-12-11 5760 24.000 00 23 493.50 0 5 test 2011-12-12 5760 24.000 00 23 638.25 0 6 test 2011-12-13 5760 24.000 00 23 680.50 0 7 test 2011-12-14 5760 24.000 00 23 717.00 0 8 test 2011-12-15 5760 24.000 00 23 0.50 0 9 test 2011-12-16 750 3.125 00 03 0.00 0 IsEndDate IsTruncated 1 0 1 2 0 1 3 0 0 4 0 0 5 0 0 6 0 0 7 1 0 8 0 1 9 0 1 ## End(Not run)
These functions look for errors in the data. A code is returned.
errorChk(x, fault = 32767)
errorChk(x, fault = 32767)
x |
vector of accelerometer data. |
fault |
numerical value that indicates voltage signal saturation (temporarily used for both accelerometer counts and steps). |
Error coded are as follow: 0, no error; 1, all values are 5-digit values or all one value; 2, negative values; 3, NA
s.
a vector of the same length as x
.
Marco Geraci
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
Accessory function for collapsing accelerometer files.
fun.collapse(x, fun = list(mean = function(x) mean(x, na.rm = TRUE), median = function(x) median(x, na.rm = TRUE), sd = function(x) sd(x, na.rm = TRUE)))
fun.collapse(x, fun = list(mean = function(x) mean(x, na.rm = TRUE), median = function(x) median(x, na.rm = TRUE), sd = function(x) sd(x, na.rm = TRUE)))
x |
numeric vector. |
fun |
named list of functions to be applied to |
a list of named values of the same length as fun
.
Marco Geraci
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
This is the output of gt1mAccFile
.
See value
in gt1mAccFile
. The 'raw' file 'gt1m_sample.dat' can be found in the directory '\inst\extdata' of this package.
Actigraph (Pensacola, Florida).
## Not run: gt1m_sample <- gt1mAccFile("gt1m_sample.dat", path = "", fileid = "test") gt1m_sample fileid serial nobs epoch mode ts_start tz voltage ts_dl 1 test xxxxx 44910 15 1 2011-12-08 08:00:00 GMT 3.76 2011-12-24 11:20:36 ## End(Not run)
## Not run: gt1m_sample <- gt1mAccFile("gt1m_sample.dat", path = "", fileid = "test") gt1m_sample fileid serial nobs epoch mode ts_start tz voltage ts_dl 1 test xxxxx 44910 15 1 2011-12-08 08:00:00 GMT 3.76 2011-12-24 11:20:36 ## End(Not run)
This function reads a list of Actigraph GT1M accelerometer files.
gt1mAccDir(accFileList, save, compress = "gzip", compression_level = 6, progbar = TRUE)
gt1mAccDir(accFileList, save, compress = "gzip", compression_level = 6, progbar = TRUE)
accFileList |
an object of type |
save |
either logical or character. See |
compress |
logical or character string specifying whether saving to a named file is to use compression if |
compression_level |
integer: the level of compression to be used. See argument |
progbar |
logical flag. Should a progress bar be used? Available for Windows only. |
An object of class acclist
.
Marco Geraci
Actigraph (Pensacola, Florida).
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
This function reads an Actigraph GT1M accelerometer file.
gt1mAccFile(file, path, fileid, counts.pos = 1, tz = "Europe/London", sparse = FALSE, fault = 32767)
gt1mAccFile(file, path, fileid, counts.pos = 1, tz = "Europe/London", sparse = FALSE, fault = 32767)
file |
file name including file extension. |
path |
path to |
fileid |
label for file identifier. |
counts.pos |
when storage mode allows for accelerometer counts and steps to be recorded at the same time, this argument specifies the position of first measurement of accelerometer counts (default is |
tz |
a character string specifying the timezone to be used for the conversion (see |
sparse |
logical flag: should data be stored in sparse format? |
fault |
numerical value that indicates voltage signal saturation. |
Raw accelerometer data are processed according to the device data format. Several data checks are performed by errorChk
and infoDate
. An additional check is performed on the lenght of the sequence of measurements when both accelerometer counts and steps are recorded. If the length is odd, a warning message is produced. See file 'gt1m_sample.dat' in directory '\inst\extdata' of this package.
These functions return an object of two class
es: accfile
and additional device-specific class (i.e., gt1m
).
An object of class accfile
is a list containing the following components:
df |
A |
info |
A |
error_summary |
A |
Marco Geraci
Actigraph (Pensacola, Florida).
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
data(gt1m_sample) class(gt1m_sample)
data(gt1m_sample) class(gt1m_sample)
This is the output of gt3xAccFile
.
See value
in gt3xAccFile
. The 'raw' file 'gt3x_sample.dat' can be found in the directory '\inst\extdata' of this package.
Actigraph (Pensacola, Florida).
## Not run: gt3x_sample <- gt3xAccFile("gt3x_sample.dat", path = "", fileid = "test") gt3x_sample fileid serial nobs epoch mode ts_start tz voltage ts_dl 1 test xxxxx 2676 1 13 2009-03-03 10:40:00 GMT 4.09 2009-03-03 11:24:49 ## End(Not run)
## Not run: gt3x_sample <- gt3xAccFile("gt3x_sample.dat", path = "", fileid = "test") gt3x_sample fileid serial nobs epoch mode ts_start tz voltage ts_dl 1 test xxxxx 2676 1 13 2009-03-03 10:40:00 GMT 4.09 2009-03-03 11:24:49 ## End(Not run)
This function reads a list of Actigraph GT3X accelerometer files.
gt3xAccDir(accFileList, save, compress = "gzip", compression_level = 6, progbar = TRUE)
gt3xAccDir(accFileList, save, compress = "gzip", compression_level = 6, progbar = TRUE)
accFileList |
an object of type |
save |
either logical or character. See |
compress |
logical or character string specifying whether saving to a named file is to use compression if |
compression_level |
integer: the level of compression to be used. See argument |
progbar |
logical flag. Should a progress bar be used? Available for Windows only. |
An object of class acclist
.
Marco Geraci
Actigraph (Pensacola, Florida).
This function reads Actigraph GT3X and ActiSleep accelerometer files.
gt3xAccFile(file, path, fileid, tz = "Europe/London", sparse = FALSE, fault = 32767)
gt3xAccFile(file, path, fileid, tz = "Europe/London", sparse = FALSE, fault = 32767)
file |
file name including file extension. |
path |
path to |
fileid |
label for file identifier. |
tz |
a character string specifying the timezone to be used for the conversion (see |
sparse |
logical flag: should data be stored in sparse format? |
fault |
numerical value that indicates voltage signal saturation. |
Raw accelerometer data are processed according to the device data format. See file 'gt3x_sample.dat' in directory '\inst\extdata' of this package.
These functions return an object of two class
es: accfile
and additional device-specific class (i.e., gt3x
).
An object of class accfile
is a list containing the following components:
df |
A |
info |
A |
error_summary |
A |
Marco Geraci
Actigraph (Pensacola, Florida).
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
data(gt3x_sample) class(gt3x_sample)
data(gt3x_sample) class(gt3x_sample)
This function identifies bouts of physical activity using user-defined breakpoints for accelerometer counts.
markbouts(object, value, which = "counts", bts = c(0, 10, 20, Inf), rescale.epoch = 60, collapse.by = "%Y-%m-%d", value.labels = NULL, bouts.labels = NULL, extreme = NULL, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'acclist' markbouts(object, value, which = "counts", bts = c(0, 10, 20, Inf), rescale.epoch = 60, collapse.by = "%Y-%m-%d", value.labels = NULL, bouts.labels = NULL, extreme = NULL, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'accfile' markbouts(object, value, which = "counts", bts = c(0, 10, 20, Inf), rescale.epoch = 60, collapse.by = "%Y-%m-%d", value.labels = NULL, bouts.labels = NULL, extreme = NULL, keep.error = FALSE, progbar = NULL)
markbouts(object, value, which = "counts", bts = c(0, 10, 20, Inf), rescale.epoch = 60, collapse.by = "%Y-%m-%d", value.labels = NULL, bouts.labels = NULL, extreme = NULL, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'acclist' markbouts(object, value, which = "counts", bts = c(0, 10, 20, Inf), rescale.epoch = 60, collapse.by = "%Y-%m-%d", value.labels = NULL, bouts.labels = NULL, extreme = NULL, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'accfile' markbouts(object, value, which = "counts", bts = c(0, 10, 20, Inf), rescale.epoch = 60, collapse.by = "%Y-%m-%d", value.labels = NULL, bouts.labels = NULL, extreme = NULL, keep.error = FALSE, progbar = NULL)
object |
an object of class |
value |
vector of breaks to define physical activity modes. The lowest breakpoint must be 0. |
which |
either 'counts' or 'steps' for |
bts |
vector of breaks to define bouts duration (in minutes). |
rescale.epoch |
epoch expressed in the same unit as acceleromenter's epoch to determine multiplier to rescale |
collapse.by |
dataset aggregation level. See argument |
value.labels |
labels for physical activity modes. |
bouts.labels |
labels for bouts duration catergories ( |
extreme |
if |
keep.error |
logical flag. If |
progbar |
logical flag. Should a progress bar be used? Available for Windows only. Argument not used for class |
Breakpoints are specified as counts per seconds using value
. If the epoch used for value
is different from the accelerometer's epoch, a rescaling is applied. E.g., if epoch is 15 seconds and breakpoints are expressed as counts per 60 seconds, value
is divided by 60/15 = 4. There can be n physical activity modes at maximum, where n is the length of value
.
The argument extreme
is NULL
by default. Use either ‘last’ to select the last category or the category number 1 to n.
The function markbouts.accfile
returns duration, frequency and mean duration of bouts by bout category, physical activity mode and T
levels of collapse.by
(e.g., day) in array of dimension c(length(bts) - 1,length(value) + 1,3,T)
. markbouts.acclist
is applied to objects of class acclist
, in which case a list of arrays of the same length as the number of accelerometer files in object
is returned.
Marco Geraci
This function identifies modes of physical activity using user-defined breakpoints for accelerometer counts.
markpa(object, value, which = "counts", rescale.epoch = 60, labels = NULL, extreme = NULL, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'acclist' markpa(object, value, which = "counts", rescale.epoch = 60, labels = NULL, extreme = NULL, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'accfile' markpa(object, value, which = "counts", rescale.epoch = 60, labels = NULL, extreme = NULL, keep.error = FALSE, progbar = NULL)
markpa(object, value, which = "counts", rescale.epoch = 60, labels = NULL, extreme = NULL, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'acclist' markpa(object, value, which = "counts", rescale.epoch = 60, labels = NULL, extreme = NULL, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'accfile' markpa(object, value, which = "counts", rescale.epoch = 60, labels = NULL, extreme = NULL, keep.error = FALSE, progbar = NULL)
object |
an object of class |
value |
vector of breaks to define physical activity modes. The lowest breakpoint must be 0. |
which |
either 'counts' or 'steps' for |
rescale.epoch |
epoch expressed in the same unit as acceleromenter epoch to determine multiplier to rescale |
labels |
labels for physical activity modes. |
extreme |
if |
keep.error |
logical flag. If |
progbar |
logical flag. Should a progress bar be used? Available for Windows only. Argument not used for class |
Breakpoints are specified as counts per seconds using value
. If the epoch used for value
is different from the accelerometer epoch, a rescaling is applied. E.g., if epoch is 15 seconds and breakpoints are expressed as counts per 60 seconds, value
is divided by 60/15 = 4. There can be n physical activity modes at maximum, where n is the length of value
.
The argument extreme
is NULL
by default. Use either ‘last’ to select the last category or the category number 1 to n.
If object
is of class acclist
, a list of factors of the same length as the number of accelerometer files in object
. If object
is of class accfile
, a single factor will be given. The number of levels is equal to length(value) + 1
.
Marco Geraci
This functions identifies sequences of zeroes of a given length to classify wear and non-wear time in accelerometer data files.
markwear(object, value, which = "counts", rescale.epoch = 60, nz = 0, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'acclist' markwear(object, value, which = "counts", rescale.epoch = 60, nz = 0, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'accfile' markwear(object, value, which = "counts", rescale.epoch = 60, nz = 0, keep.error = FALSE, progbar = NULL)
markwear(object, value, which = "counts", rescale.epoch = 60, nz = 0, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'acclist' markwear(object, value, which = "counts", rescale.epoch = 60, nz = 0, keep.error = FALSE, progbar = TRUE) ## S3 method for class 'accfile' markwear(object, value, which = "counts", rescale.epoch = 60, nz = 0, keep.error = FALSE, progbar = NULL)
object |
an object of class |
value |
the length of the time window (in minutes) which contains zero values. |
which |
either 'counts' or 'steps' for |
rescale.epoch |
epoch expressed in the same unit as acceleromenter epoch to determine multiplier to rescale |
nz |
the length of the time window (in minutes) of non-zero value sequences allowed between every two sequences of zero values. |
keep.error |
logical flag. If |
progbar |
logical flag. Should a progress bar be used? Available for Windows only. Argument not used for class |
The accelerometer epoch is assumed to be expressed in seconds. Therefore value
is automatically rescaled to value * 60/object$info$epoch
.
If object
is of class acclist
, a list of factors with two levels of the same length as the number of accelerometers files in object
. If object
is of class accfile
, a single factor will be given. Levels are 'non-wear' and 'wear'.
Marco Geraci
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
## Not run: data(gt1m_sample) # 20-minute threshold wear <- markwear(gt1m_sample, value = 20) > table(wear) wear Non-wear Wear 27572 17338 ## End(Not run) ## Not run: # lower threshold wear <- markwear(gt1m_sample, value = 5) > table(wear) wear Non-wear Wear 30188 14722 ## End(Not run) ## Not run: # allow for some non-zero values within a 20-minute window wear <- markwear.accfile(gt1m_sample, value = 20, nz = 2) > table(wear) wear Non-wear Wear 28198 16712 ## End(Not run)
## Not run: data(gt1m_sample) # 20-minute threshold wear <- markwear(gt1m_sample, value = 20) > table(wear) wear Non-wear Wear 27572 17338 ## End(Not run) ## Not run: # lower threshold wear <- markwear(gt1m_sample, value = 5) > table(wear) wear Non-wear Wear 30188 14722 ## End(Not run) ## Not run: # allow for some non-zero values within a 20-minute window wear <- markwear.accfile(gt1m_sample, value = 20, nz = 2) > table(wear) wear Non-wear Wear 28198 16712 ## End(Not run)
Thes functions plot data from Actigraph GT1M and GT3X accelerometer files.
## S3 method for class 'gt1m' plot(x, y = NULL, xlab, ylab, main, keep.error = TRUE, which = "counts", select = 1,...) ## S3 method for class 'gt3x' plot(x, y = NULL, xlab, ylab, main, keep.error = TRUE, which = "x", select = 1,...)
## S3 method for class 'gt1m' plot(x, y = NULL, xlab, ylab, main, keep.error = TRUE, which = "counts", select = 1,...) ## S3 method for class 'gt3x' plot(x, y = NULL, xlab, ylab, main, keep.error = TRUE, which = "x", select = 1,...)
x |
an object of class |
y |
ignored. |
xlab |
x-axis label (optional). |
ylab |
y-axis label (optional). |
main |
main title (optional). |
keep.error |
logical flag. If |
which |
either 'counts' or 'steps' for |
select |
numeric. If |
... |
Arguments to be passed to methods, such as graphical parameters (see |
Marco Geraci
Actigraph (Pensacola, Florida).
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
plot
, par
, gt1mAccFile
, gt1mAccDir
data(gt1m_sample) data(gt3x_sample) plot(gt1m_sample, which = "counts") plot(gt1m_sample, which = "steps") plot(gt3x_sample, which = "x") plot(gt3x_sample, which = "steps")
data(gt1m_sample) data(gt3x_sample) plot(gt1m_sample, which = "counts") plot(gt1m_sample, which = "steps") plot(gt3x_sample, which = "x") plot(gt3x_sample, which = "steps")
accfile
or acclist
Object
Print an object generated by gt1mAccFile
, gt3xAccFile
or readAccDir
.
## S3 method for class 'acclist' print(x, ...) ## S3 method for class 'accfile' print(x, ...)
## S3 method for class 'acclist' print(x, ...) ## S3 method for class 'accfile' print(x, ...)
x |
an |
... |
not used. |
Marco Geraci
This function reads raw files downloaded from accelerometers and stores them in one directory.
readAccDir(path, model, ext = "dat", counts.pos = 1, tz = "Europe/London", sparse = FALSE, fault = 32767, save = TRUE, compress = "gzip", compression_level = 6,...)
readAccDir(path, model, ext = "dat", counts.pos = 1, tz = "Europe/London", sparse = FALSE, fault = 32767, save = TRUE, compress = "gzip", compression_level = 6,...)
path |
path to accelerometer files. |
model |
accelerometer model, either 'gt1m' or 'gt3x'. |
ext |
file extension without '.' (default is 'dat'). |
counts.pos |
position of first measurement of accelerometer counts. See |
tz |
a character string specifying the timezone to be used for the conversion (see |
sparse |
logical flag: should data be stored in sparse format? |
fault |
numerical value that indicates voltage signal saturation (temporarily used for both accelerometer counts and steps). |
save |
either logical or character. If logical, |
compress |
logical or character string specifying whether saving to a named file is to use compression if |
compression_level |
integer: the level of compression to be used. See argument |
... |
not used. |
This is a wrapper function. It reads raw accelerometer files stored in one directory. The argument ext
specifies the extension of the files to look for (e.g., 'dat' or 'txt'). Files with different extension and/or sub-directories are ignored. The data format must be consistent with the specification of model
.
Either a set of .Rdata
files or a list
of objects of class accfile
. In both cases, each accelerometer data file is stored as an object of type list
and labelled using the data file name. See gt1mAccFile
or gt3xAccFile
for details.
Marco Geraci
Geraci M, Rich C, Sera F, Cortina-Borja M, Griffiths LJ, and Dezateux C (2012). Technical report on accelerometry data processing in the Millennium Cohort Study. London, UK: University College London. Available at https://discovery.ucl.ac.uk/1361699
gt1mAccFile
, gt3xAccFile
, gt1mAccDir
, gt3xAccDir
Time stamping.
tsFormat(object)
tsFormat(object)
object |
an object of class |
a vector of timestamps.
Marco Geraci
data(gt1m_sample) data(gt3x_sample) tsFormat(gt1m_sample) tsFormat(gt3x_sample)
data(gt1m_sample) data(gt3x_sample) tsFormat(gt1m_sample) tsFormat(gt3x_sample)
Utility functions.
tsFromEpoch(object, x) epochFromTS(object, x)
tsFromEpoch(object, x) epochFromTS(object, x)
object |
an object of class |
x |
either an integer giving the epoch number or the timestamp in a |
either a timestamp corresponding to an epoch number or the epoch number corresponding to a timestamp.
Marco Geraci
data(gt1m_sample) tsFromEpoch(gt1m_sample, 10000) # [1] "2011-12-10 01:39:45 GMT" epochFromTS(gt1m_sample, as.POSIXlt(strptime('2011-12-10 01:39:45', '%Y-%m-%d %H:%M:%S'))) # [1] 10000
data(gt1m_sample) tsFromEpoch(gt1m_sample, 10000) # [1] "2011-12-10 01:39:45 GMT" epochFromTS(gt1m_sample, as.POSIXlt(strptime('2011-12-10 01:39:45', '%Y-%m-%d %H:%M:%S'))) # [1] 10000