This function is intended to be used on the right hand side of the formula
argument to
create_sampler
or generate_data
.
gen(
formula = ~1,
factor = NULL,
remove.redundant = FALSE,
drop.empty.levels = FALSE,
X = NULL,
var = NULL,
prior = NULL,
Q0 = NULL,
PX = TRUE,
GMRFmats = NULL,
priorA = NULL,
Leroux = FALSE,
R0 = NULL,
RA = NULL,
constr = NULL,
S0 = NULL,
SA = NULL,
formula.gl = NULL,
name = "",
sparse = NULL,
perm = NULL,
debug = FALSE,
e = parent.frame()
)
a model formula specifying the effects that vary over the levels of
the factor variable(s) specified by argument factor
. Defaults to ~1
,
corresponding to random intercepts. If X
is specified formula
is ignored.
Variable names are looked up in the data frame passed as data
argument to
create_sampler
or generate_data
, or in environment(formula)
.
a formula with factors by which the effects specified in the formula
argument vary. Often only one such factor is needed but multiple factors are allowed so that
interaction terms can be modeled conveniently. The formula must take the form
~ f1(fac1, ...) * f2(fac2, ...) ...
, where
fac1, fac2
are factor variables and f1, f2
determine the
correlation structure assumed between levels of each factor, and the ...
indicate
that for some correlation types further arguments can be passed. Correlation structures
currently supported include iid
for independent identically distributed effects,
RW1
and RW2
for random walks of first or second order over the factor levels,
AR1
for first-order autoregressive effects, season
for seasonal effects,
spatial
for spatial (CAR) effects and custom
for supplying a custom
precision matrix corresponding to the levels of the factor. For further details about
the correlation structures, and further arguments that can be passed, see
correlation
. Argument factor
is ignored if X
is specified.
The factor variables are looked up in the data frame passed as data
argument to
create_sampler
or generate_data
, or in environment(formula)
.
whether redundant columns should be removed from the model matrix
associated with formula
. Default is FALSE
.
whether to remove factor levels without observations.
A (possibly sparse) design matrix. This can be used instead of formula
and factor
.
the (co)variance structure among the varying effects defined by formula
over the levels of the factors defined by factor
.
The default is "unstructured"
, meaning that a full covariance matrix
parameterization is used. For uncorrelated effects with different variances use
var="diagonal"
. For uncorrelated and equal variances use var="scalar"
.
In the case of a single varying effect there is no difference between these choices.
the prior specification for the variance parameters of the random effects.
These can currently be specified by a call to pr_invwishart
in case
var="unstructured"
or by a call to pr_invchisq
otherwise.
See the documentation of those prior specification functions for more details.
precision matrix associated with formula
. This can only be used in
combination with var="scalar"
.
whether parameter expansion should be used. Default is TRUE
, which
applies parameter expansion with default options. Alternative options can be specified
by supplying a list with one or more of the following components:
whether a redundant multiplicative expansion parameter is used for each varying effect
specified by formula
. The default is TRUE
except when var="scalar"
.
If FALSE
a single redundant multiplicative parameter is used.
whether the data level scale is used as a variance factor for the expansion
parameters. Default is TRUE
.
location (vector) parameter for parameter expansion. By default 0
.
precision (matrix) parameter for parameter expansion. Default is the identity matrix.
list of incidence/precision/constraint matrices. This can be specified
as an alternative to factor
. It should be a list such as is usually returned
by compute_GMRF_matrices
. Can be used together with argument X
as a flexible alternative to formula
and factor
.
prior distribution for scale factors at the variance scale associated with QA
.
In case of IGMRF models the scale factors correspond to the innovations.
The default NULL
means not to use any local scale factors.
A prior can currently be specified using pr_invchisq
or pr_exp
.
this option alters the precision matrix determined by factor
by taking a
weighted average of it with the identity matrix. If TRUE
the model gains an additional parameter,
the 'Leroux' parameter, being the weight of the original, structured, precision matrix in the weighted
average. By default a uniform prior for the weight and a uniform Metropolis-Hastings proposal density
are employed. This default can be changed by supplying a list with elements a, b, and a.star, b.star,
implying a beta(a, b) prior and a beta(a.star, b.star) independence proposal density. A third option is
to supply a single number between 0 and 1, which is then used as a fixed value for the Leroux parameter.
an optional equality restriction matrix acting on the coefficients defined by formula
, for each
level defined by factor
. If c is the number of restrictions, R0
is a
q0 x c matrix where q0 is the number of columns of the design matrix derived
from formula
. Together with RA
it defines the set of equality constraints
to be imposed on the vector of coefficients. Only allowed in combination with var="scalar"
.
an optional equality restriction matrix acting on the coefficients defined by factor
,
for each effect defined by formula
. If c is the number of restrictions, RA
is a
l x c matrix where l is the number of levels defined by factor
.
Together with R0
this defines the set of equality constraints to be imposed on the vector
of coefficients.
If constr=TRUE
, additional constraints are imposed, corresponding to the
null-vectors of the singular precision matrix in case of an intrinsic Gaussian Markov Random Field.
whether constraints corresponding to the null-vectors of the precision matrix
are to be imposed on the vector of coefficients. By default this is TRUE
for
improper or intrinsic GMRF model components, i.e. components with a singular precision matrix
such as random walks or CAR spatial components.
an optional inequality restriction matrix acting on the coefficients defined by formula
, for each
level defined by factor
. If c is the number of restrictions, S0
is a
q0 x c matrix where q0 is the number of columns of the design matrix derived
from formula
. Together with SA
it defines the set of inequality constraints
to be imposed on the vector of coefficients.
an optional inequality restriction matrix acting on the coefficients defined by factor
,
for each effect defined by formula
. If c is the number of restrictions, SA
is a
l x c matrix where l is the number of levels defined by factor
.
Together with S0
this defines the set of constraints to be imposed on the vector
of coefficients.
a formula of the form ~ glreg(...)
for group-level predictors
around which the random effect component is hierarchically centered.
See glreg
for details.
the name of the model component. This name is used in the output of the MCMC simulation
function MCMCsim
. By default the name will be 'gen' with the number of the model term attached.
whether the model matrix associated with formula
should be sparse.
The default is based on a simple heuristic based on storage size.
whether permutation should be used in the Cholesky decomposition used for updating the model component's coefficient vector. Default is based on a simple heuristic.
if TRUE
a breakpoint is set at the beginning of the posterior
draw function associated with this model component. Mainly intended for developers.
for internal use only.
An object with precomputed quantities and functions for sampling from prior or conditional posterior distributions for this model component. Only intended for internal use by other package functions.
J. Besag and C. Kooperberg (1995). On Conditional and Intrinsic Autoregression. Biometrika 82(4), 733-746.
C.M. Carvalho, N.G. Polson and J.G. Scott (2010). The horseshoe estimator for sparse signals. Biometrika 97(2), 465-480.
L. Fahrmeir, T. Kneib and S. Lang (2004). Penalized Structured Additive Regression for Space-Time Data: a Bayesian Perspective. Statistica Sinica 14, 731-761.
A. Gelman (2006). Prior distributions for variance parameters in hierarchical models. Bayesian Analysis 1(3), 515-533.
A. Gelman, D.A. Van Dyk, Z. Huang and W.J. Boscardin (2008). Using Redundant Parameterizations to Fit Hierarchical Models. Journal of Computational and Graphical Statistics 17(1), 95-122.
B. Leroux, X. Lei and N. Breslow (1999). Estimation of Disease Rates in Small Areas: A New Mixed Model for Spatial Dependence. In M. Halloran and D. Berry (Eds.), Statistical Models in Epidemiology, the Environment and Clinical Trials, 135-178.
T. Park and G. Casella (2008). The Bayesian Lasso. Journal of the American Statistical Association 103(482), 681-686.
H. Rue and L. Held (2005). Gaussian Markov Random Fields. Chapman & Hall/CRC.