R/look_IC.R

Defines functions look_IC

Documented in look_IC

#' This a function used to look at the IC.
#'
#' @param IC an influence curve evaluated at each observation
#' @return Histogram of the IC characteristics
#'
#' @importFrom dplyr group_by summarise
#' @importFrom tidyr pivot_longer
#' @importFrom ggplot2 ggplot aes geom_histogram geom_vline facet_wrap
#' @importFrom rlang .data
#'
#' @export

look_IC <- function(IC){
  colnames(IC) <- 1:ncol(IC)
  tidy_ic <- tidyr::pivot_longer(
    as.data.frame(IC), cols = colnames(IC),
    names_to = "Column")
  mean_df <- dplyr::summarise(
    dplyr::group_by(tidy_ic, .data$Column), mean = mean(.data$value)
    )

  ggplot2::ggplot(tidy_ic, ggplot2::aes(x = .data$value)) +
    ggplot2::geom_histogram() +
    ggplot2::geom_vline(data = mean_df, ggplot2::aes(xintercept = .data$mean)) +
    ggplot2::facet_wrap(~as.numeric(.data$Column))
}
adam-s-elder/amar documentation built on Feb. 5, 2022, 7:10 a.m.