Skip to content

R package for extracting actigraphy counts from accelerometer data.

License

Notifications You must be signed in to change notification settings

srlamunion/agcounts

 
 

Repository files navigation

agcounts

This R Package reads the X, Y, and Z axes in a GT3X accelerometer file and converts it to Actigraphy counts. This work was inspired by Neishabouri et al. who released a preprint of "Quantification of Acceleration as Activity Counts in ActiGraph Wearables" on February 24, 2022. Here are the links to the article and Python implementation of this code on GitHub.


Install

Install the devtools package if it is not already installed
install.packages("devtools")
Use the install_github function to download agcounts from GitHub
devtools::install_github("bhelsel/agcounts")
Load the agcounts package
library(agcounts)

Reading Files

Convert and read in a single GT3X file to R
# path = "Full pathname to the GT3X file", e.g.:
path = system.file("extdata/example.gt3x", package = "agcounts")

get_counts(path = path, epoch = 60, write.file = FALSE, return.data = TRUE)

Writing Files

Convert a single GT3X file to a CSV file
# path = "Full pathname to the GT3X file", e.g.:
path = system.file("extdata/example.gt3x", package = "agcounts")

get_counts(path = path, epoch = 60, write.file = TRUE, return.data = FALSE)
Convert multiple GT3X files to a CSV file
folder = "Full pathname to the folder where the GT3X files are stored"

files = list.files(path = folder, pattern = ".gt3x", full.names = TRUE)

sapply(files, get_counts, epoch = 60, write.file = TRUE, return.data = FALSE)
Speed up processing time by using the parallel package
folder = "Full pathname to the folder where the GT3X files are stored"

files = list.files(path = folder, pattern = ".gt3x", full.names = TRUE)

cores = parallel::detectCores()

Ncores = cores - 1

cl = parallel::makeCluster(Ncores)

doParallel::registerDoParallel(cl)

`%dopar%` = foreach::`%dopar%`

foreach::foreach(i = files, .packages = "agcounts") %dopar% {
  get_counts(path = i, epoch = 60, write.file = TRUE, return.data = FALSE)
}

parallel::stopCluster(cl)

About

R package for extracting actigraphy counts from accelerometer data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • R 100.0%