reg {mcmcsae} | R Documentation |
Create a model component object for a regression (fixed effects) component in the linear predictor
Description
This function is intended to be used on the right hand side of the
formula
argument to create_sampler
or
generate_data
. It creates an additive regression term in the
model's linear predictor. By default, the prior for the regression
coefficients is improper uniform. A proper normal prior can be set up
using function pr_normal
, and passed to argument prior
.
It should be noted that pr_normal
expects a precision matrix
as input for its second argument, and that the prior variance (matrix) is
taken to be the inverse of this precision matrix, where in case the
model's family is "gaussian"
this matrix is additionally
multiplied by the residual scalar variance parameter sigma_^2
.
Usage
reg(
formula = ~1,
remove.redundant = FALSE,
sparse = NULL,
X = NULL,
prior = NULL,
Q0 = NULL,
b0 = NULL,
R = NULL,
r = NULL,
S = NULL,
s = NULL,
lower = NULL,
upper = NULL,
name = "",
debug = FALSE
)
Arguments
formula |
a formula specifying the predictors to be used in the model,
in the same way as the right hand side of the |
remove.redundant |
whether redundant columns should be removed from the
design matrix. Default is |
sparse |
whether the model matrix associated with |
X |
a (possibly sparse) design matrix can be specified directly, as an
alternative to the creation of one based on |
prior |
prior specification for the regression coefficients. Supported
priors can be specified using functions |
Q0 |
prior precision matrix for the regression effects. The default is a
zero matrix corresponding to a noninformative improper prior.
It can be specified as a scalar value, as a numeric vector of appropriate
length, or as a matrix object. DEPRECATED, please use argument |
b0 |
prior mean for the regression effect. Defaults to a zero vector.
It can be specified as a scalar value or as a numeric vector of
appropriate length. DEPRECATED, please use argument |
R |
optional constraint matrix for equality restrictions R'x = r where
|
r |
right hand side for the equality constraints. |
S |
optional constraint matrix for inequality constraints S'x >= s where
|
s |
right hand side for the inequality constraints. |
lower |
as an alternative to |
upper |
as an alternative to |
name |
the name of the model component. This name is used in the output of the
MCMC simulation function |
debug |
if |
Value
An object with precomputed quantities and functions for sampling from prior or conditional posterior distributions for this model component. Intended for internal use by other package functions.
Examples
data(iris)
# default: flat priors on regression coefficients
sampler <- create_sampler(Sepal.Length ~
reg(~ Petal.Length + Species, name="beta"),
data=iris
)
sim <- MCMCsim(sampler, burnin=100, n.iter=400)
summary(sim)
# (weakly) informative normal priors on regression coefficients
sampler <- create_sampler(Sepal.Length ~
reg(~ Petal.Length + Species, prior=pr_normal(precision=1e-2), name="beta"),
data=iris
)
sim <- MCMCsim(sampler, burnin=100, n.iter=400)
summary(sim)
# binary regression
sampler <- create_sampler(Species == "setosa" ~
reg(~ Sepal.Length, prior=pr_normal(precision=0.1), name="beta"),
family="binomial", data=iris)
sim <- MCMCsim(sampler, burnin=100, n.iter=400)
summary(sim)
pred <- predict(sim)
str(pred)
# example with equality constrained regression effects
n <- 500
df <- data.frame(x=runif(n))
df$y <- rnorm(n, 1 + 2*df$x)
R <- matrix(1, 2, 1)
r <- 3
sampler <- create_sampler(y ~ reg(~ 1 + x, R=R, r=r, name="beta"), data=df)
sim <- MCMCsim(sampler)
summary(sim)
plot(sim, "beta")
summary(transform_dc(sim$beta, fun=function(x) crossprod_mv(R, x) - r))