R/get_distribution.R

Defines functions get_distribution

Documented in get_distribution

#' Estimate best-fitting distributions of a vector evaluated by AIC
#' @param x vector containing values
#' @param dist_class Class of gamlss.family specifying value-space of x
#' @return vector of distribution-names decreasing with fit (best fit = first element)
#' @export
get_distribution <- function(x, dist_class){
  library(tidyverse)
  library(gamlss)
  library(gamlss.util)
  assertthat::assert_that(is.numeric(x), msg = "x must be numeric")
  assertthat::assert_that(dist_class %in% c("realline", "realAll", "realplus", "real0to1", "counts", "binom"), msg = "dist_class must be of gamlss.family-type")

  distributions <- suppressWarnings(gamlss::fitDist(y = x, k = 2, type = dist_class, extra = "GA")$fits  %>% names)
  return(distributions)
}
td-berlin/anomalizer documentation built on Feb. 21, 2020, 2:03 a.m.