topmod | R Documentation |
Create or use an updateable list keeping the best x models it encounters (for advanced users)
topmod( nbmodels, nmaxregressors = NA, bbeta = FALSE, lengthfixedvec = 0, liks = numeric(0), ncounts = numeric(0), modelbinaries = matrix(0, 0, 0), betas = matrix(0, 0, 0), betas2 = matrix(0, 0, 0), fixed_vector = matrix(0, 0, 0) )
nbmodels |
The maximum number of models to be retained by the topmod object |
nmaxregressors |
The maximum number of covariates the models in the topmod object are allowed to have |
bbeta |
if |
lengthfixedvec |
The length of an optional fixed vector adhering to
each model (for instance R-squared, etc). If |
liks |
optional vector of log-likelihoods to initialize topmod object
with (length must be |
ncounts |
optional vector of MCMC frequencies to initialize topmod
object with (same length as |
modelbinaries |
optional matrix whose columns detail model binaries to
initialize topmod object with (same nb columns as |
betas |
optional matrix whose columns are coefficients to initialize
topmod object with (same dimensions as |
betas2 |
optional matrix whose columns are coefficients' second moments
to initialize topmod object with (same dimensions as |
fixed_vector |
optional matrix whose columns are a fixed vector
initialize topmod object with (same |
A 'topmod' object (as created by topmod
) holds three basic vectors:
lik
(for the (log) likelihood of models or similar), bool()
for a hexcode presentation of the model binaries (cf. bin2hex
)
and ncount() for the times the models have been drawn.
All these vectors
are sorted descendantly by lik
, and are of the same length. The
maximum length is limited by the argument nbmodels
.
If tmo
is a topmod object, then a call to tmo$addmodel
(e.g.
tmo$addmodel(mylik=4,vec01=c(T,F,F,T))
updates the object tmo
by a model represented by vec01
(here the one including the first and
fourth regressor) and the marginal (log) likelihood lik
(here: 4).
If this model is already part of tmo
, then its respective
ncount
entry is incremented by one; else it is inserted into a
position according to the ranking of lik
.
In addition, there is the possibility to save (the first moments of)
coefficients of a model (betas
) and their second moments
(betas2
), as well as an arbitrary vector of statistics per model
(fixed_vector
).
is.topmod
returns TRUE
if the argument is of class 'topmod'
a call to topmod
returns a list of class "topmod" with the
following elements:
addmodel(mylik,vec01,vbeta=numeric(0),vbeta2=numeric(0),fixedvec=numeric(0)) |
function
that adjusts the list of models in the 'topmod' object (see Details).
|
lik() |
A numeric vector of the best models (log) likelihoods, in decreasing order |
bool() |
A character vector of hexmode expressions
for the model binaries (cf. |
ncount() |
A numeric vector of MCMC frequencies for the best models
(i.e. how often the respective model was introduced by |
nbmodels |
Returns the argument |
nregs |
Returns
the argument |
bool_binary() |
Returns a matrix
whose columns present the models conforming to |
betas() |
a matrix whose columns are the coefficients conforming to
|
betas2() |
similar to |
fixed_vector() |
The columns of this matrix return the
|
topmod
is rather intended as a building block for programming;
it has no direct application for a user of the BMS package.
the object resulting from bms
includes an element of
class 'topmod'
Check http://bms.zeugner.eu for additional help.
#standard use tm= topmod(2,4,TRUE,0) #should keep a maximum two models tm$addmodel(-2.3,c(1,1,1,1),1:4,5:8) #update with some model tm$addmodel(-2.2,c(0,1,1,1),1:3,5:7) #add another model tm$addmodel(-2.2,c(0,1,1,1),1:3,5:7) #add it again -> adjust ncount tm$addmodel(-2.5,c(1,0,0,1),1:2,5:6) #add another model #read out tm$lik() tm$ncount() tm$bool_binary() tm$betas() is.topmod(tm) #extract a topmod oobject only containing the second best model tm2=tm[2] #advanced: should return the same result as #initialize tm2= topmod(2,4,TRUE,0, liks = c(-2.2,-2.3), ncounts = c(2,1), modelbinaries = cbind(c(0,1,1,1),c(1,1,1,1)), betas = cbind(0:3,1:4), betas2 = cbind(c(0,5:7),5:8)) #update tm$addmodel(-2.5,c(1,0,0,1),1:2,5:6) #add another model #read out tm$lik() tm$ncount() tm$bool_binary() tm$betas()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.