From c9d26af9ab43f940d092229001bdb2721fd58f28 Mon Sep 17 00:00:00 2001 From: Vincent van Hees Date: Wed, 20 Nov 2024 11:56:12 +0100 Subject: [PATCH] #1218 improve extraction of timewindow from log and ignore column with the word impute --- R/filterNonwearNight.R | 17 ++++++++++++++--- R/g.conv.actlog.R | 1 + man/GGIR.Rd | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/R/filterNonwearNight.R b/R/filterNonwearNight.R index d3dddddef..6b7524b31 100644 --- a/R/filterNonwearNight.R +++ b/R/filterNonwearNight.R @@ -53,10 +53,21 @@ filterNonwearNight = function(r1, metalong, qwindowImp, desiredtz, r1B$date = as.Date(metalong$time_POSIX) for (qi in 1:nrow(qwindowImp)) { qwindow_temp = qwindowImp$qwindow_values[[qi]] + # filter only SPT and time in bed reports + qwindow_temp = qwindow_temp[grep(pattern = "bed|wakeup|sleeponset", x = qwindowImp$qwindow_names[[qi]])] + qwindow_temp = sort(qwindow_temp) if (length(qwindow_temp) > 3) { - # if diary has at least two timestamps other than 0 and 24 - start = rev(qwindow_temp)[2] - end = qwindow_temp[2] + # convert to continuous scale to ease finding start and end + below18 = which(qwindow_temp < 18) + if (length(below18) > 0) { + qwindow_temp = qwindow_temp[below18] + 24 + } + start = min(qwindow_temp) + end = max(qwindow_temp) + if (length(below18) > 0) { + start = ifelse(start > 24, yes = start - 24, no = start) + end = ifelse(end > 24, yes = end - 24, no = end) + } if (start > end) { r1B$filterWindow[which(r1B$date == qwindowImp$date[qi] & r1B$hr >= start | diff --git a/R/g.conv.actlog.R b/R/g.conv.actlog.R index b03255801..c25655ed2 100644 --- a/R/g.conv.actlog.R +++ b/R/g.conv.actlog.R @@ -4,6 +4,7 @@ g.conv.actlog = function(qwindow, qwindow_dateformat="%d-%m-%Y", epochSize = 5) # local functions: time2numeric = function(x) { x = unlist(x) + x = x[grep(pattern = "impute", x = names(x), invert = TRUE)] c2t = function(x2) { tmp = as.numeric(unlist(strsplit(as.character(x2),":"))) if (length(tmp) == 2) hourinday = tmp[1] + (tmp[2]/60) diff --git a/man/GGIR.Rd b/man/GGIR.Rd index 1829c1bf6..e09b477d5 100644 --- a/man/GGIR.Rd +++ b/man/GGIR.Rd @@ -985,7 +985,7 @@ GGIR(mode = 1:5, defined by activity diary file and a diary entry is missing use midnight-6am as fall back setting. The main purpose of this functionality is to offer the option to ignore short lasting nonwear episodes during the night - when there is suspicious that these are falsely detect, e.g. in individuals + when there is suspicion that these are falsely detect, e.g. in individuals with extended motionless sleep periods caused by medication.} \item{nonwearFilterWindow}{