Skip to content

Commit

Permalink
Adding filter options for sibreport anlaysis #687
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentvanhees committed Sep 12, 2023
1 parent fef0bd0 commit 848ebd5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion R/check_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ check_params = function(params_sleep = c(), params_metrics = c(),
#-----------------------------------------------------------------------------------------
if (length(params_sleep) > 0) { # Check class of sleep parameters
numeric_params = c("anglethreshold", "timethreshold", "longitudinal_axis", "possible_nap_window", "possible_nap_dur",
"colid", "coln1", "def.noc.sleep", "nnights", "sleepefficiency.metric")
"colid", "coln1", "def.noc.sleep", "nnights", "sleepefficiency.metric", "possible_nap_edge_acc")
boolean_params = c("ignorenonwear", "constrain2range", "HASPT.ignore.invalid",
"relyonguider", "sleeplogidnum")
character_params = c("HASPT.algo", "HASIB.algo", "Sadeh_axis", "nap_model",
Expand Down
12 changes: 10 additions & 2 deletions R/g.part5.analyseRest.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
g.part5.analyseRest = function(sibreport = NULL, dsummary = NULL,
ds_names = NULL, fi = NULL, di = NULL,
time = NULL, tz = NULL, possible_nap_dur = NULL) {
time = NULL, tz = NULL, possible_nap_dur = 0,
possible_nap_edge_acc = Inf) {
# Only consider sib episodes with minimum duration
longboutsi = which((sibreport$type == "sib" & sibreport$duration >= possible_nap_dur) |
if (length(grep(pattern = "mean_acc_1min", x = colnames(sibreport))) > 0) {
sibreport$acc_edge = pmax(sibreport$mean_acc_1min_before, sibreport$mean_acc_1min_after)
} else {
sibreport$acc_edge = 0
}
longboutsi = which((sibreport$type == "sib" &
sibreport$duration >= possible_nap_dur[1] &
sibreport$acc_edge <= possible_nap_edge_acc) |
(sibreport$type != "sib" & sibreport$duration >= 1))
# for qc purposes:
dsummary[di,fi] = length(longboutsi)
Expand Down
3 changes: 2 additions & 1 deletion R/load_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ load_params = function(group = c("sleep", "metrics", "rawdata",
sleeplogsep = NULL, sleepwindowType = "SPT",
possible_nap_window = c(9, 18),
possible_nap_dur = c(15, 240),
nap_model = c(), sleepefficiency.metric = 1)
nap_model = c(), sleepefficiency.metric = 1,
possible_nap_edge_acc = Inf)
}
if ("metrics" %in% group) {
params_metrics = list(do.anglex = FALSE, do.angley = FALSE, do.anglez = TRUE,
Expand Down
9 changes: 7 additions & 2 deletions man/GGIR.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,10 @@ GGIR(mode = 1:5,
wake times). If 2, sleep efficiency is calculated as detected nocturnal
sleep time divided by detected duration in sleep period time plus sleep latency (where
sleep latency refers to the difference between log-derived sleep onset and
accelerometer-detected sleep onset).
accelerometer-detected sleep onset).}
\item{possible_nap_edge_acc}{
Minimum acceleration before or after the SIB for the nap to be considered.
}
}
}
Expand Down Expand Up @@ -1293,7 +1296,9 @@ GGIR(mode = 1:5,
In \link{g.part4}: To indicate whether to generate report for the sustained
inactivity bouts (SIB). If set to TRUE and when an advanced sleep diary is
available in part 4 then part 5 will use this to generate summary statistics
on the overlap between self-reported nonwear and napping with SIB}
on the overlap between self-reported nonwear and napping with SIB. Here,
SIB cna be filter based on argument possible_nap_edge_acc and the first value
of possible_nap_dur}
\item{do.visual}{
Boolean (default = TRUE).
Expand Down
11 changes: 10 additions & 1 deletion man/g.part5.analyseRest.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
\usage{
g.part5.analyseRest(sibreport = NULL, dsummary = NULL,
ds_names = NULL, fi = NULL,
di = NULL, time = NULL, tz = NULL)
di = NULL, time = NULL, tz = NULL,
possible_nap_dur = 0,
possible_nap_edge_acc = Inf)
}
\arguments{
\item{sibreport}{
Expand All @@ -35,6 +37,13 @@
\item{tz}{
Timezone database name
}
\item{possible_nap_dur}{
Minimum sib duration to be considered. For self-reported naps/nonwear
there is a minimum duration of 1 epoch.
}
\item{possible_nap_edge_acc}{
Maximum acceleration before or after the SIB for it to be considered.
}
}
\value{
List with updated objects dsummary, ds_names, fi, and di
Expand Down
7 changes: 1 addition & 6 deletions man/g.part5_analyseSegment.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
add_one_day_to_next_date,
lightpeak_available,
tail_expansion_log,
foldernamei, sibreport = NULL,
possible_nap_dur = NULL)
foldernamei, sibreport = NULL)
}
\arguments{
\item{indexlog}{
Expand Down Expand Up @@ -87,10 +86,6 @@
\item{sibreport}{
Sibreport object as passed on from \link{g.part5}
}
\item{possible_nap_dur}{
Minimum sib duration to be considered. For self-reported naps/nonwear
there is a minimum duration of 1 epoch.
}
}
\value{
List with objects: indexlog, timeList, and the matrix with the prelimenary results
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_load_check_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("load_params can load parameters", {

# Test length of objects
expect_equal(length(params), 8)
expect_equal(length(params$params_sleep), 21)
expect_equal(length(params$params_sleep), 22)
expect_equal(length(params$params_metrics), 41)
expect_equal(length(params$params_rawdata), 37)
expect_equal(length(params$params_247), 20)
Expand Down

0 comments on commit 848ebd5

Please sign in to comment.