# Gofpt2: Generalized Goodness-of-Fit Test for Censored Data

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

Implements a generalized goodness-of-fit test based on spacings for general progressive Type-II censored data. The test statistic is based on the methodology proposed by **Qin et al. (2022)** and extends the foundational work of **Balakrishnan et al. (2003)**.

Users can test whether their observed censored lifetime data follows any specified continuous distribution by providing custom probability density function (`pdf_func`), cumulative distribution function (`cdf_func`), and survival function (`survival_func`). The package supports both **normal approximation** and **Monte Carlo simulation** approaches for computing $p$-values and critical values.

## Features

- **Generalized Goodness-of-Fit Test**: Perform goodness-of-fit hypothesis testing on general progressive Type-II censored datasets.
- **Custom Distribution Testing**: Test against standard distributions (Exponential, Weibull, Gamma, Lognormal, etc.) or custom user-defined continuous probability distributions.
- **Dual Inference Approaches**: Compute $p$-values and critical bounds using either the analytical normal approximation (Theorem 4.1, Qin et al. 2022) or Monte Carlo simulation.
- **Data Generation**: Function `generate_progressive_censored()` enables generation of general progressive Type-II censored samples from arbitrary continuous distributions.
- **Rich S3 Interface**: Comprehensive `print()`, `summary()`, and `plot()` visualization methods.

## Installation

You can install the development version of `Gofpt2` from GitHub with:

```r
# install.packages("devtools")
devtools::install_github("shikhartyagi/Gofpt2")
```

## Quick Example

```r
library(Gofpt2)

# Define censoring scheme: n = 19, m = 11, r = 2
scheme <- list(
  n = 19,
  m = 11,
  r = 2,
  R = c(0, 0, 2, 0, 0, 2, 0, 0, 1)
)

# Insulating fluid failure data from Example 6.1 (Qin et al., 2022)
obs_data <- c(0.96, 1.31, 3.16, 4.15, 4.67, 7.35, 8.01, 8.27, 32.52, 33.91, 36.71)

# Run goodness-of-fit test against exponential distribution
res <- gof_test_censored(
  data = obs_data,
  censoring_scheme = scheme,
  method = "normal"
)

# Display results
print(res)
summary(res)
plot(res)
```

## References

- **Qin, X., Gui, W., & Balakrishnan, N. (2022).** A goodness-of-fit test for exponential distribution based on spacings for general progressive Type-II censored data. *Journal of Applied Statistics*, 49(8), 1821-1636. [doi:10.1080/02664763.2020.1821613](https://doi.org/10.1080/02664763.2020.1821613)
- **Balakrishnan, N., Ng, H.K.T., & Kannan, N. (2003).** A test of exponentiality based on spacings for progressively type-II censored data. In *Goodness-of-Fit Tests and Model Validity* (pp. 89-111). Birkhäuser, Boston, MA.
- **Balakrishnan, N., & Aggarwala, R. (2000).** *Progressive Censoring: Theory, Methods, and Applications*. Birkhäuser, Boston.
- **Lawless, J.F. (2003).** *Statistical Models and Methods for Lifetime Data* (2nd ed.). John Wiley & Sons, New York.
