BayesMfp {bfp} | R Documentation |
Bayesian model inference for multiple fractional polynomial models
Description
Bayesian model inference for multiple fractional polynomial models is conducted by means of either exhaustive model space evaluation or posterior model sampling.
Usage
BayesMfp(formula = formula(data), data = parent.frame(), family =
gaussian, priorSpecs = list(a = 4, modelPrior = "flat"), method =
c("ask", "exhaustive", "sampling"), subset = NULL, na.action = na.omit,
verbose = TRUE, nModels = NULL, nCache=1e9L, chainlength = 1e5L)
bfp(x, max = 2, scale = TRUE, rangeVals=NULL)
uc(x)
Arguments
formula |
model formula |
data |
optional data.frame for model variables (defaults to the parent frame) |
family |
distribution and link: only gaussian("identity") supported at the moment |
priorSpecs |
prior specifications, see details |
method |
which method should be used to explore the posterior model space? (default: ask the user) |
subset |
optional subset expression |
na.action |
default is to skip rows with missing data, and no other option supported at the moment |
verbose |
should information on computation progress be given? (default) |
nModels |
how many best models should be saved? (default: 1% of the explored models or the chainlength, 1 would mean only the maximum a posteriori [MAP] model) |
nCache |
maximum number of best models to be cached at the same time during the model sampling (only has an effect if sampling has been chosen as method) |
chainlength |
length of the model sampling chain (only has an effect if sampling has been chosen as method) |
x |
variable |
max |
maximum degree for this FP (default: 2) |
scale |
use pre-transformation scaling to avoid numerical problems? (default) |
rangeVals |
extra numbers if the scaling should consider values in this range. Use this argument if you have test data with larger range than the training range. |
Details
The formula is of the form
y ~ bfp (x1, max = 4) + uc (x2 + x3)
, that is, the
auxiliary functions bfp
and uc
must be
used for defining the fractional polynomial and uncertain fixed form
covariates terms, respectively. There must be an intercept, and no
other fixed covariates are allowed. All max
arguments of the
bfp
terms must be identical.
The prior specifications are a list:
- a
hyperparameter for hyper-g prior which must be greater than 3 and is recommended to be not greater than 4 (default is 4)
- modelPrior
choose if a flat model prior (default,
"flat"
), a model prior favoring sparse models explicitly ("sparse"
), or a dependent model prior ("dependent"
) should be used.
If method = "ask"
, the user is prompted with the maximum
cardinality of the model space and can then decide whether to use
posterior sampling or the exhaustive model space evaluation.
Note that if you specify only one FP term, the exhaustive model search must be done, due to the structure of the model sampling algorithm. However, in reality this will not be a problem as the model space will typically be very small.
Value
Returns an object of class BayesMfp
that inherits from list. It
is essentially a list of models. Each model is a list and has the
following components:
powers |
a list of numeric vectors, where each vector contains the powers of the covariate that its name denotes. |
ucTerms |
an integer vector of the indices of uncertain fixed form covariates that are present in the model. |
logM |
log marginal likelihood |
logP |
log prior probability |
posterior |
normalized posterior probability, and if model sampling was done, the frequency of the model in the sampling algorithm |
postExpectedg |
posterior expected covariance factor g |
postExpectedShrinkage |
posterior expected shrinkage factor t=g/(g + 1) |
R2 |
usual coefficient of determination for the linear model |
Subsetting the object
with [.BayesMfp
returns again a BayesMfp
object
with the same attributes, which are
numVisited |
the number of models that have been visited (exhaustive search) or cached (model sampling) |
inclusionProbs |
BMA inclusion probabilities for all uncertain covariates |
linearInclusionProbs |
BMA probabilities for exactly linear inclusion of FP covariates |
logNormConst |
the (estimated) log normalizing constant |
chainlength |
length of the Markov chain, only present if |
call |
the original call |
formula |
the formula by which the appropriate untransformed design matrix can be extracted |
x |
the shifted and scaled design matrix for the data |
xCentered |
the column-wise centered x |
y |
the response vector |
yMean |
the mean of the response values |
SST |
sum of squares total |
indices |
a list with components that describe the positions of uncertain covariate groups, fractional polynomial terms and fixed variables in the design matrix |
termNames |
a list of character vectors containing the names of uncertain covariate groups, fractional polynomial terms and fixed variables |
shiftScaleMax |
matrix with 4 columns containing preliminary transformation parameters, maximum degrees and cardinalities of the powersets of the fractional polynomial terms |
priorSpecs |
the utilized prior specifications |
randomSeed |
if a seed existed at function call
( |
Note
logNormConst
may be unusable due to necessary conversion
from long double to double!
Various methods for posterior summaries are available.
See Also
Examples
## generate some data
set.seed(19)
x1 <- rnorm(n=15)
x2 <- rbinom(n=15, size=20, prob=0.5)
x3 <- rexp(n=15)
y <- rt(n=15, df=2)
## run an exhaustive model space evaluation with a flat model prior and
## a uniform prior (a = 4) on the shrinkage factor t = g/(1 + g):
test <- BayesMfp(y ~ bfp (x2, max = 4) + uc (x1 + x3), nModels = 100,
method="exhaustive")
test
## now the same with a *dependent* model prior:
test2 <- BayesMfp(y ~ bfp (x2, max = 4) + uc (x1 + x3), nModels = 100,
priorSpecs = list(a = 4, modelPrior = "dependent"),
method="exhaustive")
test2