icWeights: Relative Weights for Information Criterion Values

Description Usage Arguments Details Value Examples

View source: R/utility_functions.R

Description

Computes the relative probability of being the 'best' model for a set of candidate models based on their AIC or BIC values.

Usage

1

Arguments

ic

a vector of information criterion values, either a set of AIC or BIC values.

Details

A set of information criterion values (i.e., AIC or BIC) can be transformed into a set of relative probabilities, the probability that a given model is the 'best'. In the case of the AIC, probabilities represent how likeliy a given model will minimize information loss based on the data and set of candidate models. In the case of the BIC, probabilities represent how likely a given model is the true (generating) model out of the set of candidate models (assuming the true model is in the set).

Value

A vector of probabilities.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Model comparison with polynomial regression
x = rnorm(100) # Simulate predictor
df = data.frame( x1 = x, x2 = x^2, x3 = x^3, x4 = x^4 )
# True model is quadratic
df$y = .5 * df$x1 - .7 * df$x2 + rnorm(100,0,.75)
# Fit 4 models
m1 = lm( y ~ x1, data = df )
m2 = lm( y ~ x1 + x2, data = df ) # True
m3 = lm( y ~ x1 + x2 + x3, data = df )
m4 = lm( y ~ x1 + x2 + x3 + x4, data = df )
# Compute AIC
aic = c( AIC( m1 ), AIC( m2 ), AIC( m3 ), AIC( m4 ) )
names( aic ) = c( 'M1', 'M2', 'M3', 'M4' )
# AIC weights
print( round( icWeights( aic ), 2 ) )
# Compute BIC
bic = c( BIC( m1 ), BIC( m2 ), BIC( m3 ), BIC( m4 ) )
names( bic ) = c( 'M1', 'M2', 'M3', 'M4' )
# BIC weights
print( round( icWeights( bic ), 2 ) )

# xa = seq( min(x), max(x), length = 100 )
# nd = data.frame( x1 = xa, x2 = xa^2, x3 = xa^3, x4 = xa^4, y = NA )
# plot( df$x1, df$y, pch = 19, xlab = 'x', ylab = 'y' )
# lines( xa, predict( m1, newdata = nd ), col = 'blue' )
# lines( xa, predict( m2, newdata = nd ), col = 'red' )
# lines( xa, predict( m3, newdata = nd ), col = 'green' )
# lines( xa, predict( m4, newdata = nd ), col = 'orange' )

rettopnivek/utilityf documentation built on March 1, 2021, 7:05 p.m.