R/outliers_func.R

Defines functions outliers_func

#' @title Label outliers
#'
#' @param mod_plot_agg Aggregated data set for plotting
#' @param draw_adjusted Logical for drawing OD limits, takes precedence over Poisson for outliers
#' @param limit which limit to use.  Currently 95 or 99.
#' @param multiplier how much to multiply the output by.
#'
#' @keywords internal
#' @noRd
outliers_func <- function(mod_plot_agg, draw_adjusted, limit, multiplier){

  if (limit == 95) {
    if (draw_adjusted==FALSE){
      #cat('1')
       mod_plot_agg$outlier <- ifelse((mod_plot_agg$rr * multiplier) <= mod_plot_agg$UCL95 &
                                        (mod_plot_agg$rr  * multiplier) >= mod_plot_agg$LCL95,
                                  0,
                                  1)
    } else {
      #cat('2')
      mod_plot_agg$outlier <- ifelse((mod_plot_agg$rr * multiplier) <= mod_plot_agg$OD95UCL &
                                       (mod_plot_agg$rr  * multiplier) >= mod_plot_agg$OD95LCL,
                                     0,
                                     1)
    }
  } else {

    if (limit == 99) {

       if (draw_adjusted==FALSE){
      #   cat('3')
        mod_plot_agg$outlier <- ifelse((mod_plot_agg$rr * multiplier) <= mod_plot_agg$UCL99 &
                                         (mod_plot_agg$rr * multiplier) >= mod_plot_agg$LCL99,
                                       0,
                                       1)
      } else {
        # cat('4')
        mod_plot_agg$outlier <- ifelse((mod_plot_agg$rr * multiplier) <= mod_plot_agg$OD99UCL &
                                         (mod_plot_agg$rr * multiplier) >= mod_plot_agg$OD99LCL,
                                       0,
                                       1)
      }
    }
  }
  return(mod_plot_agg)
}

Try the FunnelPlotR package in your browser

Any scripts or data that you put into this service are public.

FunnelPlotR documentation built on June 7, 2023, 6:04 p.m.