Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NA/NaN/Inf in 'y' induced by gcalibrateC #35

Closed
muschellij2 opened this issue May 14, 2024 · 1 comment · Fixed by #37
Closed

NA/NaN/Inf in 'y' induced by gcalibrateC #35

muschellij2 opened this issue May 14, 2024 · 1 comment · Fixed by #37

Comments

@muschellij2
Copy link
Contributor

NHANES File is located at https://figshare.com/articles/dataset/Accelerometer_file_that_s_failing_for_Resampling/25627848?file=46327363 and can be downloaded via: https://figshare.com/ndownloader/files/46327363,

url = "https://figshare.com/ndownloader/files/46327363"
file = tempfile(fileext = ".csv.gz")
download.file(url, file, quiet = FALSE)
library(agcounts)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(readr)


data = readr::read_csv(file,
                       col_types = 
                         readr::cols(
                           # HEADER_TIMESTAMP = col_datetime_with_frac_secs(),
                           HEADER_TIMESTAMP = vroom::col_datetime(),
                           X = vroom::col_double(),
                           Y = vroom::col_double(),
                           Z = vroom::col_double()
                         ))
probs = readr::problems(data)
stopifnot(nrow(probs) == 0)
readr::stop_for_problems(data)

head(data)
#> # A tibble: 6 × 4
#>   HEADER_TIMESTAMP         X     Y      Z
#>   <dttm>               <dbl> <dbl>  <dbl>
#> 1 2000-01-03 20:24:00 -0.032 0.053 -0.974
#> 2 2000-01-03 20:24:00 -0.032 0.053 -0.982
#> 3 2000-01-03 20:24:00 -0.032 0.047 -0.982
#> 4 2000-01-03 20:24:00 -0.032 0.053 -0.979
#> 5 2000-01-03 20:24:00 -0.032 0.053 -0.977
#> 6 2000-01-03 20:24:00 -0.032 0.053 -0.979
data = data %>%
  dplyr::rename(time = HEADER_TIMESTAMP)
# needed for fix of agcounts
# PR at https://github.com/bhelsel/agcounts/pull/32
data = as.data.frame(data)
attr(data, "sample_rate") = 80L
attr(data, "last_sample_time") = max(data$time)
xyz = c("X", "Y", "Z")

mat = as.matrix(data[, xyz])
# calibrated = agcalibrate(df, verbose = TRUE)
C <- agcounts:::gcalibrateC(dataset = mat, sf = 80L)
#> Loading chunk: 1 2
#> Error in (function (x, y, w, offset = NULL, method = "qr", tol = 1e-07, : NA/NaN/Inf in 'y'

Created on 2024-05-14 with reprex v2.1.0

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.1 (2023-06-16)
#>  os       macOS Sonoma 14.4.1
#>  system   x86_64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/New_York
#>  date     2024-05-14
#>  pandoc   3.1.11.1 @ /usr/local/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  agcounts    * 0.6.6   2024-04-10 [1] local
#>  bit           4.0.5   2022-11-15 [1] CRAN (R 4.3.0)
#>  bit64         4.0.5   2020-08-30 [1] CRAN (R 4.3.0)
#>  blob          1.2.4   2023-03-17 [1] CRAN (R 4.3.0)
#>  bslib         0.6.1   2023-11-28 [1] CRAN (R 4.3.0)
#>  cachem        1.0.8   2023-05-01 [1] CRAN (R 4.3.0)
#>  cli           3.6.2   2023-12-11 [1] CRAN (R 4.3.0)
#>  colorspace    2.1-0   2023-01-23 [1] CRAN (R 4.3.0)
#>  crayon        1.5.2   2022-09-29 [1] CRAN (R 4.3.0)
#>  data.table    1.14.10 2023-12-08 [1] CRAN (R 4.3.0)
#>  DBI           1.2.1   2024-01-12 [1] CRAN (R 4.3.0)
#>  digest        0.6.34  2024-01-11 [1] CRAN (R 4.3.0)
#>  dplyr       * 1.1.4   2023-11-17 [1] CRAN (R 4.3.0)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.3.0)
#>  evaluate      0.23    2023-11-01 [1] CRAN (R 4.3.0)
#>  fansi         1.0.6   2023-12-08 [1] CRAN (R 4.3.0)
#>  fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.3.0)
#>  fs            1.6.3   2023-07-20 [1] CRAN (R 4.3.0)
#>  generics      0.1.3   2022-07-05 [1] CRAN (R 4.3.0)
#>  GGIR          3.0-3   2024-01-11 [1] CRAN (R 4.3.0)
#>  ggplot2       3.5.0   2024-02-23 [1] CRAN (R 4.3.2)
#>  glue          1.7.0   2024-01-09 [1] CRAN (R 4.3.0)
#>  gsignal       0.3-5   2022-05-15 [1] CRAN (R 4.3.0)
#>  gtable        0.3.4   2023-08-21 [1] CRAN (R 4.3.0)
#>  hms           1.1.3   2023-03-21 [1] CRAN (R 4.3.0)
#>  htmltools     0.5.7   2023-11-03 [1] CRAN (R 4.3.0)
#>  htmlwidgets   1.6.4   2023-12-06 [1] CRAN (R 4.3.0)
#>  httpuv        1.6.13  2023-12-06 [1] CRAN (R 4.3.0)
#>  jquerylib     0.1.4   2021-04-26 [1] CRAN (R 4.3.0)
#>  jsonlite      1.8.8   2023-12-04 [1] CRAN (R 4.3.0)
#>  knitr         1.45    2023-10-30 [1] CRAN (R 4.3.0)
#>  later         1.3.2   2023-12-06 [1] CRAN (R 4.3.0)
#>  lattice       0.22-5  2023-10-24 [1] CRAN (R 4.3.0)
#>  lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.3.0)
#>  lubridate     1.9.3   2023-09-27 [1] CRAN (R 4.3.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.3.0)
#>  Matrix        1.6-5   2024-01-11 [1] CRAN (R 4.3.0)
#>  memoise       2.0.1   2021-11-26 [1] CRAN (R 4.3.0)
#>  mime          0.12    2021-09-28 [1] CRAN (R 4.3.0)
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.3.0)
#>  pillar        1.9.0   2023-03-22 [1] CRAN (R 4.3.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.3.0)
#>  png           0.1-8   2022-11-29 [1] CRAN (R 4.3.0)
#>  promises      1.2.1   2023-08-10 [1] CRAN (R 4.3.0)
#>  purrr         1.0.2   2023-08-10 [1] CRAN (R 4.3.0)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.3.0)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.3.0)
#>  R.oo          1.26.0  2024-01-24 [1] CRAN (R 4.3.2)
#>  R.utils       2.12.3  2023-11-18 [1] CRAN (R 4.3.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.3.0)
#>  Rcpp          1.0.12  2024-01-09 [1] CRAN (R 4.3.0)
#>  reactable     0.4.4   2023-03-12 [1] CRAN (R 4.3.0)
#>  read.gt3x     1.2.0   2022-06-30 [1] CRAN (R 4.3.0)
#>  readr       * 2.1.5   2024-01-10 [1] CRAN (R 4.3.0)
#>  reprex        2.1.0   2024-01-11 [1] CRAN (R 4.3.0)
#>  reticulate    1.35.0  2024-01-31 [1] CRAN (R 4.3.2)
#>  rlang         1.1.3   2024-01-10 [1] CRAN (R 4.3.0)
#>  rmarkdown     2.25    2023-09-18 [1] CRAN (R 4.3.0)
#>  RSQLite       2.3.5   2024-01-21 [1] CRAN (R 4.3.0)
#>  rstudioapi    0.16.0  2024-03-24 [1] CRAN (R 4.3.2)
#>  sass          0.4.8   2023-12-06 [1] CRAN (R 4.3.0)
#>  scales        1.3.0   2023-11-28 [1] CRAN (R 4.3.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.3.0)
#>  shiny         1.8.0   2023-11-17 [1] CRAN (R 4.3.0)
#>  stringi       1.8.3   2023-12-11 [1] CRAN (R 4.3.0)
#>  stringr       1.5.1   2023-11-14 [1] CRAN (R 4.3.0)
#>  styler        1.10.2  2023-08-29 [1] CRAN (R 4.3.0)
#>  tibble        3.2.1   2023-03-20 [1] CRAN (R 4.3.0)
#>  tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.3.0)
#>  timechange    0.3.0   2024-01-18 [1] CRAN (R 4.3.0)
#>  tzdb          0.4.0   2023-05-12 [1] CRAN (R 4.3.0)
#>  utf8          1.2.4   2023-10-22 [1] CRAN (R 4.3.0)
#>  vctrs         0.6.5   2023-12-01 [1] CRAN (R 4.3.0)
#>  vroom         1.6.5   2023-12-05 [1] CRAN (R 4.3.0)
#>  withr         3.0.0   2024-01-16 [1] CRAN (R 4.3.0)
#>  xfun          0.41    2023-11-01 [1] CRAN (R 4.3.0)
#>  xtable        1.8-4   2019-04-21 [1] CRAN (R 4.3.0)
#>  yaml          2.3.8   2023-12-11 [1] CRAN (R 4.3.0)
#>  zoo           1.8-12  2023-04-13 [1] CRAN (R 4.3.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library
#> 
#> ─ Python configuration ───────────────────────────────────────────────────────
#>  python:         /Users/johnmuschelli/miniconda3/bin/python3
#>  libpython:      /Users/johnmuschelli/miniconda3/lib/libpython3.11.dylib
#>  pythonhome:     /Users/johnmuschelli/miniconda3:/Users/johnmuschelli/miniconda3
#>  version:        3.11.4 (main, Jul  5 2023, 08:41:25) [Clang 14.0.6 ]
#>  numpy:          /Users/johnmuschelli/miniconda3/lib/python3.11/site-packages/numpy
#>  numpy_version:  1.25.2
#>  pygt3x:         /Users/johnmuschelli/miniconda3/lib/python3.11/site-packages/pygt3x
#>  
#>  NOTE: Python version was forced by RETICULATE_PYTHON
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@bhelsel
Copy link
Owner

bhelsel commented May 19, 2024

It looks like this issue is linked to lines 321-323 in the GGIR g.calibrate.R file where the authors state that there are some NaN values in the sphere data for ActiGraph monitor brands. I'm not sure if this is the case with other device brands too, but I edited line 277 in the agcounts R package to exclude these NaN values.

The code now reads:

if(curr(i, j) != 0 {
 closestpoint(i, j) = curr(i, j) / sqrt(rsum[i]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants