AIC/BIC Calculator
Compare statistical models using Akaike and Bayesian Information Criteria for model selection
About the AIC/BIC Calculator
The AIC/BIC Calculator is an essential tool for statisticians, data scientists, and researchers tasked with model selection. When building statistical models, adding more variables almost always improves the fit to the training data, but it often leads to overfitting—where the model captures noise rather than signals. This calculator computes two of the most widely used metrics for balancing model fit against model complexity, allowing you to objectively compare non-nested models and choose the one that provides the most efficient representation of your data.
Predictive modeling professionals use the Akaike Information Criterion (AIC) to estimate the relative amount of information lost by a given model. Those focused on identifying the most parsimonious 'true' model often look to the Bayesian Information Criterion (BIC), which applies a steeper penalty for adding parameters as the sample size increases. By inputting the log-likelihood, number of parameters, and sample size, users can quickly identify which model minimizes information loss while avoiding the pitfalls of over-parameterization.
Formula
AIC = 2k - 2ln(L) ; BIC = k*ln(n) - 2ln(L)In these formulas, 'L' represents the maximum likelihood of the model, which measures how well the model explains the data. The variable 'k' signifies the number of estimated parameters (including the intercept and the error variance), and 'n' is the total number of observations in the dataset.
AIC (Akaike Information Criterion) focuses on the trade-off between the goodness of fit and the complexity of the model. BIC (Bayesian Information Criterion) incorporates a larger penalty term that depends on the sample size, making it more conservative in selecting additional parameters as the dataset grows larger.
Worked examples
Example 1: A researcher is testing a simple linear regression model with 3 parameters (intercept, slope, error) and 100 observations, yielding a log-likelihood of -202.0.
k = 3, n = 100, ln(L) = -202.0 AIC = 2(3) - 2(-202.0) = 6 + 404 = 410.0 BIC = 3 * ln(100) - 2(-202.0) = 3 * 4.605 + 404 = 13.815 + 404 = 417.815 (rounded to 417.8)
Result: AIC = 410.0; BIC = 416.7. This model has a relatively low penalty due to the small number of parameters.
Example 2: The same researcher adds 4 more variables to the previous model (total parameters = 7) and the log-likelihood improves to -192.0.
k = 7, n = 100, ln(L) = -192.0 AIC = 2(7) - 2(-192.0) = 14 + 384 = 398.0 BIC = 7 * ln(100) - 2(-192.0) = 7 * 4.605 + 384 = 32.235 + 384 = 416.235 (rounded to 416.2)
Result: AIC = 398.0; BIC = 415.4. While the AIC suggests this model is better than the simple one, the BIC is very similar to the simple model due to the complexity penalty.
Common use cases
- Comparing a linear regression model against a polynomial regression model to see if the extra complexity is justified.
- Selecting the optimal number of lags in a time-series ARMA model.
- Determining whether to include additional interaction terms in a logistic regression for medical research.
- Evaluating different factor structures in structural equation modeling (SEM).
Pitfalls and limitations
- Comparing AIC or BIC values across models with different dependent variables or data subsets is mathematically invalid.
- Using AIC for small sample sizes can lead to overfitting; in such cases, the AICc (corrected AIC) should be used instead.
- Both metrics only provide a relative ranking of models and do not indicate whether the 'best' model actually fits the data well in an absolute sense.
- The number of parameters 'k' must include the error variance term (sigma squared) in most standard regression applications.
Frequently asked questions
Should I use AIC or BIC for model selection?
AIC is generally better for predictive accuracy as it prioritizes models that minimize information loss. BIC is preferred when you believe a 'true' model exists within your candidate set, as it penalizes complexity more harshly to avoid overfitting.
what is a good difference between two AIC values?
While there is no formal p-value for these metrics, a difference of more than 2 is typically considered significant, while a difference greater than 10 suggests very strong evidence that the model with the lower value is superior.
is negative aic value bad?
A negative value is perfectly normal and does not indicate an error. It usually occurs when the log-likelihood is positive, which happens frequently in models with small residual variances or high-density probability distributions.
can I compare AIC values for different datasets?
Yes, you must ensure that all models being compared are fitted on the exact same dataset. If the sample size or observations differ, the log-likelihoods are not comparable and the selection criteria will be invalid.
how to calculate aic from r squared?
Both AIC and BIC are built on the log-likelihood of the model. If you only have R-squared or MSE, you may need to convert those into a likelihood framework based on the assumption of normally distributed residuals.