## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## -----------------------------------------------------------------------------
library(BDPTobitQR)

# 1. Simulate longitudinal interval-censored dataset
dat <- sim_longitudinal_data(n = 15, m = 4, p = 4, tau = 0.5, seed = 123)

# 2. Fit Bayesian Double Adaptive Lasso Tobit Quantile Regression (PDAL-BTQR)
fit <- bdp_tobit_qr(
  formula = y ~ x1 + x2 + x3 + x4,
  random = ~ 1,
  data = dat,
  id = dat$id,
  lower = dat$lower,
  upper = dat$upper,
  tau = 0.5,
  method = "PDAL-BTQR",
  n_iter = 1000,
  burn_in = 200
)

# 3. Print summary table
summary(fit)

## -----------------------------------------------------------------------------
data("crime_data")

# Fit model at median quantile tau = 0.5
fit_crime <- bdp_tobit_qr(
  formula = y ~ x1 + x2 + x3 + x4 + x5,
  random = ~ 1,
  data = crime_data,
  id = crime_data$id,
  lower = crime_data$lower,
  upper = crime_data$upper,
  tau = 0.5,
  method = "PDAL-BTQR",
  n_iter = 1000,
  burn_in = 200
)

# Model selection and accuracy properties
cat("DIC: ", fit_crime$dic, "\n")
cat("LPML:", fit_crime$lpml, "\n")
cat("MSE: ", fit_crime$mse, "\n")

## -----------------------------------------------------------------------------
# Predict fitted values and 95% forecast credible intervals
pred <- predict(fit_crime, interval = "credible")
head(pred)
