#' 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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.