Learn R Programming

EMC2 (version 3.1.1)

model_averaging: Model Averaging

Description

Computes model weights and a Bayes factor by comparing two groups of models based on their Information Criterion (IC) values. The function works with either numeric vectors or data frames containing multiple IC measures (e.g., MD, BPIC, DIC).

Usage

model_averaging(IC_for, IC_against)

Value

A data.frame with the following columns:

wFor

The aggregated weight of the models in favor.

wAgainst

The aggregated weight of the models against.

Factor

The Bayes factor (ratio of wFor to wAgainst).

If IC_for is a data frame, a matrix with rows corresponding to each IC measure is returned.

Arguments

IC_for

A numeric vector or the output of compare

IC_against

A numeric vector or the output of compare

Details

When provided with numeric vectors, it computes the weights for the two groups by first converting the IC values into relative weights and then normalizing them. When provided with a data frame, it assumes that the data frame is the output of a call to compare and applies averaging to each IC metric

Examples

Run this code
# First set up some example models (normally these would be alternative models)
samples_LNR2 <- subset(samples_LNR, length.out = 45)
samples_LNR3 <- subset(samples_LNR, length.out = 40)
samples_LNR4 <- subset(samples_LNR, length.out = 35)

# Run compare on them, BayesFactor = F is set for speed.
ICs <- compare(list(S1 = samples_LNR, S2 = samples_LNR2,
                    S3 = samples_LNR3, S4 = samples_LNR4), BayesFactor = FALSE)

# Model averaging can either be done with a vector of ICs:
model_averaging(ICs$BPIC[1:2], ICs$BPIC[2:4])

# Or the output of compare:
model_averaging(ICs[1:2,], ICs[3:4,])

Run the code above in your browser using DataLab