R/Pointwise_Analysis.R

Defines functions pointwise_analysis

#' Do the analysis by the Connect-the-dots version of AUC.
#' 
#' @params data A data frame with columns t and y
#' @params by a quoted column column name to denote groups to average the AUC over.
#' @examples
#' data <- expand.grid( t=1:10, Subject_ID = 1:10 ) %>% mutate( y = rnorm(n()))
#' pointwise_analysis(data) 
#' @export 
#' library(dplyr)
pointwise_analysis <- function(data, by='Subject_ID'){
  out <- data %>%
    group_by_( by ) %>%
    do( data.frame( AUC = pointwise.integrate(.$t, .$y)$value ) ) %>%
    group_by() %>%
    summarize(AUC = mean(AUC))
  return(out)
}
KodyGelvin/STA485_2018 documentation built on May 17, 2019, 10:11 p.m.