---
title: "Bayesian Double-Penalty Tobit Quantile Regression for Longitudinal Interval-Censored Data"
author: "Shikhar Tyagi, Arvind Pandey, Bhupendra Singh, Vrijesh Tripathi"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Bayesian Double-Penalty Tobit Quantile Regression for Longitudinal Interval-Censored Data}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

## 1. Introduction

The `BDPTobitQR` package implements the Bayesian Double-Penalty Tobit Quantile Regression methods for longitudinal or clustered interval-censored data proposed by **Zhao, Shu, Hu, & Luo (2024)** (*Mathematics*, 12(12), 1782).

Interval-censored and Tobit-restricted longitudinal data occur frequently in econometrics, social sciences, public health, and medicine. Standard linear or Tobit mean regression models can fail to capture the full conditional distribution of responses across different quantiles. The methods in this package overcome these limitations by combining:
1. **Quantile Regression** via the Asymmetric Laplace Distribution (ALD) normal-exponential mixture decomposition.
2. **Tobit Interval Censoring** with latent variable data augmentation via truncated normal distributions.
3. **Double Penalization** on both fixed effects $\beta$ and random effects $\alpha_i$:
   - **`PDAL-BTQR`**: Double Adaptive Lasso penalty for sparse/dense longitudinal variable selection.
   - **`PDL-BTQR`**: Double Lasso penalty.
   - **`P-BTQR`**: Unpenalized Tobit quantile regression with mixed effects.

## 2. Quick Start Example with Simulated Data

```r
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)
```

## 3. Real-World Application: Interprovincial Crime Rate Data

The package includes the `crime_data` dataset analyzed in Section 4 of Zhao et al. (2024), containing crime rates and economic indicators across 31 provinces from 2010 to 2016.

```r
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")
```

## 4. Forecasting & Predictions

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

## 5. References

- Zhao, K., Shu, T., Hu, C., & Luo, Y. (2024). Research on Quantile Regression Method for Longitudinal Interval-Censored Data Based on Bayesian Double Penalty. *Mathematics*, 12(12), 1782. <doi:10.3390/math12121782>
- Tobin, J. (1958). Estimation of relationships for limited dependent variables. *Econometrica*, 26(1), 24–36.
- Koenker, R., & Bassett, G. (1978). Regression quantiles. *Econometrica*, 46(1), 33–50.
- Zou, H. (2006). The adaptive lasso and its oracle properties. *Journal of the American Statistical Association*, 101(476), 1418–1429.
