paulhibbing / AGread

Read Accelerometer Files from ActiGraph Accelerometers
Other
15 stars 4 forks source link

Rounding dev #32

Open muschellij2 opened 3 years ago

muschellij2 commented 3 years ago

Dev should have rounded values like legacy to 3 digits.

library(AGread)
#> package 'AGread' was built under R version 4.0.0
file <- system.file(
  "extdata", "example.gt3x", package = "AGread"
)
y = read_gt3x(file, parser = "legacy")
x = read_gt3x(file, parser = "dev")
head(x$RAW - y$RAW)
#>   Timestamp Accelerometer_X Accelerometer_Y Accelerometer_Z
#> 1    0 secs      0.00009375      0.00018750     -0.00006250
#> 2    0 secs      0.00034375      0.00018750     -0.00015625
#> 3    0 secs      0.00015625      0.00028125     -0.00006250
#> 4    0 secs      0.00015625      0.00028125     -0.00006250
#> 5    0 secs      0.00006250      0.00018750     -0.00015625
#> 6    0 secs      0.00006250      0.00018750     -0.00015625
xyz = paste0("Accelerometer_", c("X", "Y", "Z"))

all(abs(x$RAW[, xyz] - y$RAW[, xyz]) < 1e-5)
#> [1] FALSE

round_away_zero = function (x, n = 0) {
  return(sign(x) * trunc(abs(x) * 10^n + 0.5)/10^n)
}
for (i in xyz) {
  x$RAW[, i] = round_away_zero(x$RAW[, i], 3)
}
all(abs(x$RAW[, xyz] - y$RAW[, xyz]) < 1e-5)
#> [1] TRUE

Created on 2021-01-26 by the reprex package (v0.3.0.9001)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.0.2 (2020-06-22) #> os macOS Catalina 10.15.7 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz America/New_York #> date 2021-01-26 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> AGread * 1.1.1.9000 2021-01-26 [1] local #> anytime 0.3.9 2020-08-27 [1] CRAN (R 4.0.2) #> assertthat 0.2.1 2019-03-21 [2] CRAN (R 4.0.0) #> backports 1.2.0 2020-11-02 [1] CRAN (R 4.0.2) #> binaryLogic 0.3.9 2017-12-13 [2] CRAN (R 4.0.0) #> cli 2.2.0 2020-11-20 [1] CRAN (R 4.0.2) #> colorspace 2.0-0 2020-11-11 [1] CRAN (R 4.0.2) #> crayon 1.3.4 2017-09-16 [2] CRAN (R 4.0.0) #> data.table 1.13.2 2020-10-19 [1] CRAN (R 4.0.2) #> digest 0.6.27 2020-10-24 [1] CRAN (R 4.0.2) #> dplyr 1.0.2 2020-08-18 [2] CRAN (R 4.0.2) #> ellipsis 0.3.1 2020-05-15 [2] CRAN (R 4.0.0) #> evaluate 0.14 2019-05-28 [2] CRAN (R 4.0.0) #> fansi 0.4.1 2020-01-08 [2] CRAN (R 4.0.0) #> fs 1.5.0 2020-07-31 [2] CRAN (R 4.0.2) #> generics 0.1.0 2020-10-31 [1] CRAN (R 4.0.2) #> ggplot2 3.3.2 2020-06-19 [2] CRAN (R 4.0.0) #> glue 1.4.2 2020-08-27 [1] CRAN (R 4.0.2) #> gtable 0.3.0 2019-03-25 [2] CRAN (R 4.0.0) #> highr 0.8 2019-03-20 [2] CRAN (R 4.0.0) #> htmltools 0.5.0 2020-06-16 [2] CRAN (R 4.0.0) #> knitr 1.30 2020-09-22 [1] CRAN (R 4.0.2) #> lifecycle 0.2.0 2020-03-06 [2] CRAN (R 4.0.0) #> lubridate 1.7.9 2020-06-08 [2] CRAN (R 4.0.0) #> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.0.2) #> munsell 0.5.0 2018-06-12 [2] CRAN (R 4.0.0) #> PAutilities 1.0.1 2020-08-06 [2] local #> pillar 1.4.7 2020-11-20 [1] CRAN (R 4.0.2) #> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.0.0) #> purrr 0.3.4 2020-04-17 [2] CRAN (R 4.0.0) #> R6 2.5.0 2020-10-28 [1] CRAN (R 4.0.2) #> Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.2) #> reprex 0.3.0.9001 2020-09-30 [1] Github (tidyverse/reprex@d3fc4b8) #> rlang 0.4.9.9000 2020-12-11 [1] Github (r-lib/rlang@1939a71) #> rmarkdown 2.5 2020-10-21 [1] CRAN (R 4.0.2) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.0.2) #> scales 1.1.1 2020-05-11 [2] CRAN (R 4.0.0) #> sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 4.0.0) #> stringi 1.5.3 2020-09-09 [1] CRAN (R 4.0.2) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.0.0) #> styler 1.3.2 2020-02-23 [2] CRAN (R 4.0.0) #> tibble 3.0.4 2020-10-12 [1] CRAN (R 4.0.2) #> tidyselect 1.1.0 2020-05-11 [2] CRAN (R 4.0.0) #> vctrs 0.3.5 2020-11-17 [1] CRAN (R 4.0.2) #> withr 2.3.0 2020-09-22 [1] CRAN (R 4.0.2) #> xfun 0.19 2020-10-30 [1] CRAN (R 4.0.2) #> yaml 2.2.1 2020-02-01 [2] CRAN (R 4.0.0) #> #> [1] /Users/johnmuschelli/Library/R/4.0/library #> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library ```
paulhibbing commented 3 years ago

This was a conscious omission in dev, mostly because the legacy approach to rounding seemed ridiculously inefficient (see mid_round below). My main reason for rounding was to ensure I could replicate output from ActiLife. With dev, I didn't see a lot of value in rounding things off (although I would be surprised if the devices are precise past 3 digits). I still check dev against legacy and ActiLife when troubleshooting issues, but I've become comfortable with making those comparisons with a defined tolerance of 0.0015 g (see also PAutilities::test_errors). Are there other considerations you recommend?

https://github.com/paulhibbing/AGread/blob/ac1456d939b68857cf7bfc8b46ec79838cb412b2/src/helpers.cpp#L56

muschellij2 commented 3 years ago

I think rounding to 3 decimal places should be done as it's stated in https://github.com/actigraph/GT3X-File-Format/blob/main/LogRecords/Activity.md#scaling-activity-values and https://github.com/actigraph/GT3X-File-Format/blob/main/LogRecords/Activity2.md#scaling-activity-values

and specifically uses rounding away from zero. https://github.com/actigraph/GT3X-File-Format/blame/main/LogRecords/Activity.md#L226

My only concern is that I'd probably think to just use round, but that's not the same rounding as ActiLife. And also shows the data really only has 3 significant digits.

Best, John

On Tue, Jan 26, 2021 at 3:36 PM paulhibbing notifications@github.com wrote:

This was a conscious omission in dev, mostly because the legacy approach to rounding seemed ridiculously inefficient (see mid_round below). My main reason for rounding was to ensure I could replicate output from ActiLife. With dev, I didn't see a lot of value in rounding things off (although I would be surprised if the devices are precise past 3 digits). I still check dev against legacy and ActiLife when troubleshooting issues, but I've become comfortable with making those comparisons with a defined tolerance of 0.0015 g (see also PAutilities::test_errors https://github.com/paulhibbing/PAutilities/blob/master/R/test_errors.R). Are there other considerations you recommend?

https://github.com/paulhibbing/AGread/blob/ac1456d939b68857cf7bfc8b46ec79838cb412b2/src/helpers.cpp#L56

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/paulhibbing/AGread/issues/32#issuecomment-767812033, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIGPLTFNKRYUQVYWCFIKQTS34RVLANCNFSM4WT77YLA .