#' Null distribution generator
#'
#' This function generates a null distribution by scrambling the time values on glucose measurements from a cgms.df object
#' @param df input dataframe
#' @keywords nulldistribution generation
#' @export
#' @examples cgms.df %>% addnulldist()
#'
#by resampling historic_glucose at each unique time and append to input df
addnulldist <- function(df) {
sampledf <- sample(df$historic_glucose,size= length(unique(df$time_past_start)), replace = T)
rdf <- df %>% dplyr::distinct(time_past_start,.keep_all = T)
rdf$historic_glucose <- sampledf
rdf <- rdf %>%
dplyr::mutate_at(c("subjno","subj_id","run_id","Group","Subject","id","Age","Gender","Phase","visit"),
function(x){
return("nulldist")
}
)
rdf <- rbind(df,rdf)
return(rdf)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.