Title: | Model averaging |
---|---|
Description: | This package implementes model averaging. |
Authors: | Sangeeta Bhatia [aut, cre], Anne Cori [aut], Pierre Nouvellet [aut] |
Maintainer: | Sangeeta Bhatia <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.1 |
Built: | 2024-11-20 02:48:19 UTC |
Source: | https://github.com/mrc-ide/weighter |
Mapping of groupvar to models run
groupvar_to_model(pred, groupvars)
groupvar_to_model(pred, groupvars)
pred |
data.frame with at least one column called model |
groupvars |
quoted variable names used to define groups within which models should be ranked. |
In some cases, we might not have the same set of models run for
a grouping variable. For example, say the grouping variable is
country, and we have Models ,
and
run for country
, and models
run
for country
. For this example,
groupvar_to_model
returns
a named list where names are formed by concatenating models
and elements are countries for which a particular set of models has been run.
(m1_m2_m3 = c1, m1_m2_m3_m4 = c2)
list
Sangeeta Bhatia
Rank models according to the error
model_ranks(pred, groupvars, errvar)
model_ranks(pred, groupvars, errvar)
pred |
data.frame with at least one column called model |
groupvars |
quoted variable names used to define groups within which models should be ranked. |
errvar |
quoted column name that contains the metric used to rank models |
When multiple models have made predictions, we want to rank them
by their error, where error can be any metric e.g. Root mean
squared error or likelihood. Each model is ranked within the
groups defined by groupvars
data.frame with the same structure as pred
and an
extra column called rank which contains the model ranks within
the groups defined by groupvar
Sangeeta Bhatia
pred <- data.frame( models = as.factor(c("a", "b", "c", "a", "b", "c")), country = c("C1", "C1", "C1", "C2", "C2", "C2"), error = c(6L, 1L, 3L, 4L, 7L, 9L), date = c("1", "1", "1", "2", "2", "2"), stringsAsFactors = FALSE ) model_ranks(pred, c("country", "date"), "error")
pred <- data.frame( models = as.factor(c("a", "b", "c", "a", "b", "c")), country = c("C1", "C1", "C1", "C2", "C2", "C2"), error = c(6L, 1L, 3L, 4L, 7L, 9L), date = c("1", "1", "1", "2", "2", "2"), stringsAsFactors = FALSE ) model_ranks(pred, c("country", "date"), "error")
Mapping of models to groups for which they have been run
model_to_groupvar(pred, groupvars)
model_to_groupvar(pred, groupvars)
pred |
data.frame with at least one column called model |
groupvars |
quoted variable names used to define groups within which models should be ranked. |
In some cases, we might not have the same set of models run for
a grouping variable. For example, say the grouping variable is
country, and we have Models ,
and
run for country
, and models
run
country
. For this example, this function will return the
list
m_1 = c_1, c_2, m_2 = c_1, c_1, m_3 = c_1, c_2, m_4 = c_2
This can be used to identify for which countries a give model has
been run.
list
Sangeeta Bhatia
Compute Model Weights
model_weights(pred, groupvars, errvar)
model_weights(pred, groupvars, errvar)
pred |
data.frame with at least one column called model |
groupvars |
quoted variable names used to define groups within which models should be ranked. |
errvar |
quoted column name that contains the metric used to rank models |
Compute model weights within each group
named list where the names are the combinations of
models run for a group, and each element of the list is a
data.frame containing model weights outputted from
model_weights_in_group
Sangeeta Bhatia
model_weights_in_group
Compute model weights from model ranks
model_weights_in_group(pred, groupvars = "model", rankvar = "rank")
model_weights_in_group(pred, groupvars = "model", rankvar = "rank")
pred |
data.frame that has at least columns specified via
parameters |
groupvars |
quoted variable names used to define groups within which model weights are computed. Defaults to model. |
rankvar |
quoted variable names that contain model ranks. |
In a group defined by groupvars
, the weight of a model is
defined as
where is the number of times model M is ranked
among
models.
a data.frame with columns model and weight where weight is the unnormalised weight of the model
Sangeeta Bhatia
model_ranks
model_weights
pred <- data.frame( model = as.factor(c("a", "b", "c", "a", "b", "c")), country = c("C1", "C1", "C1", "C2", "C2", "C2"), error = c(6L, 1L, 3L, 4L, 7L, 9L), date = c("1", "1", "1", "2", "2", "2"), stringsAsFactors = FALSE ) ranked <- model_ranks(pred, c("country", "date"), "error") model_weights_in_group(ranked)
pred <- data.frame( model = as.factor(c("a", "b", "c", "a", "b", "c")), country = c("C1", "C1", "C1", "C2", "C2", "C2"), error = c(6L, 1L, 3L, 4L, 7L, 9L), date = c("1", "1", "1", "2", "2", "2"), stringsAsFactors = FALSE ) ranked <- model_ranks(pred, c("country", "date"), "error") model_weights_in_group(ranked)