---
title: "Goodness-of-Fit Tests for Censored Lifetime Data with gofPHCS"
author: "Shikhar Tyagi, Arvind Pandey, Bhupendra Singh, Vrijesh Tripathi"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Goodness-of-Fit Tests for Censored Lifetime Data with gofPHCS}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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

## Introduction

The `gofPHCS` package implements a unified framework for conducting goodness-of-fit (GOF) tests on lifetime data subject to complete sampling, progressive Type-II censoring, and Type-I / Type-II hybrid censoring schemes based on Cramer & Balakrishnan (2023).

---

## 1. Complete Data Example

For complete failure time data, standard EDF test statistics including Kolmogorov-Smirnov (`KS`), Cramér-von Mises (`CvM`), and Anderson-Darling (`AD`) are supported.

```{r complete-data}
set.seed(123)
x_complete <- rexp(25, rate = 0.5)

# Create censored data container
cd_comp <- cens_data(x = x_complete, scheme = "complete")

# Define target exponential distribution
dist_exp <- make_distribution(
  cdf = function(x, rate) pexp(x, rate = rate),
  params = c(rate = 0.5),
  support = c(0, Inf)
)

# Perform KS test
test_ks <- gof_test(cd_comp, distribution = dist_exp, statistic = "KS", p.method = "montecarlo", nsim = 499)
print(test_ks)
```

---

## 2. Progressive Type-II Censoring Example

Progressive Type-II censoring allows items to be removed at each failure time according to a pre-specified removal plan $R = (R_1, \dots, R_m)$.

```{r prog2-data}
# Example data: insulating fluid breakdown times (n = 19, m = 18)
x_prog <- c(0.19, 0.78, 0.96, 1.31, 2.78, 3.16, 4.15, 4.67, 4.85, 6.50,
            7.35, 8.01, 8.27, 12.06, 31.75, 32.52, 33.91, 36.71)
R_plan <- c(rep(0, 17), 1)

cd_prog <- cens_data(x = x_prog, scheme = "progtypeII", n = 19, R = R_plan)

# Test exponentiality using Spacings Test statistic T (Balakrishnan et al. 2002b)
test_T <- gof_test(cd_prog, distribution = dist_exp, statistic = "T", p.method = "asymptotic")
print(test_T)
```

---

## 3. Type-I Hybrid Censoring Example

In Type-I hybrid censoring, the test terminates at $T^* = \min(T_0, X_{r:n})$.

```{r hybrid1-data}
set.seed(456)
x_hyb1 <- c(0.25, 0.48, 0.81, 1.05, 1.32)
cd_hyb1 <- cens_data(x = x_hyb1, scheme = "hybridI", n = 10, r = 7, T0 = 1.5)

test_ksi <- gof_test(cd_hyb1, distribution = dist_exp, statistic = "KSI", p.method = "montecarlo", nsim = 499)
print(test_ksi)
```

---

## 4. Type-II Hybrid Censoring Example

In Type-II hybrid censoring, the test terminates at $T^* = \max(T_0, X_{r:n})$.

```{r hybrid2-data}
set.seed(789)
x_hyb2 <- c(0.31, 0.55, 0.92, 1.15, 1.60, 2.10)
cd_hyb2 <- cens_data(x = x_hyb2, scheme = "hybridII", n = 10, r = 5, T0 = 1.0)

test_ksii <- gof_test(cd_hyb2, distribution = dist_exp, statistic = "KSII", p.method = "montecarlo", nsim = 499)
print(test_ksii)
```

---

## References

- Balakrishnan, N., Cramer, E., & Kundu, D. (2023). *Hybrid Censoring Know-How: Designs and Implementations*. Academic Press.
- Banerjee, B., & Pradhan, B. (2018). Kolmogorov-Smirnov test for life test data with hybrid censoring. *Communications in Statistics - Theory and Methods*, 47(11), 2590-2604.
