---
title: "MCMC Estimation of Generalized Process Capability Indices under Hybrid Type-II Censoring"
author: "Shikhar Tyagi, Vrijesh Tripathi"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{MCMC Estimation of Generalized Process Capability Indices under Hybrid Type-II Censoring}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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

## Introduction

The `gpcihybridIImcmc` package provides Bayesian Markov Chain Monte Carlo (MCMC) estimation methods using Metropolis-Hastings within Gibbs sampler for Generalized Process Capability Indices (GPCIs) under Hybrid Type-II censored lifetime data.

Under Hybrid Type-II censoring (Epstein 1954; Childs et al. 2003; Kundu and Pradhan 2009), $n$ identical units are placed on life testing. The experiment stops at $T^* = \max(x_r, T_c)$, where $r \le n$ is the target number of failures and $T_c > 0$ is the pre-fixed censoring time.

Supported capability indices include $C_{py}$, $C_p$, $C_{pk}$, $C_{pu}$, $C_{pl}$, $C_{pm}$, $C_{pmk}$, $S_{pmk}$, $C_{pTk}$, $C_{pc}$, $C_{Np}$, $C_{Npk}$, $C_{Npm}$, $C_{Npmk}$, $C_{Npmc}$, and $C_{Npmkc}$.

## Usage with Custom Probability Functions

Users can pass custom probability density/mass functions (`pdf`), cumulative distribution functions (`cdf`), and survival functions (`surv`) as R functions:

```{r example}
library(gpcihybridIImcmc)

# User-defined Exponential lifetime distribution functions
my_pdf  <- function(x, rate) stats::dexp(x, rate = rate)
my_cdf  <- function(q, rate) stats::pexp(q, rate = rate)
my_surv <- function(q, rate) stats::pexp(q, rate = rate, lower.tail = FALSE)

# Hybrid Type-II censored sample: n = 10 units, target r = 3, censoring time tc = 2.5
data <- c(0.5, 1.2, 2.1, 3.4)

fit <- gpci_hybrid2_mcmc(
  x = data,
  r = 3,
  tc = 2.5,
  n = 10,
  pdf = my_pdf,
  cdf = my_cdf,
  surv = my_surv,
  param_names = "rate",
  start = c(rate = 0.5),
  length_chain = 1000,
  burn_in = 200,
  thinning = 2,
  USL = 8,
  LSL = 0,
  target = 4
)

print(fit)
```

## Statistical Summaries & Convergence Diagnostics

The package automatically calculates:
- Point estimates and initial MLE estimates under Hybrid Type-II censoring.
- Posterior mean estimates, bias, Mean Squared Error (MSE), and Bayes Risk under squared error loss.
- Highest Posterior Density (HPD) credible intervals at 90%, 95%, and 99% levels.
- Heidelberger and Welch's MCMC Convergence Diagnostics (stationarity and half-width tests).
- Empirical coverage probabilities.

## References

- Childs, A., Chandrasekar, B., Balakrishnan, N., & Kundu, D. (2003). Exact likelihood inference based on type-I and type-II hybrid censored samples from the exponential distribution. *Annals of the Institute of Statistical Mathematics*, 55(2), 319-330. <doi:10.1080/0266476032000053637>
- Kundu, D., & Pradhan, B. (2009). Estimating the parameters of the generalized exponential distribution in presence of hybrid censoring. *Statistics & Probability Letters*, 79(7), 873-882. <doi:10.1016/j.spl.2008.09.006>
- Saha, M., & Dey, S. (2019). Process capability index $C_{py}$ for Lindley distributed quality characteristic. *Quality and Reliability Engineering International*, 35(6), 1930-1949. <doi:10.1007/s41872-019-00081-4>
- Alotaibi, N., Dey, S., Tripathi, H., & Al-Moisheer, A. S. (2022). Estimation and confidence intervals of a new process capability index $C_{Npmc}$ for logistic-exponential distribution. *Journal of Mathematics*, 2022, 3135264. <doi:10.1155/2022/3135264>
- Dey, S., Saha, M., & Maiti, S. S. (2017). Process capability index $C_{py}$ for Weibull distributed quality characteristic. *Communications in Statistics - Simulation and Computation*, 46(8), 6296-6310. <doi:10.1080/03610918.2017.1280166>
- Wu, C. W., Pearn, W. L., & Kotz, S. (2021). An overview of process capability indices. *Communications in Statistics - Theory and Methods*, 50(17), 3959-3984. <doi:10.1080/03610918.2021.1963449>
