-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1219 from wadpac/work839_955_1028_1129
Revise and expand circadian rhythm and fragmentation analyses based on recent publications
- Loading branch information
Showing
57 changed files
with
1,719 additions
and
1,059 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,16 @@ Authors@R: c(person("Vincent T","van Hees",role=c("aut","cre"), | |
comment = c(ORCID = "0000-0002-6033-960X")), | ||
person(given = "Taren",family = "Sanders", role = "ctb"), | ||
person("Chenxuan","Zhao",role="ctb"), | ||
person("Ian","Meneghel Danilevicz", role="ctb", | ||
email="ian.meneghel-danilevicz @ inserm.fr", | ||
comment = c(ORCID = "0000-0003-4541-0524")), | ||
person("Victor","Barreto Mesquita", role="ctb", | ||
email="[email protected]"), | ||
person("Gaia","Segantin",role="ctb"), | ||
person("Medical Research Council UK", role = c("cph", "fnd")), | ||
person("Accelting", role = c("cph", "fnd")), | ||
person("French National Research Agency", role = c("cph", "fnd"))) | ||
person("French National Research Agency", role = c("cph", "fnd")) | ||
) | ||
Maintainer: Vincent T van Hees <[email protected]> | ||
Description: A tool to process and analyse data collected with wearable raw acceleration sensors as described in Migueles and colleagues (JMPB 2019), and van Hees and colleagues (JApplPhysiol 2014; PLoSONE 2015). The package has been developed and tested for binary data from 'GENEActiv' <https://activinsights.com/>, binary (.gt3x) and .csv-export data from 'Actigraph' <https://theactigraph.com> devices, and binary (.cwa) and .csv-export data from 'Axivity' <https://axivity.com>. These devices are currently widely used in research on human daily physical activity. Further, the package can handle accelerometer data file from any other sensor brand providing that the data is stored in csv format. Also the package allows for external function embedding. | ||
URL: https://github.com/wadpac/GGIR/, https://groups.google.com/forum/#!forum/RpackageGGIR, https://wadpac.github.io/GGIR/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# NOTE ABOUT DOCUMENTATION: | ||
# GGIR does not use Roxygen. The documentation below is not used. | ||
# All function documentation can be found in the man/*.Rd files. | ||
# Please edit documentation there. | ||
# | ||
#- @title Activity balance index (ABI) | ||
#- | ||
#- @description This function estimates the Activity balance index (ABI), which is a transformation of the self-similarity parameter (SSP), also known as scaling exponent or alpha. | ||
#- @param x the estimated self-similarity parameter (SSP) | ||
#- | ||
#- @details ABI = exp(-abs(SSP-1)/exp(-2)) | ||
#- | ||
#- @return The estimated Activity balance index (ABI) is a real number between zero and one. | ||
#- | ||
#- @author Ian Meneghel Danilevicz | ||
#- | ||
#- @references C.-K. Peng, S.V. Buldyrev, S. Havlin, M. Simons, H.E. Stanley, A.L. Goldberger Phys. Rev. E, 49 (1994), p. 1685 | ||
#- Mesquita, Victor & Filho, Florencio & Rodrigues, Paulo. (2020). Detection of crossover points in detrended fluctuation analysis: An application to EEG signals of patients with epilepsy. Bioinformatics. 10.1093/bioinformatics/btaa955. | ||
#- | ||
#- @examples | ||
#- # Estimate Activity balance index of a very known time series available on R base: the sunspot.year. | ||
#- | ||
#- ssp = SSP(sunspot.year, scale = 1.2) | ||
#- abi = ABI(ssp) | ||
#- | ||
ABI = function(x){ | ||
if (is.na(x)) { | ||
y = NA | ||
} else { | ||
y = exp(-abs(x - 1) * exp(2)) | ||
} | ||
return(y) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# NOTE ABOUT DOCUMENTATION: | ||
# GGIR does not use Roxygen. The documentation below is not used. | ||
# All function documentation can be found in the man/*.Rd files. | ||
# Please edit documentation there. | ||
# | ||
#- @title Detrended Fluctuation Analysis | ||
#- | ||
#- @description ... | ||
#- @usage DFA(data, scale = 2^(1/8), box_size = 4, m = 1) | ||
#- @param data Univariate time series (must be a vector or data frame) | ||
#- @param scale Specifies the ratio between successive box sizes (by default scale = 2^(1/8)) | ||
#- @param box_size Vector of box sizes (must be used in conjunction with scale = "F") | ||
#- @param m An integer of the polynomial order for the detrending (by default m=1) | ||
#- | ||
#- @details The DFA fluctuation can be computed in a geometric scale or for different choices of boxes sizes. | ||
#- | ||
#- @return Estimated alpha is a real number between zero and two. | ||
#- | ||
#- @note It is not possible estimating alpha for multiple time series at once. | ||
#- | ||
#- @author Ian Meneghel Danilevicz and Victor Mesquita | ||
#- | ||
#- @references C.-K. Peng, S.V. Buldyrev, S. Havlin, M. Simons, H.E. Stanley, A.L. Goldberger Phys. Rev. E, 49 (1994), p. 1685 | ||
#- Mesquita, Victor & Filho, Florencio & Rodrigues, Paulo. (2020). Detection of crossover points in detrended fluctuation analysis: An application to EEG signals of patients with epilepsy. Bioinformatics. 10.1093/bioinformatics/btaa955. | ||
#- | ||
#- @examples | ||
#- # Estimate self-similarity of a very known time series available on R base: the sunspot.year. | ||
#- # Then the spend time with each method is compared. | ||
#- | ||
|
||
DFA = function(data, scale = 2^(1/8), box_size = 4, m = 1){ | ||
if (inherits(x = data, "data.frame")) { | ||
data = data[, 1] | ||
} | ||
N = length(data) | ||
if (scale != "F") { | ||
box_size <- NULL | ||
n = 1 | ||
n_aux <- 0 | ||
box_size[1] <- 4 | ||
for (n in 1:N) { | ||
while (n_aux < round(N/4)) { | ||
n_aux <- box_size[1] | ||
n = n + 1 | ||
box_size[n] <- ceiling(scale * box_size[n - 1]) | ||
n_aux <- box_size[n] + 4 | ||
} | ||
} | ||
} | ||
ninbox2 <- NULL | ||
for (j in 1:length(box_size)) { | ||
ninbox2[j] <- N %/% box_size[j] | ||
} | ||
aux_seq = seq_along(ninbox2) | ||
aux_length = aux_seq[length(aux_seq)] | ||
y_k = cumsum(data) - mean(data) | ||
rm(data, n_aux, scale) | ||
aux_mat = matrix(nrow = aux_length, ncol = 2) | ||
for (j in seq_along(ninbox2)) { | ||
W = box_size[j] * ninbox2[j] | ||
aux_j = numeric(W) | ||
fit = y_k | ||
for (i in seq_len(W)) { | ||
if (i == 1) { | ||
aux_j[1] = box_size[j] | ||
tmp1 = i:aux_j[i] | ||
} else if (i >= 2) { | ||
aux_j[i] = aux_j[i - 1] + box_size[j] | ||
tmp1 = (aux_j[i - 1] + 1):(aux_j[i]) | ||
} | ||
if (m == 1) { | ||
fit[tmp1] = lm.fit(x = cbind(1, tmp1), y = y_k[tmp1])$fitted.values | ||
} else { | ||
fit[tmp1] = lm(y_k[tmp1] ~ poly(tmp1, m, raw = TRUE))$fitted.values | ||
} | ||
if (i >= ninbox2[j]) { | ||
aux_j[i] <- 0 | ||
} | ||
} | ||
aux_mat[j,] = c(round(box_size[j], digits = 0), | ||
sqrt((1 / N) * sum((y_k[1:W] - fit[1:W]) ^ 2))) | ||
} | ||
colnames(aux_mat) <- c("box", "DFA") | ||
aux_list = aux_mat | ||
return(aux_list) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# NOTE ABOUT DOCUMENTATION: | ||
# GGIR does not use Roxygen. The documentation below is not used. | ||
# All function documentation can be found in the man/*.Rd files. | ||
# Please edit documentation there. | ||
# | ||
#- @title Estimated self-similarity parameter | ||
#- | ||
#- @description This function estimates the self-similarity parameter (SSP), also known as scaling exponent or alpha. | ||
#- @usage alpha_hat(data,scale = 2^(1/8),box_size = 4,m=1) | ||
#- @param data Univariate time series (must be a vector or data frame) | ||
#- @param scale Specifies the ratio between successive box sizes (by default scale = 2^(1/8)) | ||
#- @param box_size Vector of box sizes (must be used in conjunction with scale = "F") | ||
#- @param m An integer of the polynomial order for the detrending (by default m=1) | ||
#- | ||
#- @details The DFA fluctuation can be computed in a geometric scale or for different choices of boxes sizes. | ||
#- | ||
#- @return Estimated alpha is a real number between zero and two. | ||
#- | ||
#- @note It is not possible estimating alpha for multiple time series at once. | ||
#- | ||
#- @author Ian Meneghel Danilevicz and Victor Mesquita | ||
#- | ||
#- @references C.-K. Peng, S.V. Buldyrev, S. Havlin, M. Simons, H.E. Stanley, A.L. Goldberger Phys. Rev. E, 49 (1994), p. 1685 | ||
#- Mesquita, Victor & Filho, Florencio & Rodrigues, Paulo. (2020). Detection of crossover points in detrended fluctuation analysis: An application to EEG signals of patients with epilepsy. Bioinformatics. 10.1093/bioinformatics/btaa955. | ||
#- | ||
#- @examples | ||
#- # Estimate self-similarity of a very known time series available on R base: the sunspot.year. | ||
#- # Then the spend time with each method is compared. | ||
#- | ||
#- SSP(sunspot.year, scale = 2) | ||
#- SSP(sunspot.year, scale = 1.2) | ||
|
||
SSP = function(data, scale = 2^(1/8), box_size = 4, m = 1){ | ||
if (inherits(x = data, "data.frame")) { | ||
data = data[, 1] | ||
} | ||
if (length(data) <= box_size || any(is.na(data))) { | ||
alpha_hat = NA | ||
} else { | ||
dfa_hat = DFA(data, scale = scale, box_size = box_size, m = m) | ||
est_ols = lm(log(dfa_hat[,2]) ~ log(dfa_hat[,1])) | ||
alpha_hat = est_ols$coefficients[[2]] | ||
} | ||
return(alpha_hat) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.