I found a wonderful post describing how to use fitdistrplus
and aggregate
to fit multiple distributions in the same data set (unfortunately I cannot find it now to credit it!). My code works how I want it to, but I would like to add more information into the output, including the AIC of the original distribution and some other fitted distributions to I can easily tell which distribution to use to represent the data.
This is my current code:
aggregate(bias~location,df1,function(X)fitdist(X,distr="norm")$estimate)
Achieving the following output:
I tried doing AIC by itself:
aggregate(bias~location,df1,function(X)fitdist(X,distr="norm")$AIC)
but only got NULL in the output column. How can I add AIC to the output above as well as other distributions (i.e., lognormal and the AIC for that)?
Thank you!
According to the documentation, the AIC list element in the output is called
aic
notAIC
The returned element is
aic
(lower case) notAIC
. So,fitdist(X, distr="norm")$aic
should work.