Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/weights-stacking.R

Computes model weights based on a cross-validation-like procedure.

1 | ```
stackingWeights(object, ..., data, R, p = 0.5)
``` |

`object, ...` |
two or more fitted |

`data` |
a data frame containing the variables in the model, used for fitting and prediction. |

`R` |
the number of replicates. |

`p` |
the proportion of the |

Each model in a set is fitted to the training data: a subset of `p * N`

observations in `data`

. From these models a prediction is produced on
the remaining part of `data`

(the test
or hold-out data). These hold-out predictions are fitted to the hold-out
observations, by optimising the weights by which the models are combined. This
process is repeated `R`

times, yielding a distribution of weights for each
model (which Smyth & Wolpert (1998) referred to as an ‘empirical Bayesian
estimate of posterior model probability’). A mean or median of model weights for
each model is taken and re-scaled to sum to one.

`stackingWeights`

returns a matrix with two rows, holding model weights
calculated using `mean`

and `median`

.

This approach requires a sample size of at least *2x* the number
of models.

Carsten Dormann, Kamil Bartoń

Wolpert, D. H. (1992) Stacked generalization. *Neural Networks*, 5: 241-259.

Smyth, P. & Wolpert, D. (1998) *An Evaluation of Linearly Combining
Density Estimators via Stacking. Technical Report No. 98-25.* Information
and Computer Science Department, University of California, Irvine, CA.

Other model.weights: `BGWeights`

,
`bootWeights`

, `cos2Weights`

,
`jackknifeWeights`

1 2 3 4 5 6 7 8 9 10 11 | ```
# global model fitted to training data:
fm <- glm(y ~ X1 + X2 + X3 + X4, data = Cement, na.action = na.fail)
# generate a list of *some* subsets of the global model
models <- lapply(dredge(fm, evaluate = FALSE, fixed = "X1", m.lim = c(1, 3)), eval)
wts <- stackingWeights(models, data = Cement, R = 10)
ma <- model.avg(models)
Weights(ma) <- wts["mean", ]
predict(ma)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.