How to Calculate Bayesian Information Criterion (BIC) in R

Spread the love

Statistical model selection is a critical step in data analysis, ensuring that the model best represents the data without unnecessary complexity. Several criteria help in this task, and one of the most notable is the Bayesian Information Criterion (BIC). BIC provides a balance between the goodness of fit and the number of parameters used, making it invaluable in model comparison.

This article will walk you through the concept, the underlying mathematics, and the process of calculating BIC in R.


  1. Introduction to BIC
  2. The Mathematical Formula
  3. BIC vs. AIC
  4. Calculating BIC in R
  5. Using BIC for Model Selection
  6. Benefits and Limitations
  7. Conclusion

1. Introduction to BIC:

The Bayesian Information Criterion, often abbreviated as BIC, is a criterion for model selection among a set of models. It is rooted in the framework of Bayesian probability. BIC balances model fit and complexity, penalizing models that use more parameters and thus risk overfitting.

The central idea behind BIC is to introduce a penalty term for the complexity of the model. This ensures that models that perform slightly better but at the expense of many additional parameters aren’t necessarily chosen.

2. The Mathematical Formula:

The BIC is mathematically formulated as:


  • The log-likelihood evaluates how well the model fits the data.
  • k is the number of parameters in the model.
  • n is the number of observations.

As you can see, as the number of parameters increases, the BIC will increase, thus “penalizing” more complex models.

3. BIC vs. AIC:

Another commonly used criterion for model selection is the Akaike Information Criterion (AIC). While both BIC and AIC introduce a penalty for the number of parameters, they do so differently. BIC’s penalty term is generally larger, especially as the sample size grows. This often results in BIC favoring simpler models compared to AIC.

4. Calculating BIC in R:

R offers a straightforward way to calculate BIC, especially when using functions like lm() for linear regression. Here’s a step-by-step guide:

# Sample data
x <- rnorm(100)
y <- 1.5 * x + rnorm(100)

# Fit a linear regression model
model <- lm(y ~ x)

# Calculate BIC
bic_value <- BIC(model)

5. Using BIC for Model Selection:

  1. Fit Multiple Models: Begin by fitting all the candidate models to the data.
  2. Calculate BIC for Each Model: Using the approach outlined above, determine the BIC for each model.
  3. Compare BIC Values: Lower BIC values indicate better models. Select the model with the lowest BIC value.
  4. Re-evaluate as Necessary: If you introduce new data or consider additional models, re-calculate and compare BIC values.

6. Benefits and Limitations:


  • Provides a clear criterion for model comparison.
  • Balances fit and complexity, helping to avoid overfitting.
  • Rooted in Bayesian probability, giving it a solid theoretical foundation.


  • Doesn’t always agree with other criteria, like AIC. In such cases, domain knowledge and other validation techniques become crucial.
  • Assumes that the true model (from which data was generated) is not among the set of models being considered. This might not always hold.
  • Might be overly conservative and prefer overly simple models, especially in large datasets.

7. Conclusion:

The Bayesian Information Criterion is a powerful tool in the statistician’s and data analyst’s toolkit, helping in the essential task of model selection. By introducing a penalty for model complexity, BIC ensures that models are chosen based on both their fit and parsimony. R, being a language tailored for statistical computing, offers easy ways to calculate and compare BIC values across models. As with all statistical techniques, understanding the underlying assumptions and the context in which you’re working is vital for the appropriate application of BIC.

Posted in RTagged

Leave a Reply