| Title: | Accelerometer Processing Methods for Cycle 7 of the CHMS |
| Version: | 7.1 |
| Description: | 'ActiGraph wGT3X-BT' accelerometer processing methods using the standardized workflow developed by Statistics Canada for cycle 7 of the Canadian Health Measures Survey (CHMS). The package promotes transparent and reproducible data processing while supporting the harmonization of analytical approaches among researchers wishing to align with Statistics Canada's methods. For general details about the processing methods, please consult Clarke J, Gribbon A, St-Laurent M, Ferrao T, Barnes J, Kuzik N, Colley R (2026) <doi:10.25318/82-003-x202600200001-eng>. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/statcan/chms |
| BugReports: | https://github.com/statcan/chms/issues |
| Depends: | R (≥ 4.1.0) |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.2 |
| Imports: | cli, DBI, dbplyr, dplyr, haven, hms, jsonlite, knitr, lubridate, mirai, mori, parallelly, purrr, R6, readr, rlang, RSQLite, stats, stringr, tidyr, utils, zoo |
| Suggests: | config, ggplot2, janitor, kableExtra, PhysicalActivity, quarto, scales, testthat, tibble |
| NeedsCompilation: | no |
| Packaged: | 2026-08-25 23:45:32 UTC; barnjoe |
| Author: | Joel Barnes [aut, cre], Janine Clarke [ctb], Rachel Colley [ctb], His Majesty the King in Right of Canada, as represented by Statistics Canada [cph] |
| Maintainer: | Joel Barnes <joel.barnes@statcan.gc.ca> |
| Repository: | CRAN |
| Date/Publication: | 2026-09-08 13:30:15 UTC |
R6 class: agd
Description
agd is an R6 class that runs a data processing pipeline on one or more jobs that include two .agd (ActiGraph; github.com/actigraph) accelerometer files with LowFrequencyExtension and Normal filters per participant. This class makes calls to the agd_worker R6 class.
Public fields
argsA list of arguments passed into
agd$new(). See documentation foragd$new()for details.logA tibble with
method,timestamp,status, andmessagevectors providing a record of events during the pipeline run.jobsA tibble with vectors based on the
argspassed intoagd$new()representing jobs to be run that are distributed across the number of CPUs set bycpu_maxinagd$new().resultsA list of five tibbles (
summary_full,summary_full_stc,summary_run,summary_sleeping_hours,summary_waking_hours) summarizing pipeline run(s).
Methods
Public methods
Method new()
This method creates an instance of an agd_worker class.
Usage
agd$new( id, age, agd_lfe, agd_nml, epoch_length = 60, day_max = 7, sleep_algo = "barreira", non_wear_algo = "barreira", start_date = NA, cpu_max = 1, dir = NA )
Arguments
idRequired: a vector representing unique participant ID(s).
ageRequired: an integer vector representing participant age(s) in years.
agd_lfeRequired: a character vector representing the full path to
.agdfile(s) with theLowFrequencyExtensionfilter.agd_nmlRequired: a character vector representing the full path to
.agdfile(s) with theNormalfilter.epoch_lengthRequired (default:
60): an integer vector (length-one or the same length asid) representing the epoch length(s) at which to process the data. Statistics Canada currently uses15for participants under 18 years and60for participants at all other ages. Note: ifsleep_algois set to"barreira"andepoch_lengthis set to15, the sleep algorithm will be applied to 60-second epoch data and the results will be applied to the 15-second epoch data.day_maxRequired (default:
7): an integer vector (length-one or the same length asid) representing the maximum number of days of data to load fromagd_lfeandagd_nml.sleep_algoRequired (default:
"barreira"): a character vector (length-one or the same length asid) representing the sleep algorithm to apply. Options currently include"barreira". Seeapply_barreira_algo()for more details.non_wear_algoRequired (default:
"barreira"): a character vector (length-one or the same length asid) representing the non-wear algorithm to apply. Options currently include"barreira","20-min-algo","60-min-algo","90-min-algo"and"choi". Seeapply_barreira_algo()andapply_non_wear_algo()for more details.start_dateOptional (default:
NA): a character or date vector (format: yyyy-mm-dd) that is length-one or the same length asidrepresenting the first day of data to load fromagd_lfeandagd_nml. If not set, data will be loaded from the first available day untilday_maxis reached.cpu_maxRequired (default:
1): a length-one integer vector representing the number of CPUs to distribute the data processing across.dirOptional (default:
NA): a length-one character vector representing the full path to the location where theresultslist will be exported tibble by tibble in.csvformat.
Returns
Returns an object of class agd.
Method run()
This method iterates jobs and calls run_agd_job().
Usage
agd$run()
Returns
Returns the results list from an agd_worker object and binds it to self (an instance of agd).
Method export()
This method exports self$results tibble by tibble in .csv format.
Usage
agd$export(dir = self$args$dir, stc = FALSE)
Arguments
dirOptional (default:
self$args$dir): a length-one character vector representing the full path to the location where theresultslist will be exported tibble by tibble in.csvformat.stcOptional (default:
FALSE): a length-one logical vector indicating whether to export only statcan-formatted results.
Returns
Returns the agd object (self) invisibly.
Method print()
This method renders details (arguments, issues, log) about an instance agd to the console.
Usage
agd$print()
Returns
Returns the agd object (self) invisibly.
Method sanity_check()
This method renders a sanity check report in .html format.
Usage
agd$sanity_check( name = "sanity-check-report", id = self$jobs$id, dir = self$args$dir, include_plot = FALSE )
Arguments
nameRequired (default:
"sanity-check-report"): a length-one character vector representing the file name of the report.idRequired (default:
self$jobs$id): a vector representing unique participant ID(s).dirRequired (default:
self$args$dir): a length-one character vector representing the full path to the location where the report will be exported in.htmlformat.include_plotOptional (default:
FALSE): a length-one logical vector representing whether to render scatterplots.
Returns
Returns an .html-formatted report.
Method view()
This method renders data frames from $results in tab.
Usage
agd$view(results = c(names(self$results), "issues", "log"))
Arguments
resultsOptional (default:
c(names(self$results), "issues", "log")): a character vector representing the results to render to tab. Options include:"summary_full","summary_full_stc","summary_run","summary_sleeping_hours","summary_waking_hours","issues","log".
Returns
Returns the agd object (self) invisibly.
Method clone()
The objects of this class are cloneable with this method.
Usage
agd$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
# Create meta data frame (external/non-statcan users)
meta <- data.frame(
id = c("jane-canuck", "john-canuck"),
age = c(10, 40),
agd_lfe = c(
system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
system.file("extdata", "john-canuck-lfe.agd", package = "chms")
),
agd_nml = c(
system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
system.file("extdata", "john-canuck-nml.agd", package = "chms")
),
start_date = c("2021-05-30", "2021-05-27"),
epoch_length = c(15, 60)
)
# Initialize agd R6 class
agd_data <- agd$new(
id = meta$id,
age = meta$age,
agd_lfe = meta$agd_lfe,
agd_nml = meta$agd_nml,
epoch_length = meta$epoch_length,
day_max = 2,
sleep_algo = "barreira",
non_wear_algo = "barreira",
start_date = meta$start_date,
cpu_max = 1
)
# Run data processing pipeline (load, clean, classify and summarize data)
agd_data$run()
R6 class: agd_worker
Description
agd_worker is an R6 class that runs a data processing pipeline on two .agd (ActiGraph; github.com/actigraph) accelerometer files with LowFrequencyExtension and Normal filters for a single participant. This class does all the heavy lifting for the agd R6 class.
Public fields
argsA list of arguments passed into
agd_worker$new(). See documentation foragd_worker$new()for details.dataA list of four tibbles created during
agd_worker$load()(settings,raw),agd_worker$clean()(clean) andagd_worker$classify()(classify) representing.agddata at various stages of the pipeline.issuesA list of seven length-one, dichotomous (
"yes"/"") character vectors (file_missing,files_identical,files_mismatched,non_midnight_start,no_complete_days,sleep_missing,age_out_of_range) representing flags for issues affecting pipeline results.logA tibble with
method,timestamp,statusandmessagevectors providing a record of events during the pipeline run.resultsA list of four tibbles (
summary_full,summary_full_stc,summary_sleeping_hours,summary_waking_hours) summarizing the pipeline run.
Methods
Public methods
Method new()
This method creates an instance of an agd_worker class.
Usage
agd_worker$new( id, age, agd_lfe, agd_nml, epoch_length = 60, day_max = 7, sleep_algo = "barreira", non_wear_algo = "barreira", start_date = NA )
Arguments
idRequired: a length-one vector representing a unique participant ID.
ageRequired: a length-one integer vector representing a participant's age in years.
agd_lfeRequired: a length-one character vector representing the full path to an
.agdfile with theLowFrequencyExtensionfilter.agd_nmlRequired: a length-one character vector representing the full path to an
.agdfile with theNormalfilter.epoch_lengthRequired (default:
60): a length-one integer vector representing the epoch length at which to process the data. Statistics Canada currently uses15for participants under 18 years and60for participants at all other ages. Note: ifsleep_algois set to"barreira"andepoch_lengthis set to15, the sleep algorithm will be applied to 60-second epoch data and the results will be applied to the 15-second epoch data.day_maxRequired (default:
7): a length-one integer vector representing the maximum number of days of data to load fromagd_lfeandagd_nml.sleep_algoRequired (default:
"barreira"): a length-one character vector representing the sleep algorithm to apply. Options currently include"barreira". Seeapply_barreira_algo()for more details.non_wear_algoRequired (default:
"barreira"): a length-one character vector representing the non-wear algorithm to apply. Options currently include"barreira","20-min-algo","60-min-algo","90-min-algo"and"choi". Seeapply_barreira_algo()andapply_non_wear_algo()for more details.start_dateOptional (default:
NA): a length-one date vector (format: yyyy-mm-dd) representing the first day of data to load fromagd_lfeandagd_nml. If not set, data will be loaded from the first available day untilday_maxis reached.
Returns
Returns an object of class agd_worker.
Method load()
This method calls load_agd_settings() and load_agd_data().
Usage
agd_worker$load()
Returns
Returns the agd_worker object (self) invisibly.
Method clean()
This method calls clean_agd_data().
Usage
agd_worker$clean()
Returns
Returns the agd_worker object (self) invisibly.
Method classify()
This method calls classify_agd_data().
Usage
agd_worker$classify()
Returns
Returns the agd_worker object (self) invisibly.
Method summarize()
This method calls summarize_agd_data().
Usage
agd_worker$summarize()
Returns
Returns the agd_worker object (self) invisibly.
Method run()
This method calls agd_worker$load(), agd_worker$clean(), agd_worker$classify() and agd_worker$summarize().
Usage
agd_worker$run()
Returns
Returns the agd_worker object (self) invisibly.
Method print()
This method renders details (arguments, issues, log) about an instance of agd_worker to the console.
Usage
agd_worker$print()
Returns
Returns the agd_worker object (self) invisibly.
Method clone()
The objects of this class are cloneable with this method.
Usage
agd_worker$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Run data processing pipeline (load, clean, classify and summarize data)
agd_data$run()
Classify an accelerometer axis vector of 60-second epochs as sleep time or awake time.
Description
This function uses the Barreira algorithm (pubmed.ncbi.nlm.nih.gov/25202840) to classify an accelerometer axis vector of 60-second epochs as sleep time or awake time. This function was validated against output from the official SAS version of the algorithm (www.pbrc.edu/pdf/PBRCSleepEpisodeTimeMacroCode.pdf).
Usage
apply_barreira_algo(
x,
time_stamp = "dataTimestamp",
axis1 = "axis1",
incline_off = "inclineOff",
incline_standing = "inclineStanding",
incline_sitting = "inclineSitting",
incline_lying = "inclineLying",
age,
return = "everything"
)
Arguments
x |
Required: a data frame of accelerometer data in 60-second epochs. |
time_stamp |
Required (default " |
axis1 |
Required (default: " |
incline_off |
Required (default: " |
incline_standing |
Required (default: " |
incline_sitting |
Required (default: " |
incline_lying |
Required (default: " |
age |
Required: a length-one integer vector representing the participant's age in years. This parameter is used to determine when the first sleep bout can begin. Statistics Canada sets the time to 18:00 for participants under five years and younger, and 19:00 for all other ages. |
return |
Required (default: " |
Value
Returns the data frame x along with all vectors that were derived while applying the Barreira algorithm.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Load and clean data
agd_data$load()$clean()
# Apply Barreira sleep algorithm
dt <- apply_barreira_algo(
x = agd_data$data$clean |>
dplyr::filter(
epoch_length == 60,
filter == "LowFrequencyExtension"
),
age = agd_data$args$age
)
Classify an accelerometer axis vector of epochs based on a set of bout rules.
Description
This function uses a general algorithm to classify an accelerometer axis vector of of epochs based on a set of bout rules.
Usage
apply_general_bout_algo(
x,
axis1 = "axis1",
is_wearing = "is_wearing",
min_bout_length = 10,
target_values,
max_exceptions = 2,
return = "everything"
)
Arguments
x |
Required: a data frame of accelerometer data. |
axis1 |
Required: a length-one character vector representing the name of the vertical axis (default: "axis1"). |
is_wearing |
Required: a character vector of "Yes" and "No" values representing wear time and non-wear time respectively (default: "is_wearing"). See |
min_bout_length |
Required: a length-one numeric vector representing the minimum number of epochs in a bout (default: 10). |
target_values |
Required: a numeric vector representing the epoch value(s) that belong to a bout. |
max_exceptions |
Required: a length-one numeric vector representing the maximum number of epochs permitted within a bout that is outside the range of the values in the |
return |
Required: a character vector representing which vectors to return (default: "everything"). If set to "everything", the data frame in the |
Value
Returns the data frame in the x argument along with all vectors that were derived while applying the bout algorithm.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Load, clean and classify data
agd_data$load()$clean()$classify()
# Look for 10+ minute bouts of moderate-intensity physical activity
dt <- apply_general_bout_algo(
x = agd_data$data$classify,
min_bout_length = 10 * (60 / agd_data$args$movement_epoch_length),
target_values = 574:1002,
max_exceptions = 2 * (60 / agd_data$args$movement_epoch_length),
return = c("dataTimestamp", "axis1", "in_bout")
)
# Get bout lengths
rle(dt$in_bout)
Classify an accelerometer axis vector of epochs as wear time or non-wear time based on a set of bout rules.
Description
This function uses a general algorithm to classify an accelerometer axis vector of epochs as wear time or non-wear time based on a set of bout rules
Usage
apply_non_wear_algo(
x,
axis1 = "axis1",
min_bout_length = 90,
target_values,
max_exceptions = 2,
return = "everything"
)
Arguments
x |
Required: a data frame of accelerometer data. |
axis1 |
Required: a length-one character vector representing the name of the vertical axis (default: "axis1"). |
min_bout_length |
Required: a length-one numeric vector representing the minimum number of epochs in a bout (default: 10). |
target_values |
Required: a numeric vector representing the epoch value(s) that belong to a bout. |
max_exceptions |
Required: a length-one numeric vector representing the maximum number of epochs permitted within a bout that outside the range of the values in the |
return |
Required: a character vector representing which vectors to return (default: "everything"). If set to "everything", the data frame in the |
Value
Returns the data frame in the x argument along with all vectors that were derived while applying the bout algorithm.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Load and clean data
agd_data$load()$clean()
# Apply Barreira sleep algorithm
dt <- apply_barreira_algo(
x = agd_data$data$clean |>
dplyr::filter(
epoch_length == 60,
filter == "LowFrequencyExtension"
),
age = agd_data$args$age
)
# Apply general non-wear algorithm
dt <- apply_non_wear_algo(
x = dt,
min_bout_length = 60,
target_values = 0,
max_exceptions = 2,
return = c("is_wearing", "is_sleeping", "ymd_hm")
)
Classify an accelerometer axis vector of 60-second epochs as sleep time or awake time.
Description
This function uses the Sadeh algorithm (https://pubmed.ncbi.nlm.nih.gov/7939118) to classify an accelerometer axis vector of 60-second epochs as sleep time or awake time.
Usage
apply_sadeh_algo(
x,
axis1 = "axis1",
censor_counts = FALSE,
return = "everything"
)
Arguments
x |
Required: a data frame of accelerometer data. |
axis1 |
Required default ( |
censor_counts |
Optional (default: |
return |
Required (default: |
Value
Returns x along with all vectors that were derived while applying the Sadeh algorithm. Note: values in the sadeh_sleep_score vector that are greater than -4 are interpreted as sleep time (see https://actigraphcorp.my.site.com/support/s/article/Where-can-I-find-documentation-for-the-Sadeh-and-Cole-Kripke-algorithms).
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Load and clean data
agd_data$load()$clean()
# Apply Sadeh sleep algorithm
dt <- apply_sadeh_algo(
x = agd_data$data$clean |>
dplyr::filter(
epoch_length == 60,
filter == "LowFrequencyExtension"
)
)
Classify an accelerometer axis vector of 60-second epochs as sleep time or awake time.
Description
This function uses the Tudor-Locke algorithm (https://pubmed.ncbi.nlm.nih.gov/24383507) to classify an accelerometer axis vector of 60-second epochs as sleep time or awake time. This function was validated indirectly against output from the official SAS version of the Barreira algorithm (www.pbrc.edu/pdf/PBRCSleepEpisodeTimeMacroCode.pdf).
Usage
apply_tudor_locke_algo(
x,
time_stamp = "dataTimestamp",
axis1 = "axis1",
incline_off = "inclineOff",
incline_standing = "inclineStanding",
incline_sitting = "inclineSitting",
incline_lying = "inclineLying",
return = "everything"
)
Arguments
x |
Required: a data frame of accelerometer data in 60-second epochs. |
time_stamp |
Required (default: |
axis1 |
Required (default: |
incline_off |
Required (default: |
incline_standing |
Required (default: |
incline_sitting |
Required (default: |
incline_lying |
Required (default: |
return |
Required (default: |
Value
Returns x along with all vectors that were derived while applying the Tudor-Locke algorithm.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Load and clean data
agd_data$load()$clean()
# Apply Tudor-Locke sleep algorithm
dt <- apply_tudor_locke_algo(
x = agd_data$data$clean |>
dplyr::filter(
epoch_length == 60,
filter == "LowFrequencyExtension"
)
)
Classify epochs in an ActiGraph .agd file.
Description
This function classifies epochs in an ActiGraph .agd file.
Usage
classify_agd_data(x)
Arguments
x |
Required: an agd_worker object. |
Value
Returns NULL invisibly.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Load and clean data
agd_data$load()$clean()
# Classify data
classify_agd_data(agd_data)
# Store updated data
dt <- agd_data$data$classify
Prepare an ActiGraph .agd file for downstream classification.
Description
This function prepares an ActiGraph .agd file for downstream classification (e.g., remove incomplete days, aggregate data to 60-second epochs).
Usage
clean_agd_data(x)
Arguments
x |
Required: an agd_worker object. |
Value
Returns a NULL invisibly.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Load data
agd_data$load()
# Clean data
clean_agd_data(agd_data)
# Store updated data
dt <- agd_data$data$clean
Gets CHMS participant metadata.
Description
This function gets CHMS participant metadata.
Usage
get_chms_meta(
clinic_file,
agd_dir,
clinic_id = "CLINICID",
site = "SITE",
age = "CLC_AGE",
day = "V2_DAY",
month = "V2_MTH",
year = "V2_YEAR"
)
Arguments
clinic_file |
Required: a length-one character vector representing the full path to the clinic file. Note: a |
agd_dir |
Required: a character vector representing the full path(s) to the site directory ("full/path/to/data/site"). |
clinic_id |
Required (default: |
site |
Required (default: |
age |
Required (default: |
day |
Required (default: |
month |
Required (default: |
year |
Required (default: |
Value
Returns a tibble with eight vectors (id, age, site, agd_lfe, agd_nml, mec_visit_date, start_date, epoch_length).
Examples
# Create participant meta (statcan users)
meta <- get_chms_meta(
clinic_file = "path/to/clinic/file.sas7bdat",
agd_dir = "path/to/agd/files/site",
clinic_id = "CLINICID",
site = "SITE",
age = "CLC_AGE",
day = "V2_DAY",
month = "V2_MTH",
year = "V2_YEAR"
)
Load the data table from an ActiGraph .agd file.
Description
This function loads the data table from an ActiGraph .agd file.
Usage
load_agd_data(
file,
col_select = "everything",
day_max = 7,
start_date,
settings
)
Arguments
file |
Required: a length-one character vector representing the full path to an |
col_select |
Required (default: " |
day_max |
Required (default: |
start_date |
Optional: a length-one date vector (format: yyyy-mm-dd) representing the first day of data to load from |
settings |
Optional: a tibble from |
Value
Returns a tibble of the data table.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Load data with low frequency extension
dt <- load_agd_data(
file = agd_data$args$agd_lfe,
start_date = agd_data$args$start_date
)
Load the settings table from an ActiGraph .agd file.
Description
This function loads the settings table from an ActiGraph .agd file.
Usage
load_agd_settings(file)
Arguments
file |
Required: a length-one character vector representing the full path to an |
Value
Returns a tibble of the settings table in a wide shape.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Load ActiGraph settings
dt <- load_agd_settings(agd_data$args$agd_lfe)
Plot method for the agd R6 class.
Description
This method renders scatter plots iteratively and interactively using results from an agd object.
Usage
## S3 method for class 'agd'
plot(x, ..., id)
Arguments
x |
Required: an agd object. |
... |
Optional: arguments to be passed to methods. Note: currently not used. |
id |
Optional: a vector representing participant IDs in |
Value
Returns ggplot2 objects invisibly.
Examples
# Initialize agd R6 class
agd_data <- agd$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 2,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Run data processing pipeline (load, clean, classify and summarize data)
agd_data$run()
# Plot data
plot(agd_data)
Plot method for the agd_worker R6 class.
Description
This method renders a scatter plot using results from an agd_worker object.
Usage
## S3 method for class 'agd_worker'
plot(x, ..., title_size = 11, axis_size = 9, label_size = 3)
Arguments
x |
Required: an agd_worker object. |
... |
Optional: arguments to be passed to methods. Note: currently not used. |
title_size |
Required (default: |
axis_size |
Required (default: |
label_size |
Required (default: |
Value
Returns a ggplot2 object invisibly.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 2,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Run data processing pipeline (load, clean, classify and summarize data)
agd_data$run()
# Plot data
plot(agd_data)
Run a job that initiates an ActiGraph data processing pipeline for a single participant.
Description
This function runs a job that processes ActiGraph data for a single participant by calling agd_worker$new()$run(). This function is used heavily by the agd R6 class.
Usage
run_agd_job(x)
Arguments
x |
Required: a one-row tibble from an agd object |
Value
Returns the results list from an agd_worker object.
Examples
# Create meta data frame (external/non-statcan users)
meta <- data.frame(
id = c("jane-canuck", "john-canuck"),
age = c(10, 40),
agd_lfe = c(
system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
system.file("extdata", "john-canuck-lfe.agd", package = "chms")
),
agd_nml = c(
system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
system.file("extdata", "john-canuck-nml.agd", package = "chms")
),
start_date = c("2021-05-30", "2021-05-27"),
epoch_length = c(15, 60)
)
# Initialize agd R6 class
agd_data <- agd$new(
id = meta$id,
age = meta$age,
agd_lfe = meta$agd_lfe,
agd_nml = meta$agd_nml,
epoch_length = meta$epoch_length,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira",
start_date = meta$start_date,
cpu_max = 2
)
# Run data processing pipeline (load, clean, classify and summarize data)
# on first participant in agd_data
lst <- run_agd_job(agd_data$jobs[1,])
Summarizes an ActiGraph .agd file.
Description
This function summarizes an ActiGraph .agd file.
Usage
summarize_agd_data(x)
Arguments
x |
Required: an agd_worker object. |
Value
Returns a NULL invisibly.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Load, clean and classify data
agd_data$load()$clean()$classify()
# Summarize data
summarize_agd_data(agd_data)
# Store updated data
dt <- agd_data$results$summary_full
Summary method for the agd R6 class.
Description
This method renders summary tibbles for waking and sleeping hours from an agd object to the console.
Usage
## S3 method for class 'agd'
summary(object, ..., row_max = 10)
Arguments
object |
Required: an agd_worker object. |
... |
Optional: additional arguments affecting the summary produced. Note: currently not used. |
row_max |
Required (default: |
Value
Returns NULL invisibly.
Examples
# Create meta data frame (external/non-statcan users)
meta <- data.frame(
id = c("jane-canuck", "john-canuck"),
age = c(10, 40),
agd_lfe = c(
system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
system.file("extdata", "john-canuck-lfe.agd", package = "chms")
),
agd_nml = c(
system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
system.file("extdata", "john-canuck-nml.agd", package = "chms")
),
start_date = c("2021-05-30", "2021-05-27"),
epoch_length = c(15, 60)
)
# Initialize agd R6 class
agd_data <- agd$new(
id = meta$id,
age = meta$age,
agd_lfe = meta$agd_lfe,
agd_nml = meta$agd_nml,
epoch_length = meta$epoch_length,
day_max = 2,
sleep_algo = "barreira",
non_wear_algo = "barreira",
start_date = meta$start_date,
cpu_max = 1
)
# Run data processing pipeline (load, clean, classify and summarize data)
agd_data$run()
# Summarize data
summary(agd_data)
Summary method for the agd_worker R6 class.
Description
This method renders summary tibbles for waking and sleeping hours from an agd_worker object to the console.
Usage
## S3 method for class 'agd_worker'
summary(object, ...)
Arguments
object |
Required: an agd_worker object. |
... |
Optional: additional arguments affecting the summary produced. Note: currently not used. |
Value
Returns NULL invisibly.
Examples
# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
id = "jane-canuck",
age = 10,
agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
epoch_length = 15,
day_max = 3,
sleep_algo = "barreira",
non_wear_algo = "barreira"
)
# Run data processing pipeline (load, clean, classify and summarize data)
agd_data$run()
# Summarize data
summary(agd_data)