Learn R Programming

bayesQRsurvey (version 0.1.4)

prior: Create prior for Bayesian quantile regression models for complex survey data

Description

prior creates prior distributions for both single (bqr.svy) and multiple-output (mo.bqr.svy) Bayesian quantile regression models for complex survey data.

Usage

prior(
  beta_x_mean = NULL,
  beta_x_cov = NULL,
  sigma_shape = 0.001,
  sigma_rate = 0.001,
  beta_y_mean = NULL,
  beta_y_cov = NULL
)

Value

An object of class "prior".

Arguments

beta_x_mean

vector of prior means for the regression coefficients. (default = NULL).

beta_x_cov

prior covariance matrix for the regression coefficients. (default = NULL).

sigma_shape

shape parameter for inverse Gamma prior for \(\sigma^2\). (default = 0.001).

sigma_rate

rate parameter for inverse Gamma prior for \(\sigma^2\). (default = 0.001).

beta_y_mean

prior means for the coefficients related to the variables that emerge from the product between the orthogonal basis and the outputs (default = NULL).

beta_y_cov

prior covariance matrix for the coefficients related to the variables that emerge from the product between the orthogonal basis and the outputs. (default = NULL).

Details

The function prior builds prior distributions for the three methods implemented in the function bqr.svy and for the multiple-output quantile regression implemented in the function mo.bqr.svy. Every nonspecified prior parameter will get the default value.

  • method = "ald" in function bqr.svy allow the specification of hyperparameters beta_x_mean, beta_x_cov, sigma_shape, and sigma_rate.

  • method = "score" in function bqr.svy allow the specification of hyperparameters beta_x_mean and beta_x_cov.

  • method = "approximate" in function bqr.svy allow the specification of hyperparameters beta_x_mean and beta_x_cov.

  • In function mo.bqr.svy, the specification of hyperparameters beta_x_mean,beta_x_cov, sigma_shape, sigma_rate, beta_y_mean, and beta_y_cov are allowed.

See Also

bqr.svy, mo.bqr.svy, summary

Examples

Run this code
# \donttest{

# Simulate data
set.seed(123)
n  <- 200
x1 <- rnorm(n, 0, 1)
x2 <- runif(n, -1, 1)
w  <- runif(n, 0.5, 2)   # survey weights

y1 <- 2 + 1.5*x1 - 0.8*x2 + rnorm(n, 0, 1)
y2 <- 1 + 0.5*x1 - 0.2*x2 + rnorm(n, 0, 1)

data <- data.frame(y1 = y1, y2 = y2, x1 = x1, x2 = x2, w = w)

# Define a general informative prior
prior_general <- prior(
  beta_x_mean = c(2, 1.5, -0.8),
  beta_x_cov  = diag(c(0.25, 0.25, 0.25)),
  sigma_shape = 3,
  sigma_rate  = 2,
  beta_y_mean = 1,
  beta_y_cov  = 0.25
)

# Estimate the model parameters with informative prior
fit_ald <- bqr.svy(y1 ~ x1 + x2, weights = w, data = data,
                   prior = prior_general, method = "ald")

fit_scr <- bqr.svy(y1 ~ x1 + x2, weights = w, data = data,
                   prior = prior_general, method = "score")

fit_apx <- bqr.svy(y1 ~ x1 + x2, weights = w, data = data,
                   prior = prior_general, method = "approximate")

# Multiple-output method
fit_mo <- mo.bqr.svy(cbind(y1, y2) ~ x1 + x2, weights = w,
                     data = data, prior = prior_general, n_dir = 10)

plot(fit_ald, type = "trace", which = "x1", tau = 0.5)
plot(fit_ald, type = "trace", which = "x2", tau = 0.5)

print(fit_mo)
# }

Run the code above in your browser using DataLab