Prepares the list of data required for geostan's (spatial) measurement error models. Given a data frame of standard errors and any optional arguments, the function returns a list with all required data for the models, filling in missing elements with default values.

prep_me_data(
  se,
  car_parts,
  prior,
  logit = rep(FALSE, times = ncol(se)),
  bounds = c(-Inf, Inf)
)

Arguments

se

Data frame of standard errors; column names must match (exactly) the variable names used in the model formula.

car_parts

A list of data required for spatial CAR models, as created by prep_car_data; optional. If omitted, the measurement error model will be a non-spatial Student's t model.

prior

A named list of prior distributions (see priors). If none are provided, default priors will be assigned. The list of priors may include the following parameters:

df

If using a non-spatial ME model, the degrees of freedom (df) for the Student's t model is assigned a gamma prior with default parameters of gamma2(alpha = 3, beta = 0.2). Provide values for each covariate in se, listing the values in the same order as the columns of se.

location

The prior for the location parameter (mu) is a normal (Gaussian) distribution (the default being normal(location = 0, scale = 100)). To adjust the prior distributions, provide values for each covariate in se, listing the values in the same order as the columns of se.

scale

The prior for the scale parameters is Student's t, and the default parameters are student_t(df = 10, location = 0, scale = 40). To adjust, provide values for each covariate in se, listing the values in the same order as the columns of se.

car_rho

The CAR model, if used, has a spatial autocorrelation parameter, rho, which is assigned a uniform prior distribution. You must specify values that are within the permissible range of values for rho; these are automatically printed to the console by the prep_car_data function.

logit

Optional vector of logical values (TRUE, FALSE) indicating if the latent variable should be logit-transformed. Only use for rates. This keeps rates between zero and one and may improve modeling of skewed variables (e.g., the poverty rate).

bounds

Rarely needed; an optional numeric vector of length two providing the upper and lower bounds, respectively, of the variables (e.g., a magnitudes must be greater than 0). If not provided, they will be set to c(-Inf, Inf) (i.e., unbounded).

Value

A list of data as required for (spatial) ME models. Missing arguments will be filled in with default values, including prior distributions.

See also

Examples

data(georgia)

## for a non-spatial prior model for two covariates
se <- data.frame(ICE = georgia$ICE.se,
                 college = georgia$college.se)
ME <- prep_me_data(se)

## see default priors
print(ME$prior)

## set prior for the scale parameters
ME <- prep_me_data(se,
                   prior = list(scale = student_t(df = c(10, 10),
                                                  location = c(0, 0),
                                                  scale = c(20, 20))))

## for a spatial prior model (often recommended)
A <- shape2mat(georgia, "B")
cars <- prep_car_data(A)
ME <- prep_me_data(se,
                   car_parts = cars)