# An Overview of the New AIC Functions in the TidyDensity Package

**Steve's Data Tips and Tricks**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

# Introduction

The latest update the the `TidyDensity`

package introduces several new functions that make it easier to work with data in R. In this article, we’ll take a look at the new AIC functions and how they work.

# New Functions

The set of functions that we will go over are the `util_dist_aic()`

functions, where `dist`

is the distribution in question, for example `util_negative_binomial_aic()`

. These functions calculate the Akaike Information Criterion (AIC) for a given distribution and data. The AIC is a measure of the relative quality of a statistical model for a given set of data. The lower the AIC value, the better the model fits the data. Here is a bit about the functions.

## Usage

util_negative_binomial_aic()

## Arguments

`.x`

: A numeric vector of data values.

## Value

A numeric value representing the AIC for the given data and distribution.

## Details

This function calculates the Akaike Information Criterion (AIC) for a distribution fitted to the provided data.

This function fits a distribution to the provided data. It estimates the parameters of the distribution from the data. Then, it calculates the AIC value based on the fitted distribution.

Initial parameter estimates: The function uses the param estimate family of functions in order to estimate the starting point of the parameters. For example `util_negative_binomial_param_estimate()`

.

Optimization method: Since the parameters are directly calculated from the data, no optimization is needed.

Goodness-of-fit: While AIC is a useful metric for model comparison, it’s recommended to also assess the goodness-of-fit of the chosen model using visualization and other statistical tests.

## Examples

library(TidyDensity) set.seed(123) # Generate some data x <- rnorm(100) # Calculate the AIC for a negative binomial distribution cat( " AIC of rnorm() using TidyDensity: ", util_normal_aic(x), "\n", "AIC of rnorm() using fitdistrplus: ", fitdistrplus::fitdist(x, "norm")$aic )

AIC of rnorm() using TidyDensity: 268.5385 AIC of rnorm() using fitdistrplus: 268.5385

## New AIC Functions

Here is a listing of all of the new AIC functions:

`util_negative_binomial_aic()`

`util_zero_truncated_negative_binomial_aic()`

`util_zero_truncated_poisson_aic()`

`util_f_aic()`

`util_zero_truncated_geometric_aic()`

`util_t_aic()`

`util_pareto1_aic()`

`util_paralogistic_aic()`

`util_inverse_weibull_aic()`

`util_pareto_aic()`

`util_inverse_burr_aic()`

`util_generalized_pareto_aic()`

`util_generalized_beta_aic()`

`util_zero_truncated_binomial_aic()`

# Conclusion

Thanks for reading. I hope you find these new functions useful in your work. If you have any questions or feedback, please feel free to reach out. I worked hard to ensure where I could that results would come back identical to what would be calculated from the amazing `fitdistrplus`

package.

Happy Coding!

**leave a comment**for the author, please follow the link and comment on their blog:

**Steve's Data Tips and Tricks**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.