weighted_model: Create a Weighted Consensus Model

View source: R/model_fit.R

weighted_modelR Documentation

Create a Weighted Consensus Model

Description

Constructs a weighted consensus model formed as a weighted average of a set of models. The consensus model combines the input models according to their respective weights.

Usage

weighted_model(
  fits,
  names = 1:length(fits),
  weights = rep(1/length(fits), length(fits))
)

Arguments

fits

A list of model fits to be combined.

names

An optional list of names, one per model fit (default: numeric indices).

weights

A vector of weights, one per model fit, that sum up to 1 (default: equal weights for all models).

Value

An object of class weighted_model, containing the list of model fits, their names, and the assigned weights. The object is also assigned a class 'list'.

Examples

# Create two sample model fits
fit1 <- list(model = "model1", y = c(0, 1), fit = "fit1")
fit2 <- list(model = "model2", y = c(1, 0), fit = "fit2")

# Combine the model fits into a weighted consensus model
w_model <- weighted_model(fits = list(fit1, fit2), names = c("model1", "model2"), weights = c(0.6, 0.4))


bbuchsbaum/rMVPA documentation built on April 28, 2024, 6:30 a.m.