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

segmentWalking cannot work for 10Hz data #18

Open
muschellij2 opened this issue Oct 18, 2023 · 0 comments
Open

segmentWalking cannot work for 10Hz data #18

muschellij2 opened this issue Oct 18, 2023 · 0 comments

Comments

@muschellij2
Copy link
Contributor

Issue

When using segmentWalking, if you are using a sampling frequency < 15, you will get an error. This is because the hard-coded parameter x.adept.ma.W is 0.2:

x.adept.ma.W = 0.2,

and segmentPattern calls get.x.smoothed:
x.smoothed <- get.x.smoothed(x = x,

which then calls windowSmooth:
x.smoothed <- windowSmooth(x = x, W = W, x.fs = x.fs)

where W = 0.2 and x.fs = 10 (or any x.fs < 12.5) will fail since W.vl <- round(W * x.fs) will be less than 3 and fail:

adept/R/windowSmooth.R

Lines 56 to 57 in d7165ad

W.vl <- round(W * x.fs)
if (W.vl < 3) stop("W.vl (refer to function's details description) must not be smaller than 3 vector indices. Define wider W averaging window length")

Proposed Solutions

  1. Either we don't hard code the parameters in segmentWalking (i.e. pass them through as arguments, with defaults as they are in the code now): downsides are that it may be different than the proposed "ADEPT" algorithm. Also, likely unclear to many users as to what x.adept.ma.W should be.
  2. Note in the documentation that if you have Hz < 13, then this will fail and to run segmentPattern separately
  3. Adapt x.adept.ma.W to the sample rate
  4. Adapt x.adept.ma.W for low frequency samples.

Issue: Reproducible Example

We took the example from adept::segmentWalking and show that this does indeed fail:

library(adeptdata)
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(adept)
xyz <-
  adeptdata::acc_walking_IU %>%
  filter(loc_id == "left_wrist", subj_id == "id86237981") %>%
  arrange(time_s) %>%
  select(v1 = x, v2 = y, v3 = z) %>%
  as.matrix()
# define raw accelerometry data sample frequency
xyz.fs <- 10

# define template list based on predefined templates
template_mat <- adeptdata::stride_template$left_wrist[[3]]
template <- list(
  template_mat[1, ],
  template_mat[2, ],
  template_mat[3, ]
)

# run walking segmentation
# (parallel supported, except for Windows; see run.parallel, run.parallel.cores args)
segmentWalking(xyz, xyz.fs, template)
#> Error in windowSmooth(x = x, W = W, x.fs = x.fs): W.vl (refer to function's details description) must not be smaller than 3 vector indices. Define wider W averaging window length

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

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.1 (2022-06-23)
#>  os       macOS Big Sur ... 10.16
#>  system   x86_64, darwin17.0
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/New_York
#>  date     2023-10-18
#>  pandoc   3.1.5 @ /usr/local/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  adept       * 1.2     2023-09-08 [1] Github (muschellij2/adept@211c36d)
#>  adeptdata   * 1.1     2021-03-28 [1] CRAN (R 4.2.0)
#>  cli           3.6.1   2023-03-23 [1] CRAN (R 4.2.0)
#>  colorspace    2.1-0   2023-01-23 [1] CRAN (R 4.2.0)
#>  data.table    1.14.9  2023-08-21 [1] local
#>  DBI           1.1.3   2022-06-18 [1] CRAN (R 4.2.0)
#>  digest        0.6.33  2023-07-07 [1] CRAN (R 4.2.0)
#>  dplyr       * 1.1.3   2023-09-03 [1] CRAN (R 4.2.0)
#>  dvmisc        1.1.4   2019-12-16 [1] CRAN (R 4.2.0)
#>  evaluate      0.21    2023-05-05 [1] CRAN (R 4.2.0)
#>  fansi         1.0.4   2023-01-22 [1] CRAN (R 4.2.0)
#>  fastmap       1.1.1   2023-02-24 [1] CRAN (R 4.2.0)
#>  fs            1.6.3   2023-07-20 [1] CRAN (R 4.2.0)
#>  generics      0.1.3   2022-07-05 [1] CRAN (R 4.2.0)
#>  ggplot2       3.4.3   2023-08-14 [1] CRAN (R 4.2.0)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.0)
#>  gtable        0.3.4   2023-08-21 [1] CRAN (R 4.2.0)
#>  htmltools     0.5.6   2023-08-10 [1] CRAN (R 4.2.0)
#>  httr          1.4.6   2023-05-08 [1] CRAN (R 4.2.0)
#>  kableExtra    1.3.4   2021-02-20 [1] CRAN (R 4.2.0)
#>  knitr         1.44    2023-09-11 [1] CRAN (R 4.2.0)
#>  lattice       0.21-8  2023-04-05 [1] CRAN (R 4.2.0)
#>  lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.2.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.0)
#>  MASS          7.3-60  2023-05-04 [1] CRAN (R 4.2.0)
#>  Matrix        1.6-0   2023-07-08 [1] CRAN (R 4.2.1)
#>  mitools       2.4     2019-04-26 [1] CRAN (R 4.2.0)
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.2.0)
#>  mvtnorm       1.2-2   2023-06-08 [1] CRAN (R 4.2.0)
#>  pillar        1.9.0   2023-03-22 [1] CRAN (R 4.2.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.2.0)
#>  pracma        2.4.2   2022-09-22 [1] CRAN (R 4.2.0)
#>  purrr         1.0.1   2023-01-10 [1] CRAN (R 4.2.0)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.2.0)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.2.0)
#>  R.oo          1.25.0  2022-06-12 [1] CRAN (R 4.2.0)
#>  R.utils       2.12.2  2022-11-11 [1] CRAN (R 4.2.0)
#>  R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.0)
#>  rbenchmark    1.0.0   2012-08-30 [1] CRAN (R 4.2.0)
#>  Rcpp          1.0.11  2023-07-06 [1] CRAN (R 4.2.0)
#>  reprex        2.0.2   2022-08-17 [1] CRAN (R 4.2.0)
#>  rlang         1.1.1   2023-04-28 [1] CRAN (R 4.2.0)
#>  rmarkdown     2.25    2023-09-18 [1] CRAN (R 4.2.0)
#>  rstudioapi    0.15.0  2023-07-07 [1] CRAN (R 4.2.0)
#>  rvest         1.0.3   2022-08-19 [1] CRAN (R 4.2.0)
#>  scales        1.2.1   2022-08-20 [1] CRAN (R 4.2.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.0)
#>  stringi       1.7.12  2023-01-11 [1] CRAN (R 4.2.0)
#>  stringr       1.5.0   2022-12-02 [1] CRAN (R 4.2.0)
#>  styler        1.10.1  2023-06-05 [1] CRAN (R 4.2.0)
#>  survey        4.2-1   2023-05-03 [1] CRAN (R 4.2.0)
#>  survival      3.5-5   2023-03-12 [1] CRAN (R 4.2.0)
#>  svglite       2.1.1   2023-01-10 [1] CRAN (R 4.2.0)
#>  systemfonts   1.0.4   2022-02-11 [1] CRAN (R 4.2.0)
#>  tab           5.1.1   2021-08-02 [1] CRAN (R 4.2.0)
#>  tibble        3.2.1   2023-03-20 [1] CRAN (R 4.2.0)
#>  tidyselect    1.2.0   2022-10-10 [1] CRAN (R 4.2.0)
#>  utf8          1.2.3   2023-01-31 [1] CRAN (R 4.2.0)
#>  vctrs         0.6.3   2023-06-14 [1] CRAN (R 4.2.0)
#>  viridisLite   0.4.2   2023-05-02 [1] CRAN (R 4.2.0)
#>  webshot       0.5.5   2023-06-26 [1] CRAN (R 4.2.0)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun          0.40    2023-08-09 [1] CRAN (R 4.2.0)
#>  xml2          1.3.5   2023-07-06 [1] CRAN (R 4.2.0)
#>  yaml          2.3.7   2023-01-23 [1] CRAN (R 4.2.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
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

No branches or pull requests

1 participant