# \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