This function processes epoch-level step count files (raw exports or GGIR output) and derives a comprehensive set of **daily** and **person-level** metrics. Metrics include total steps, cadence peaks, time and steps accumulated in predefined cadence bands, and time and steps in moderate, vigorous, and moderate-to-vigorous physical activity (MPA, VPA, MVPA).
The function writes two types of summary CSVs:
Day-level: One file per participant per day, stored in `outputdir/daySummary/`.
Person-level: A single file with aggregated averages across valid days per participant, stored as `outputdir/personSummary.csv`.
step.metrics(
datadir,
outputdir = "./",
idloc = "_",
cadence_bands = c(0, 1, 20, 40, 60, 80, 100, 120, Inf),
cadence_peaks = c(1, 30, 60),
cadence_MOD = 100,
cadence_VIG = 130,
includedaycrit = 10,
includeawakecrit = NULL,
includedaylengthcrit = 23,
exclude_pk30_0 = TRUE,
exclude_pk60_0 = TRUE,
time_format = NULL,
verbose = TRUE
)This function does not return an object. It writes:
<ID>_DaySum.csv in `outputdir/daySummary/` with daily metrics.
personSummary.csv in `outputdir/` with person-level averages.
Character. Path to the directory containing the step data. If processing GGIR output, provide the GGIR output folder (its name starts with `"output_"`); the function will then look inside `meta/ms2.out/`.
Character. Directory where results should be stored. Subfolders will be created as needed (`daySummary/`).
Character (default = `"_"`). Delimiter used to extract participant IDs from filenames (ID is expected before this string).
Numeric vector (default = `c(0, 1, 20, 40, 60, 80, 100, 120, Inf)`). Breakpoints (in steps/min) used to compute time and steps per cadence band.
Numeric vector (default = `c(1, 30, 60)`). Cadence peak values (e.g., peak 30 = mean of the top 30 cadence minutes).
Numeric (default = 100). Threshold cadence (steps/min) for moderate physical activity.
Numeric (default = 130). Threshold cadence (steps/min) for vigorous physical activity.
Numeric (default = 10). Minimum wear time in hours for a day to be considered valid.
Numeric (default = NULL). If GGIR part 5 outputs are available, use the proportion of awake time instead of wear time to define valid days.
Numeric (default = 23). Minimum day length (hours) for a day to be valid (only relevant if using GGIR part 5 outputs).
Logical (default = TRUE).
Logical (default = TRUE). Exclude days with zero values in the 60-minute cadence peak.
Character (default = NULL). Time format used when reading non-GGIR step files.
Logical (default = TRUE). Whether to print progress messages.
For each participant and day, the function computes:
Total steps per day
Cadence peak metrics (e.g., peak 1, 30, 60 minutes)
Minutes and steps in each cadence band
Minutes in MPA, VPA, and MVPA
Steps accumulated in MPA, VPA, and MVPA
Recording duration, valid wear time, and awake time (if GGIR available)
Person-level outputs include plain, weighted (weekday/weekend), and stratified (weekday/weekend separately) averages of all variables.
# \donttest{
datadir = system.file("extdata", "testfiles_fitbit", package = "stepmetrics")
step.metrics(datadir = datadir, outputdir = tempdir())
# }
Run the code above in your browser using DataLab