Bayesian model inference for multiple fractional polynomial models is conducted by means of either exhaustive model space evaluation or posterior model sampling.
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)
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:
a list of numeric vectors, where each vector contains the powers of the covariate that its name denotes.
an integer vector of the indices of uncertain fixed form covariates that are present in the model.
log marginal likelihood
log prior probability
normalized posterior probability, and if model sampling was done, the frequency of the model in the sampling algorithm
posterior expected covariance factor g
posterior expected shrinkage factor t=g/(g + 1)
usual coefficient of determination for the linear model
Subsetting the object
with [.BayesMfp
returns again a BayesMfp
object
with the same attributes, which are
the number of models that have been visited (exhaustive search) or cached (model sampling)
BMA inclusion probabilities for all uncertain covariates
BMA probabilities for exactly linear inclusion of FP covariates
the (estimated) log normalizing constant \(f (D)\)
length of the Markov chain, only present if method = "sampling"
the original call
the formula by which the appropriate untransformed design matrix can be extracted
the shifted and scaled design matrix for the data
the column-wise centered x
the response vector
the mean of the response values
sum of squares total
a list with components that describe the positions of uncertain covariate groups, fractional polynomial terms and fixed variables in the design matrix
a list of character vectors containing the names of uncertain covariate groups, fractional polynomial terms and fixed variables
matrix with 4 columns containing preliminary transformation parameters, maximum degrees and cardinalities of the powersets of the fractional polynomial terms
the utilized prior specifications
if a seed existed at function call
(get(".Random.seed", .GlobalEnv)
), it is saved here
model formula
optional data.frame for model variables (defaults to the parent frame)
distribution and link: only gaussian("identity") supported at the moment
prior specifications, see details
which method should be used to explore the posterior model space? (default: ask the user)
optional subset expression
default is to skip rows with missing data, and no other option supported at the moment
should information on computation progress be given? (default)
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)
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)
length of the model sampling chain (only has an effect if sampling has been chosen as method)
variable
maximum degree for this FP (default: 2)
use pre-transformation scaling to avoid numerical problems? (default)
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.
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:
hyperparameter for hyper-g prior which must be greater than 3 and is recommended to be not greater than 4 (default is 4)
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.
BayesMfp Methods, BmaSamples
## 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
Run the code above in your browser using DataLab