Skip to content

Commit

Permalink
correct sleep efficiency calculation part 4, fixes #1157
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentvanhees committed Jun 24, 2024
1 parent 3db6b5a commit 87b07ef
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# CHANGES IN GGIR VERSION 3.1-2

- Part 4: Correct calculation of sleep efficiency for `sleepefficiency.metric = 1`, fixed #1157

- Parts 2-5: Give more informative error when folders with expected milestone files are empty. #1144

- Report part 5: fix bug that was introduced on 2024-Feb-19 in the calculation of wear percentage #1148
Expand Down
4 changes: 2 additions & 2 deletions R/g.part4.R
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,9 @@ g.part4 = function(datadir = c(), metadatadir = c(), f0 = f0, f1 = f1,
digits = 7) #sleeponset - guider_onset
# sleep efficiency:
if (params_sleep[["sleepefficiency.metric"]] == 1) {
nightsummary[sumi, 26] = round(nightsummary[sumi, 14]/nightsummary[sumi, 9], digits = 5) #accumulated nocturnal sleep / guider
nightsummary[sumi, 26] = round(nightsummary[sumi, 14]/nightsummary[sumi, 5], digits = 5) # accumulated sleep in spt / duration of spt
} else if (params_sleep[["sleepefficiency.metric"]] == 2) {
nightsummary[sumi, 26] = round(nightsummary[sumi, 14]/(nightsummary[sumi, 5] + nightsummary[sumi, 25]), digits = 5) #accumulated nocturnal sleep / detected spt + latency
nightsummary[sumi, 26] = round(nightsummary[sumi, 14]/(nightsummary[sumi, 5] + nightsummary[sumi, 25]), digits = 5) # accumulated sleep in spt / duration of spt + latency
}
}
nightsummary[sumi, 27] = pagei
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_chainof5parts.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ test_that("chainof5parts", {
load(rn[1])
expect_true("sleeplatency" %in% colnames(nightsummary))
expect_true("sleepefficiency" %in% colnames(nightsummary))
expect_equal(round(nightsummary$sleepefficiency[1], 3), 0.851)
expect_equal(round(nightsummary$sleepefficiency[1], 3), 0.974)

#--------------------------------------------
# part 4 without sleeplog
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_recordingEndSleepHour.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ test_that("recordingEndSleepHour works as expected", {
expect_equal(sum(p4$guider_inbedStart), 41.42)
expect_equal(sum(p4$guider_inbedEnd), 57.961)
expect_equal(sum(p4$number_sib_sleepperiod), 13)
expect_equal(sum(p4$sleepefficiency), 0.422)
expect_equal(sum(p4$sleepefficiency), 0.428)
expect_equal(sum(p4$longitudinal_axis), 6)

p5 = read.csv("output_test/results/part5_daysummary_MM_L40M100V400_T5A5.csv")
Expand Down

0 comments on commit 87b07ef

Please sign in to comment.