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

Facilitate research on comparing self-reported nap/nonwear with acc-based daytime rest detection #900

Merged
merged 48 commits into from
Sep 13, 2023
Merged
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
8069dba
progress on mapping overlap selfreported nonwear, nap and sibs #687
vincentvanhees Oct 19, 2022
64c02fc
splitting nap classification from sibreport analyses, first draft of …
vincentvanhees Oct 19, 2022
e527e45
limit sibanalyses to waking hours only
vincentvanhees Oct 19, 2022
39d23a2
#687 updating var names, addressing timestamp issue and including ext…
vincentvanhees Oct 21, 2022
632c5df
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Oct 24, 2022
409670f
#687 sibreport now has duration for selfreported naps and nonwear and…
vincentvanhees Oct 26, 2022
06aeeb7
#687 move code to separate function and add unit test
vincentvanhees Oct 26, 2022
d2fedee
merge master
vincentvanhees Nov 3, 2022
8090dfc
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Dec 5, 2022
9b82e13
merge master branch
vincentvanhees Dec 7, 2022
9f5a278
merge master
vincentvanhees Feb 27, 2023
502f153
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Mar 16, 2023
0f83af1
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Mar 24, 2023
1e17a81
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Mar 24, 2023
59719fa
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Mar 24, 2023
d6c924e
merge master
vincentvanhees Mar 24, 2023
852bad1
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Apr 28, 2023
d57721d
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Apr 29, 2023
d4b12ca
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees May 1, 2023
09563b7
merge master
vincentvanhees May 9, 2023
ac8f05b
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees May 10, 2023
1730e5c
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees May 11, 2023
db73f8f
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Jun 6, 2023
adeeab4
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Jun 6, 2023
37c165e
merge master
vincentvanhees Jun 18, 2023
d8b79c0
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Jun 18, 2023
e220dc1
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Jun 18, 2023
65e5cf3
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Jun 22, 2023
6e4b828
Merge branch 'master' into issue687_nap_enhancement2_test_merge_master
vincentvanhees Aug 2, 2023
59887b0
Merge branch 'master' into issue687_nap_test_merge_master
vincentvanhees Aug 31, 2023
b6e61da
Moving rest analyses to new g.part5_analyseSegment function #687
vincentvanhees Sep 1, 2023
9158f57
update documentation for previous commit
vincentvanhees Sep 1, 2023
b235928
make indentation align with rest of repo
vincentvanhees Sep 1, 2023
99501e7
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Sep 1, 2023
17e35e8
Merge branch 'master' into issue687_nap_enhancement2
vincentvanhees Sep 12, 2023
129c5bc
making sure rest analysis is not run when no sibreport object is avai…
vincentvanhees Sep 12, 2023
4ddaebe
Improving documentation for #687 and updating changelog
vincentvanhees Sep 12, 2023
6bfcc41
making sure code can run when nap_model is not specified
vincentvanhees Sep 12, 2023
fef0bd0
reusing argument possible_nap_duration to specify minimum sib duratio…
vincentvanhees Sep 12, 2023
848ebd5
Adding filter options for sibreport anlaysis #687
vincentvanhees Sep 12, 2023
ebbe8fa
Update NEWS.md
vincentvanhees Sep 12, 2023
cf90d60
fix typo in documentation
vincentvanhees Sep 12, 2023
c80331e
transform time in g.part5.analyseRest if needed
jhmigueles Sep 13, 2023
ee01f80
fix issue introduced in previous commit, make sure time is character …
jhmigueles Sep 13, 2023
708cfff
improve code comments
vincentvanhees Sep 13, 2023
00561e7
update to master
jhmigueles Sep 13, 2023
c21adc4
add check that input is character and condense code
vincentvanhees Sep 13, 2023
3c36304
Merge branch 'issue687_nap_enhancement2' of https://github.com/wadpac…
vincentvanhees Sep 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve code comments
vincentvanhees committed Sep 13, 2023
commit 708cfff66661fba53ab18bdb1e0fc06634e0f5ac
16 changes: 9 additions & 7 deletions R/g.part5.analyseRest.R
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ g.part5.analyseRest = function(sibreport = NULL, dsummary = NULL,
if (is.ISO8601(time[1])) {
time = iso8601chartime2POSIX(time, tz = tz)
}

# Only consider sib episodes with minimum duration
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)
@@ -26,7 +25,7 @@ g.part5.analyseRest = function(sibreport = NULL, dsummary = NULL,
srep_tmp = sibreport[which(sibreport$start > min(time) &
sibreport$end < max(time)),]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not getting the expected output when testing this, and it is because time here is introduced as ISO6801, but sibreport$start and sibreport$end are stored as POSIX objects, so the function was not able to find any srep_tmp.
I fixed this locally by introducing these lines at the begining of this function:

# transform time to POSIX
  if (is.ISO8601(time[1])) {
    time = iso8601chartime2POSIX(time, tz = tz)
  }

@vincentvanhees Should I commit this change or do you want to investigate why do you get the expected output and I don't?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please. I have been working so far with the csv variant of ms5.outraw. Maybe if you use the RData variant time is also stored different. It is good to facilitate both.


# account for possibility that some of these categories do not exis
# account for possibility that some of these categories do not exist
# identify overlapping and non-overlapping, (nap-sib, non-wear-sib, sib, nap, nonwear)
# calculate for all five categories number, total duration, mean duration
# for qc purposes:
@@ -49,29 +48,33 @@ g.part5.analyseRest = function(sibreport = NULL, dsummary = NULL,
if (length(sibs) > 0) {
classes = unique(srep_tmp$type)
selfreport = which(srep_tmp$type == "nonwear" | srep_tmp$type == "nap")
# summarise overlap between selfreported and accelerometer-based SIB
if (length(selfreport) > 0) {
for (si in sibs) {
for (sr in selfreport) {
# SIB overlap with selfreported behaviour
if (srep_tmp$start[si] <= srep_tmp$end[sr] &
srep_tmp$end[si] >= srep_tmp$start[sr]) {
end_overlap = as.numeric(pmin(srep_tmp$end[si], srep_tmp$end[sr]))
start_overlap = as.numeric(pmax(srep_tmp$start[si], srep_tmp$start[sr]))
duration_overlap = end_overlap - start_overlap
duration_sib = as.numeric(srep_tmp$end[si]) - as.numeric(srep_tmp$start[si])
# percentage of overlap
perc_overlap = round(100 * (duration_overlap / duration_sib), digits = 1)
if (srep_tmp$type[sr] == "nonwear") {
srep_tmp$SIBoverlapNonwear[si] = perc_overlap
} else if (srep_tmp$type[sr] == "nap") {
srep_tmp$SIBoverlapNap[si] = perc_overlap
}
}

# Selfreport behaviour overlap with SIB
if (srep_tmp$start[sr] <= srep_tmp$end[si] &
srep_tmp$end[sr] >= srep_tmp$start[si]) {
end_overlap = as.numeric(pmin(srep_tmp$end[si], srep_tmp$end[sr]))
start_overlap = as.numeric(pmax(srep_tmp$start[si], srep_tmp$start[sr]))
duration_overlap = end_overlap - start_overlap
duration_sr = as.numeric(srep_tmp$end[sr]) - as.numeric(srep_tmp$start[sr])
# percentage of overlap
perc_overlap = round(100 * (duration_overlap / duration_sr), digits = 1)
if (srep_tmp$type[sr] == "nonwear") {
srep_tmp$NonwearOverlapSIB[sr] = perc_overlap
@@ -84,7 +87,6 @@ g.part5.analyseRest = function(sibreport = NULL, dsummary = NULL,
}
}
}

sibs_indices = which(srep_tmp$type == "sib")
nap_indices = which(srep_tmp$type == "nap")
nonwear_indices = which(srep_tmp$type == "nonwear")
@@ -99,11 +101,11 @@ g.part5.analyseRest = function(sibreport = NULL, dsummary = NULL,
length(SIBoverlapNonwear_indices),
length(NapOverlapSIB_indices),
length(NonwearOverlapSIB_indices))

ds_names[fi:(fi + 6)] = c("nbouts_day_sib", "nbouts_day_srnap", "nbouts_day_srnonw",
"noverl_sib_srnap", "noverl_sib_srnonw",
"noverl_srnap_sib", "noverl_srnonw_sib")
fi = fi + 7
# mean and total duration in sib per day
if (length(sibs_indices) > 0) {
dsummary[di,fi:(fi + 1)] = c(mean(srep_tmp$duration[sibs_indices]),
sum(srep_tmp$duration[sibs_indices]))
@@ -112,6 +114,7 @@ g.part5.analyseRest = function(sibreport = NULL, dsummary = NULL,
}
ds_names[fi:(fi + 1)] = c("frag_mean_dur_sib_day", "dur_day_sib_min")
fi = fi + 2
# mean and total duration in self-reported naps per day
if (length(nap_indices) > 0) {
srep_tmp$duration[nap_indices] = (as.numeric(srep_tmp$end[nap_indices]) -
as.numeric(srep_tmp$start[nap_indices])) / 60
@@ -123,7 +126,7 @@ g.part5.analyseRest = function(sibreport = NULL, dsummary = NULL,

ds_names[fi:(fi + 1)] = c("frag_mean_dur_srnap_day", "dur_day_srnap_min")
fi = fi + 2

# mean and total duration in self-reported nonwear per day
if (length(nonwear_indices) > 0) {
dsummary[di,fi:(fi + 1)] = c(mean(srep_tmp$duration[nonwear_indices]),
sum(srep_tmp$duration[nonwear_indices]))
@@ -147,7 +150,6 @@ g.part5.analyseRest = function(sibreport = NULL, dsummary = NULL,
}
ds_names[fi:(fi + 2)] = c("mdur_sib_overl_srnap", "tdur_sib_overl_srnap", "perc_sib_overl_srnap")
fi = fi + 3

# Overlap srnap with sib
calcOverlapPercentage = function(overlap, duration) {
return(sum(overlap * duration) / sum(duration))