walkabillylab / activitycounts Goto Github PK
View Code? Open in Web Editor NEWCreates ActiLife counts based on the raw acceleration data
Creates ActiLife counts based on the raw acceleration data
As discussed over e-mail, I have now removed activityCounts as a dependency of the GGIR package as there are a number of issues that worry me. If you need help addressing these then let me know.
The gain is being changed each time through the loop; to fix this, the result from multiplication should not be reassigned to B. That is, instead of
B = B * gain
fx8up = filter(B, A, datab)
the code should be simply
fx8up = filter(B * gain, A, datab)
When the input data is passed in tibble format, it throws the following error.
Error: Must subset rows with a valid subscript vector. x Can't convert from <double> to <integer> due to loss of precision.
library(activityCounts)
bad_input = dplyr::as_tibble(activityCounts::sampleXYZ)
activityCounts::counts(bad_input)
A data frame with counts:
Time x y z
1 2022-01-16 17:57:49 4 93 13
2 2022-01-16 17:57:50 21 50 14
3 2022-01-16 17:57:51 17 22 15
4 2022-01-16 17:57:52 22 39 23
5 2022-01-16 17:57:53 15 25 16
...
Error: Must subset rows with a valid subscript vector.
x Can't convert from <double> to <integer> due to loss of precision.
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning message:
In counts(data = dplyr::as_tibble(input), hertz = 100, x_axis = 2,
This bug report is created based on Karl Brown feedback.
What is the expected unit of measurement for the data argument in function counts()?
When I express the data in mg units the mean count is around 500, while when expressed in g it is around 3, so I am guessing the expected unit of measurement is mg. Can you please confirm?
Actigraph released code to calculate counts in Python: https://github.com/actigraph/agcounts
I believe there is a potentially big issue with the calculation of counts, as it is not agnostic to the labeling of axes. I believe if you passed in a vector of X or a vector of Y, you should get the same result as if you passed in all the data. If that is incorrect, please let me know.
The issue is the update of B
for each iteration: https://github.com/walkabillylab/activityCounts/blob/master/R/counts.R#L162 for the count filtering @khataei. Thus, the first axis has a value of B * gain
and the second is B * gain^2
and third is B * gain^3
. This is not likely what we want happening, correct?
Note in the code below, the column for z
is always the same, but that is only an artifact, not a representation of correctness. If I reordered the columns, it'd be off in the same way.
library(activityCounts)
data("sampleXYZ")
head(sampleXYZ)
#> Time accelerometer_X accelerometer_Y accelerometer_Z
#> 1 2019-01-01 03:30:00 -0.035 0.816 -0.063
#> 2 2019-01-01 03:30:00 -0.047 0.805 -0.023
#> 3 2019-01-01 03:30:00 -0.031 0.793 -0.008
#> 4 2019-01-01 03:30:00 -0.020 0.809 0.012
#> 5 2019-01-01 03:30:00 -0.016 0.844 0.023
#> 6 2019-01-01 03:30:00 -0.004 0.879 0.012
Here we use the correct columns and use the time column
sampleXYZ_counts <- counts(
data = sampleXYZ, hertz = 100,
x_axis = 2,y_axis = 3,z_axis = 4, time_column = 1)
head(sampleXYZ_counts)
#> Time x y z
#> 1 2019-01-01 03:30:00 4 89 11
#> 2 2019-01-01 03:30:01 21 48 13
#> 3 2019-01-01 03:30:02 17 19 14
#> 4 2019-01-01 03:30:03 22 39 22
#> 5 2019-01-01 03:30:04 15 21 15
#> 6 2019-01-01 03:30:05 23 40 34
Here simply reorder the columns so Y is first
data2 = sampleXYZ
data2 = data2[, c("Time", paste0("accelerometer_", c("Y", "X", "Z")))]
when we calculate counts, this lines up correctly (x is 3rd axis, y is 2nd)
sampleXYZ_counts2 <- counts(data = data2, hertz = 100,
x_axis = 3,y_axis = 2,z_axis = 4, time_column = 1)
head(sampleXYZ_counts2)
#> Time x y z
#> 1 2019-01-01 03:30:00 4 89 11
#> 2 2019-01-01 03:30:01 21 48 13
#> 3 2019-01-01 03:30:02 17 19 14
#> 4 2019-01-01 03:30:03 22 39 22
#> 5 2019-01-01 03:30:04 15 21 15
#> 6 2019-01-01 03:30:05 23 40 34
they are equal
all.equal(sampleXYZ_counts, sampleXYZ_counts2)
#> [1] TRUE
If we pass in the original data, but “incorrectly” specify the 3rd column is X
sampleXYZ_counts3 <- counts(data = sampleXYZ, hertz = 100,
x_axis = 3, y_axis = 2,z_axis = 4, time_column = 1)
head(sampleXYZ_counts3)
#> Time x y z
#> 1 2019-01-01 03:30:00 93 4 11
#> 2 2019-01-01 03:30:01 50 21 13
#> 3 2019-01-01 03:30:02 22 17 14
#> 4 2019-01-01 03:30:03 39 21 22
#> 5 2019-01-01 03:30:04 25 15 15
#> 6 2019-01-01 03:30:05 42 22 34
We see these are different, which is understandable because “x” means different things
all.equal(sampleXYZ_counts, sampleXYZ_counts3)
#> [1] "Component \"x\": Mean relative difference: 1.149771"
#> [2] "Component \"y\": Mean relative difference: 0.6900884"
If we reorder the columns it still persists, which means the method is
not agnostic to the order of the columns
sampleXYZ_counts3 = sampleXYZ_counts3[c("Time", "y", "x", "z")]
colnames(sampleXYZ_counts3) = c("Time", "x", "y", "z")
all.equal(sampleXYZ_counts, sampleXYZ_counts3)
#> [1] "Component \"x\": Mean relative difference: 0.09035909"
#> [2] "Component \"y\": Mean relative difference: 0.06063813"
head(sampleXYZ_counts)
#> Time x y z
#> 1 2019-01-01 03:30:00 4 89 11
#> 2 2019-01-01 03:30:01 21 48 13
#> 3 2019-01-01 03:30:02 17 19 14
#> 4 2019-01-01 03:30:03 22 39 22
#> 5 2019-01-01 03:30:04 15 21 15
#> 6 2019-01-01 03:30:05 23 40 34
head(sampleXYZ_counts3)
#> Time x y z
#> 1 2019-01-01 03:30:00 4 93 11
#> 2 2019-01-01 03:30:01 21 50 13
#> 3 2019-01-01 03:30:02 17 22 14
#> 4 2019-01-01 03:30:03 21 39 22
#> 5 2019-01-01 03:30:04 15 25 15
#> 6 2019-01-01 03:30:05 22 42 34
Created on 2022-03-24 by the reprex package (v2.0.1)
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.1.2 (2021-11-01)
#> os Debian GNU/Linux 10 (buster)
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate C.UTF-8
#> ctype C.UTF-8
#> tz Etc/UTC
#> date 2022-03-24
#> pandoc 2.14.0.3 @ /usr/lib/rstudio-server/bin/pandoc/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> activityCounts * 0.1.2 2019-07-31 [1] CRAN (R 4.1.2)
#> cli 3.2.0.9000 2022-03-16 [1] Github (r-lib/cli@51463d2)
#> crayon 1.5.0 2022-02-14 [1] CRAN (R 4.1.2)
#> digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.2)
#> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.2)
#> evaluate 0.15 2022-02-18 [1] CRAN (R 4.1.2)
#> fansi 1.0.2 2022-01-14 [1] CRAN (R 4.1.2)
#> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.2)
#> fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.2)
#> generics 0.1.2 2022-01-31 [1] CRAN (R 4.1.2)
#> glue 1.6.2 2022-02-24 [1] CRAN (R 4.1.2)
#> highr 0.9 2021-04-16 [1] CRAN (R 4.1.2)
#> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.0)
#> knitr 1.37 2021-12-16 [1] CRAN (R 4.1.2)
#> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.0)
#> lubridate 1.8.0 2021-10-07 [1] CRAN (R 4.1.0)
#> magrittr 2.0.2 2022-01-26 [1] CRAN (R 4.1.2)
#> MASS 7.3-54 2021-05-03 [4] CRAN (R 4.1.0)
#> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.1.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.2)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.0)
#> rlang 1.0.2 2022-03-04 [1] CRAN (R 4.1.2)
#> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.0)
#> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.2)
#> seewave 2.2.0 2022-03-04 [1] CRAN (R 4.1.2)
#> sessioninfo 1.2.2.9000 2022-03-16 [1] Github (r-lib/sessioninfo@27965c2)
#> signal 0.7-7 2021-05-25 [1] CRAN (R 4.1.0)
#> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.0)
#> stringr 1.4.0.9000 2021-12-14 [1] xgit ([email protected]:tidyverse/stringr.git@dd909b7)
#> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.1.0)
#> tuneR 1.3.3.1 2021-08-04 [1] CRAN (R 4.1.0)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0)
#> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.2)
#> withr 2.5.0 2022-03-03 [1] CRAN (R 4.1.2)
#> xfun 0.30 2022-03-02 [1] CRAN (R 4.1.2)
#> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.1.2)
#>
#> [1] /home/jupyter/.R/library
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
#>
#> ──────────────────────────────────────────────────────────────────────────────
Explain the input units.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.