Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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.2.3
Version: 4.3.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.3.0
* Updated MAG computation in the presence of large missing data

# iglu 4.2.3
* Fixed GVP output for iglu::all_metrics

Expand Down
13 changes: 6 additions & 7 deletions R/mag.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
#' The glucose values are linearly interpolated over a time grid starting at the
#' beginning of the first day of data and ending on the last day of data. Then, MAG
#' is calculated as \eqn{\frac{|\Delta G|}{\Delta t}} where \eqn{|\Delta G|} is
#' the sum of the absolute change in glucose calculated for each interval as specified
#' by n, default n = 60 for hourly change in glucose. The sum is then divided by
#' \eqn{\Delta t} which is the total time in hours.
#' the sum of the absolute change in glucose. The sum is then divided by \eqn{\Delta t},
#' the total number of n-minute intervals (default n = 60 for hourly change).
#'
#' @author Elizabeth Chun
Copy link
Owner

Choose a reason for hiding this comment

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

Add yourself as author

Copy link
Owner

Choose a reason for hiding this comment

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

Also double-check that we indeed agreed that n=60 is the right default

#'
Expand Down Expand Up @@ -54,10 +53,10 @@ mag <- function (data, n = 60L, dt0 = NULL, inter_gap = 45, tz = "") {
n <- dt0
}

idx = seq(1, ncol(data_ip[[1]]), by = round(n/data_ip[[3]]))
idx_gl = as.vector(t(data_ip[[1]][, idx]))
mag = sum(abs(diff(idx_gl)), na.rm = TRUE)/
(length(na.omit(idx_gl))*n/60)
diffs = diff(as.vector(t(data_ip[[1]])))
total_time = (length(na.omit(diffs))*dt0)/n
Copy link
Owner

Choose a reason for hiding this comment

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

if total_time is in hours, then n should always be 60. if n is less than 60, then I am not sure the logic is appropriate. The original code was specifically taking differences over an interval controlled by n. THe new code will always take consecutive differences so this control is eliminated. Better to stick to the original code, but modify for NA

mag = sum(abs(diffs), na.rm = TRUE)/total_time

return(mag)
}

Expand Down
5 changes: 2 additions & 3 deletions man/mag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading