Skip to content

Commit

Permalink
Merge pull request #164 from neokok/master
Browse files Browse the repository at this point in the history
GRI Bug Fix plus additional testing
  • Loading branch information
irinagain authored Sep 24, 2024
2 parents 0fd34c9 + b61758b commit fb85882
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: iglu
Type: Package
Title: Interpreting Glucose Data from Continuous Glucose Monitors
Version: 4.1.7
Version: 4.2.0
Authors@R: c(person("Elizabeth", "Chun",
role = c("aut")),
person("Steve", "Broll",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# iglu 4.2.0
* Fixed bug in GRI calculation

# iglu 4.1.7
* added tz parameter to functions that require it

Expand Down
4 changes: 2 additions & 2 deletions R/gri.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ gri <- function(data, tz = ""){
range_percents <- agp_metrics(data)
range_percents <- range_percents[c("below_54", "below_70", "above_180", "above_250")]

out = 3*range_percents$below_54 + 2.4*range_percents$below_70 +
1.6*range_percents$above_250 + 0.8*range_percents$above_180
out = 3*range_percents$below_54 + 2.4*(range_percents$below_70 - range_percents$below_54) +
1.6*range_percents$above_250 + 0.8*(range_percents$above_180 - range_percents$above_250)

# threshold at 100%
out = ifelse(out > 100, 100, out)
Expand Down
33 changes: 33 additions & 0 deletions tests/testthat/test-hbgi.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Test on one subject data
test1 = iglu::example_data_1_subject
test2 = iglu::example_data_1_subject[1:300, ]
test3 = iglu::example_data_5_subject

out = iglu::hbgi(iglu::example_data_5_subject)$HBGI


fg = c()
for(g in test1$gl){fg = c(fg, max(0, 1.509 * ((log(g)^1.084) - 5.381)))}
first_test = (1/length(test1$gl)) * sum(10 * fg^2)

fg = c()
for(g in test2$gl){fg = c(fg, max(0, 1.509 * ((log(g)^1.084) - 5.381)))}
second_test = (1/length(test2$gl)) * sum(10 * fg^2)

five_tests = c()

for(sub in unique(test3$id)){
fg = c()
for(g in test3[test3$id == sub,]$gl){fg = c(fg, max(0, 1.509 * ((log(g)^1.084) - 5.381)))}
five_tests = c(five_tests, ((1/length(test3[test3$id == sub,]$gl)) * sum(10 * fg^2)))
}

testthat::test_that("hbgi works", {
testthat::expect_equal(iglu::hbgi(test1)$HBGI[1], first_test, tolerance = 0.0001)
testthat::expect_equal(iglu::hbgi(test2)$HBGI[1], second_test, tolerance = 0.0001)
testthat::expect_equal(out[1], five_tests[1], tolerance = 0.0001)
testthat::expect_equal(out[2], five_tests[2], tolerance = 0.0001)
testthat::expect_equal(out[3], five_tests[3], tolerance = 0.0001)
testthat::expect_equal(out[4], five_tests[4], tolerance = 0.0001)
testthat::expect_equal(out[5], five_tests[5], tolerance = 0.0001)
})

0 comments on commit fb85882

Please sign in to comment.