Site icon R-bloggers

An Overview of the New AIC Functions in the TidyDensity Package

[This article was first published on 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.
< section id="introduction" class="level1">

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.

< section id="new-functions" class="level1">

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.

< section id="usage" class="level2">

Usage

util_negative_binomial_aic()
< section id="arguments" class="level2">

Arguments

< section id="value" class="level2">

Value

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

< section id="details" class="level2">

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.

< section id="examples" class="level2">

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
< section id="new-aic-functions" class="level2">

New AIC Functions

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

< section id="conclusion" class="level1">

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!

To 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.
Exit mobile version