Calculate Summary Measures from Raw Accelerometer Data
Source:R/calculate_ac.R
, R/calculate_measures.R
calculate_measures.Rd
Calculate Summary Measures from Raw Accelerometer Data
Usage
calculate_activity_counts(
df,
sample_rate = NULL,
unit = "1 min",
verbose = TRUE,
...
)
calculate_ac(df, sample_rate = NULL, unit = "1 min", verbose = TRUE, ...)
calculate_measures(
df,
unit = "1 min",
fix_zeros = TRUE,
fill_in = TRUE,
by_second = FALSE,
trim = FALSE,
dynamic_range = NULL,
calculate_mims = TRUE,
calculate_ac = TRUE,
flag_data = TRUE,
flags = NULL,
ensure_all_time = TRUE,
verbose = TRUE,
sample_rate = NULL,
...
)
calculate_ai(df, unit = "1 min", ensure_all_time = TRUE, verbose = FALSE)
calculate_activity_index(
df,
unit = "1 min",
ensure_all_time = TRUE,
verbose = FALSE
)
calculate_flags(df, unit = "1 min", ensure_all_time = TRUE)
calculate_n_idle(df, unit = "1 min", ensure_all_time = TRUE)
calculate_enmo(...)
calculate_ai_defined(...)
calculate_mad(df, unit = "1 min", ensure_all_time = TRUE, verbose = FALSE)
get_sample_rate(df, sample_rate = NULL)
calculate_auc(
df,
unit = "1 min",
sample_rate = NULL,
allow_truncation = FALSE,
ensure_all_time = TRUE,
verbose = TRUE
)
calculate_fast_mims(
df,
unit = "1 min",
dynamic_range = NULL,
sample_rate = NULL,
allow_truncation = TRUE,
ensure_all_time = TRUE,
verbose = TRUE,
...
)
calculate_mims(
df,
unit = "1 min",
dynamic_range = c(-6, 6),
ensure_all_time = TRUE,
...
)
Arguments
- df
An object with columns `X`, `Y`, and `Z` or an object of class `AccData`
- sample_rate
sample rate of data, if not specified in header of object
- 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 `second`, `minute`, `hour`, `day`, `week`, `month`, `bimonth`, `quarter`, `season`, `halfyear`, and `year`. Arbitrary unique English abbreviations as in the
period
constructor are allowed.- verbose
print diagnostic messages
- ...
additional arguments to pass to [MIMSunit::mims_unit]
- fix_zeros
Should
fix_zeros
be run before calculating the measures?- fill_in
if
fix_zeros = TRUE
, should the zeros be filled in with the last- by_second
Should the last observation carried forward be done only within the same second?
- trim
if
fix_zeros = TRUE
, should the time course be trimmed for zero values at the beginning and the end of the time course? observation carried forward?- dynamic_range
Dynamic range of the device, in gravity units
- calculate_mims
Should MIMS units be calculated?
- calculate_ac
Should Activity Counts from the
activityCounts
package be calculated?- flag_data
Should [SummarizedActigraphy::flag_qc()] be run? It will be executed after
fix_zeros
before any measure calculation- flags
the flags to calculate, passed to [SummarizedActigraphy::flag_qc()]
- ensure_all_time
if
TRUE
, then all times from the first to last times will be in the output, even if data during that time was not in the input- allow_truncation
truncate small values
Examples
file = system.file("extdata", "TAS1H30182785_2019-09-17.gt3x",
package = "SummarizedActigraphy")
res = read_actigraphy(file)
#> Input is a .gt3x file, unzipping to a temporary location first...
#> Unzipping gt3x data to /tmp/RtmpsiCePd
#> 1/1
#> Unzipping /home/runner/work/_temp/Library/SummarizedActigraphy/extdata/TAS1H30182785_2019-09-17.gt3x
#> === info.txt, log.bin extracted to /tmp/RtmpsiCePd/TAS1H30182785_2019-09-17
#> GT3X information
#> $ Serial Number :"TAS1H30182785"
#> $ Device Type :"Link"
#> $ Firmware :"1.7.2"
#> $ Battery Voltage :"4.18"
#> $ Sample Rate :100
#> $ Start Date : POSIXct, format: "2019-09-17 18:40:00"
#> $ Stop Date : POSIXct, format: "2019-09-18 19:00:00"
#> $ Last Sample Time : POSIXct, format: "2019-09-17 19:20:05"
#> $ TimeZone :"-04:00:00"
#> $ Download Date : POSIXct, format: "2019-09-17 19:20:05"
#> $ Board Revision :"8"
#> $ Unexpected Resets :"0"
#> $ Acceleration Scale:256
#> $ Acceleration Min :"-8.0"
#> $ Acceleration Max :"8.0"
#> $ Subject Name :"suffix_85"
#> $ Serial Prefix :"TAS"
#> Parsing GT3X data via CPP.. expected sample size: 240500
#> ---GT3X PARAMETERS
#> address: 0 key: 6 value: 1
#> address: 0 key: 7 value: 54703161
#> address: 0 key: 8 value: 8
#> address: 0 key: 9 value: 1534154836
#> address: 0 key: 13 value: 17235970
#> address: 0 key: 16 value: 3791650816
#> address: 0 key: 20 value: 0
#> address: 0 key: 21 value: 0
#> address: 0 key: 22 value: 0
#> address: 0 key: 23 value: 0
#> address: 0 key: 26 value: 2
#> address: 0 key: 28 value: 262013
#> address: 0 key: 29 value: 255
#> address: 0 key: 32 value: 16908288
#> address: 0 key: 37 value: 1024
#> address: 0 key: 38 value: 0
#> address: 0 key: 49 value: 2048
#> address: 0 key: 50 value: 88181047
#> address: 0 key: 51 value: 6.82667
#> address: 0 key: 55 value: 256
#> address: 0 key: 57 value: 333.87
#> address: 0 key: 58 value: 21
#> address: 0 key: 61 value: 2
#> address: 1 key: 0 value: 0
#> address: 1 key: 1 value: 872668711
#> address: 1 key: 2 (features) value: 388
#> address: 1 key: 3 value: 1
#> address: 1 key: 4 value: 4294967131
#> address: 1 key: 5 value: 4294967095
#> address: 1 key: 6 value: 4294967149
#> address: 1 key: 7 value: 298
#> address: 1 key: 8 value: 286
#> address: 1 key: 9 value: 300
#> address: 1 key: 10 value: 100
#> address: 1 key: 12 (start time) value: 1568745600
#> address: 1 key: 13 value: 1568833200
#> address: 1 key: 14 value: 1568745556
#> address: 1 key: 15 value: 74
#> address: 1 key: 16 value: 40
#> address: 1 key: 17 value: 72
#> address: 1 key: 20 value: 0
#> address: 1 key: 21 value: 0
#> address: 1 key: 33 value: 60000
#> address: 1 key: 34 value: 4294965247
#> address: 1 key: 35 value: 4294965190
#> address: 1 key: 36 value: 4294965237
#> address: 1 key: 37 value: 2051
#> address: 1 key: 38 value: 2000
#> address: 1 key: 39 value: 2048
#> address: 1 key: 40 value: 0
#> address: 1 key: 41 value: 1
#> address: 1 key: 42 value: 0
#> address: 1 key: 43 value: 4294967283
#> address: 1 key: 44 value: 0
#> address: 1 key: 45 value: 0
#> address: 1 key: 46 value: 0
#> ---END PARAMETERS
#>
#> Activity with Sample Size of 0
#> payload start: 1568747741
#> total_records: 214100
#> max_samples: 240500
#> Activity with Sample Size of 0
#> payload start: 1568747759
#> total_records: 215900
#> max_samples: 240500
#> Total Records: 216000
#> Scaling...
#> Creating dimnames
#> CPP returning
#> Done (in 0.496452808380127 seconds)
measures = calculate_measures(res, dynamic_range = NULL,
calculate_mims = FALSE)
#> Fixing Zeros with fix_zeros
#> Flagging data
#> Flagging Spikes
#> Flagging Interval Jumps
#> Flagging Spikes at Second-level
#> Flagging Repeated Values
#> Flagging Device Limit Values
#> Flagging Zero Values
#> Flagging 'Impossible' Values
#> Calculating ai0
#> Calculating MAD
#> Joining AI and MAD
#> Calculating AC
#> Calculating Axis-Specific Activity Counts
#> Summing up Axes
#> Joining AC
#> Joining flags
auc = calculate_auc(res)
#> Absolute values
#> Calculting trapezoids
#> Replacing first value as NA
#> Calculating AUCs
# \donttest{
mims = calculate_mims(res, dynamic_range = NULL)
#> ================================================================================
# }
if (requireNamespace("data.table", quietly = TRUE)) {
dt = data.table::as.data.table(res$data)
out = calculate_measures(dt, calculate_mims = FALSE, flag_data = FALSE)
}
#> Fixing Zeros with fix_zeros
#> Calculating ai0
#> Calculating MAD
#> Joining AI and MAD
#> Calculating AC
#> Calculating Axis-Specific Activity Counts
#> Summing up Axes
#> Joining AC