bhelsel / agcounts

R package for extracting actigraphy counts from accelerometer data.
Other
9 stars 5 forks source link

Using agcalibrate with agread #28

Open bhelsel opened 1 year ago

bhelsel commented 1 year ago

Problem using the agcalibrate function if the data are read into R with agcounts::agread. Adding an issue as a reminder to look into this problem more.

library(read.gt3x)
library(agcounts)
library(magrittr)

path <- system.file("extdata/example.gt3x", package = "agcounts")

Currently, a user can read in the data without imputed zeros from the read.gt3x package and it can be passed to agcalibrate for GGIR autocalibration.

calibrated_data1 <-  
  read.gt3x::read.gt3x(path, asDataFrame = TRUE) %>%
  agcounts::agcalibrate()

However, it won’t work when you read it with agread. If you use the read.gt3x parser, it will give an error because of the imputed zeros argument set to TRUE. And when trying to use the pygt3x parser from agread, the time stamps are not merging correctly. Consequently, you get twice as many time stamps as the original file when using only the agread function and no autocalibration with agcalibrate.

pygt3x <- agcounts::agread(path, parser = "pygt3x")

calibrated_data3 <- agcounts::agcalibrate(pygt3x)
#> Loading chunk: 1
#> 
#>  There is not enough data to perform the GGIR calibration method. Returning data as read by read.gt3x.

nrow(calibrated_data3)
#> [1] 35721
nrow(pygt3x) 
#> [1] 18000
nrow(calibrated_data3) - nrow(pygt3x)
#> [1] 17721

Created on 2023-10-04 with reprex v2.0.2