---
title: "Lindley Approximation for Capability Indices under Hybrid Censoring"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Lindley Approximation for Capability Indices under Hybrid Censoring}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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

```{r setup}
library(gpcihybridIILinApp)
```

## Introduction

The `gpcihybridIILinApp` package provides a comprehensive framework for computing, estimating, and validating Generalized Process Capability Indices (GPCIs) using the **Lindley Approximation Method** for Hybrid Type-II censored lifetime data under Bayesian inference.

### Hybrid Type-II Censoring Scheme
Under Hybrid Type-II censoring with initial sample size $n$, target failures $r$, and censoring time $T_c$, the experiment terminates at time:
$$T^* = \max(x_r, T_c)$$
The likelihood function based on observed failure times $x = (x_1, \dots, x_d)$ ($d \ge r$) is:
$$L(\theta \mid x, r, T_c, n) = \left[ \prod_{i=1}^d f(x_i; \theta) \right] [S(T^*; \theta)]^{n-d}$$

### Supported Generalized Process Capability Indices
Supported GPCIs include:
- $C_{py}$ (Process Capability Index based on Yield; Maiti et al., 2010)
- $C_p, C_{pk}, C_{pu}, C_{pl}, C_{pm}, C_{pmk}$ (Classical capability indices)
- $C_{pTk}$ (Saha et al., 2019)
- $S_{pmk}$ (Dey & Saha, 2019)
- $C_{pc}$ (Saha et al., 2022)
- $CN_{pk}$ (Saha et al., 2018)
- $CN_{pmc}$ (Alotaibi et al., 2022)
- $CN_{pmkc}$ (Saha et al., 2024)
- $C_p(u,v), CN_p(u,v)$ (Vännman's generalized family)
- Quantile-based analogs ($C_{p,q}, C_{pk,q}, C_{pu,q}, C_{pl,q}, C_{pm,q}, C_{pmk,q}$)

## Basic Example with Custom PDF/CDF/SF

Below is an example estimating GPCIs for Hybrid Type-II censored data using the high-level user interface function `gpci_lindley_hybrid2()`:

```{r example-custom}
set.seed(42)
x_obs <- c(0.2, 0.5, 0.8, 1.1, 1.4)

fit_res <- gpci_lindley_hybrid2(
  x = x_obs, r = 3, tc = 1.2, n = 10,
  pdf = function(x, rate = 1) stats::dexp(x, rate = rate),
  cdf = function(x, rate = 1) stats::pexp(x, rate = rate),
  sf  = function(x, rate = 1) stats::pexp(x, rate = rate, lower.tail = FALSE),
  chain_length = 50,
  burn_in = 10,
  thinning = 1,
  USL = 3,
  LSL = 0,
  target = 1.5,
  indices = c("Cpy", "Cp", "Cpk", "Cpm", "CNpmc"),
  B = 20
)

# Display Summary Diagnostics Table
summary(fit_res)
```

## Using Built-in Distribution Objects

The package provides pre-defined distribution objects such as `dist_exponential()`, `dist_weibull()`, `dist_gamma()`, `dist_normal()`, `dist_lognormal()`, `dist_logistic()`, and `dist_loglogistic()`:

```{r example-builtin}
dist_exp <- dist_exponential(rate = 1)

fit_exp <- lindley_gpci_hybrid2(
  x = x_obs, r = 3, tc = 1.2, n = 10,
  distribution = dist_exp,
  chain_length = 50,
  burn_in = 10,
  thinning = 1,
  USL = 3,
  LSL = 0,
  target = 1.5,
  indices = c("Cpy", "Cp", "Cpk", "Cpm", "CNpmc"),
  B = 20
)

summary(fit_exp)
```

## Goodness-of-Fit Testing

Goodness-of-fit testing under Hybrid Type-II censoring can be performed directly using `gof_test_hybrid2()`:

```{r example-gof}
gof_res <- gof_test_hybrid2(
  fit = fit_exp,
  p.method = "asymptotic"
)

print(gof_res)
```

## References

1. Lindley, D. V. (1980). Approximate Bayesian methods. *Trabajos de Estadística y de Investigación Operativa*, 31(1), 223-245.
2. 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.
3. Balakrishnan, N., & Kundu, D. (2013). Hybrid censoring: models, methods and applications. *Naval Research Logistics*, 60(5), 379-409.
4. Maiti, S. S., Saha, M., & Nanda, A. K. (2010). On generalizing process capability indices. *Quality Technology & Quantitative Management*, 7(3), 279-289.
5. Saha, M., Dey, S., & Maiti, S. S. (2018). Parametric and non-parametric bootstrap confidence intervals of CNpk for exponential power distribution. *Journal of Industrial and Production Engineering*, 35(3), 160-169.
6. Dey, S., & Saha, M. (2019). Assessing the process capability index Spmk using improved estimators. *Life Cycle Reliability and Safety Engineering*, 8, 81-88.
7. Saha, M., Dey, S., & Maiti, S. S. (2019). Bootstrap confidence intervals of CpTk for two parameter logistic exponential distribution with applications. *International Journal of System Assurance Engineering and Management*.
8. Alotaibi, R., Dey, S., & Saha, M. (2022). Estimation and confidence intervals of a new PCI CNpmc for logistic-exponential process distribution. *Journal of Mathematics*, 2022, 3135264.
9. Saha, M., Dey, S., & Nadarajah, S. (2022). Parametric inference of the process capability index Cpc for exponentiated exponential distribution. *Journal of Applied Statistics*, 49(16), 4097-4121.
10. Saha, M., Tripathi, V., & Dey, S. (2024). Classical inference of a new PCI CNpmkc for logistic-exponential process distribution. *International Journal of Reliability, Quality and Safety Engineering*, 31(3), 2450013.
11. Heidelberger, P., & Welch, P. D. (1983). Simulation run length control in the presence of an initial transient. *Operations Research*, 31(6), 1109-1144.
