mec: Create a model component object for a regression (fixed...

View source: R/mc_mec.R

mecR Documentation

Create a model component object for a regression (fixed effects) component in the linear predictor with measurement errors in quantitative covariates

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. If b0 or Q0 are specified the prior becomes normal with mean b0 (default 0) and variance (matrix) sigma_^2 Q0^-1 where sigma_^2 is the overall scale parameter of the model, if any. Covariates are assumed to be measured subject to normally distributed errors with zero mean and variance specified using the formula or V arguments. Note that this means that formula should only contain quantitative variables, and no intercept.

Usage

mec(
  formula = ~1,
  sparse = NULL,
  X = NULL,
  V = 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 subject to measurement error and possibly their variances as well. In the latter case the formula syntax ~ (x1 | V.x1) + (x2 | V.x2) + ... should be used where x1, x2, ... are the names of (quantitative) predictors and V.x1, V.x2, ... are the names of the variables holding the corresponding measurement error variances. If only the predictors are specified the formula has the usual form ~ x1 + x2 + .... In that case variances should be specified using argument V. All variable names are looked up in the data frame passed as data argument to create_sampler or generate_data, or in environment(formula).

sparse

whether the model matrix associated with formula should be sparse. The default is to base this on a simple heuristic.

X

a (possibly sparse) design matrix can be specified directly, as an alternative to the creation of one based on formula. If X is specified formula is ignored.

V

measurement error variance; can contain zeros

prior

prior specification for the regression coefficients. Currently only normal priors are supported, specified using function pr_normal.

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 prior instead, i.e. prior = pr_normal(mean = b0.value, precision = Q0.value).

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 prior instead, i.e. prior = pr_normal(mean = b0.value, precision = Q0.value).

R

optional constraint matrix for equality restrictions R'x = r where x is the vector of regression effects.

r

right hand side for the equality constraints.

S

optional constraint matrix for inequality constraints S'x >= s where x is the vector of regression effects.

s

right hand side for the inequality constraints.

lower

as an alternative to s, lower and upper may be specified for two-sided constraints lower <= S'x <= upper.

upper

as an alternative to s, lower and upper may be specified for two-sided constraints lower <= S'x <= upper.

name

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 'reg' with the number of the model term attached.

debug

if TRUE a breakpoint is set at the beginning of the posterior draw function associated with this model component. Mainly intended for developers.

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.

References

L.M. Ybarra and S.L. Lohr (2008). Small area estimation when auxiliary information is measured with error. Biometrika 95(4), 919-931.

S. Arima, G.S. Datta and B. Liseo (2015). Bayesian estimators for small area models when auxiliary information is measured with error. Scandinavian Journal of Statistics 42(2), 518-529.

Examples


# example of Ybarra and Lohr (2008)
m <- 50
X <- rnorm(m, mean=5, sd=3)  # true covariate values
v <- rnorm(m, sd=2)
theta <- 1 + 3*X + v  # true values
psi <- rgamma(m, shape=4.5, scale=2)
e <- rnorm(m, sd=sqrt(psi))  # sampling error
y <- theta + e  # direct estimates
C <- c(rep(3, 10), rep(0, 40))  # measurement error for first 10 values
W <- X + rnorm(m, sd=sqrt(C))  # covariate subject to measurement error

# fit Ybarra-Lohr model
sampler <- create_sampler(
  y ~ 1 + mec(~ 0 + W, V=C) + gen(factor=~local_),
  Q0=1/psi, sigma.fixed=TRUE, linpred="fitted"
)
sim <- MCMCsim(sampler, n.iter=800, n.chain=2, store.all=TRUE, verbose=FALSE)
(summ <- summary(sim))
plot(X, W, xlab="true X", ylab="inferred X")
points(X, summ$mec2_X[, "Mean"], col="green")
abline(0, 1, col="red")
legend("topleft", legend=c("prior mean", "posterior mean"), col=c("black", "green"), pch=c(1,1))



mcmcsae documentation built on Oct. 11, 2023, 1:06 a.m.