-
Notifications
You must be signed in to change notification settings - Fork 29
Updated MAG computation in the presence of large missing data #186
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| #' | ||
|
|
@@ -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 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| } | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add yourself as author
There was a problem hiding this comment.
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