---
title: "Benchmark Analyses and Case Studies with UniLindleyApprox"
author: "Shikhar Tyagi, Arvind Pandey, Bhupendra Singh, Vrijesh Tripathi"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Benchmark Analyses and Case Studies with UniLindleyApprox}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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

## Introduction

This vignette demonstrates the application of `UniLindleyApprox` to 14 benchmark probability distributions across survival analysis, reliability theory, and computational statistics literature:

1. Exponential
2. Weibull
3. Gamma
4. Normal
5. Lognormal
6. Lindley
7. Inverse Gaussian
8. Generalized Gamma
9. Power Lindley
10. Linear Failure Rate
11. Power Failure Rate
12. Modified Topp-Leone
13. Power Xgamma
14. Arvind Distribution

## Weibull Distribution under Progressive Type-II Censoring

```{r}
library(UniLindleyApprox)

# Weibull PDF, CDF, Survival (theta = c(shape, scale))
dweibull_custom <- function(x, theta) dweibull(x, shape = theta[1], scale = theta[2])
pweibull_custom <- function(x, theta) pweibull(x, shape = theta[1], scale = theta[2])
sweibull_custom <- function(x, theta) 1 - pweibull(x, shape = theta[1], scale = theta[2])

# Independent Gamma log-prior for shape and scale
logprior_weibull <- function(theta) {
  if (theta[1] <= 0 || theta[2] <= 0) return(-Inf)
  dgamma(theta[1], shape = 2, rate = 1, log = TRUE) +
    dgamma(theta[2], shape = 2, rate = 1, log = TRUE)
}

# Simulated progressive Type-II data
obs <- c(0.5, 1.2, 1.8, 2.5, 3.1)
R <- c(2, 0, 1, 0, 2)
data_prog <- list(observed = obs, removal_scheme = R, n_total = 10)

fit_weibull <- lindley_fit(
  data = data_prog,
  pdf = dweibull_custom,
  cdf = pweibull_custom,
  survival = sweibull_custom,
  log_prior = logprior_weibull,
  theta0 = c(1.5, 2.0),
  scheme = "progressive_type2",
  loss = "SELF",
  control = lindley.control(verbose = FALSE)
)

summary(fit_weibull)
```

## Lindley Distribution

The 1-parameter Lindley distribution has PDF $f(x) = \frac{\theta^2}{1 + \theta} (1 + x) e^{-\theta x}$ for $x > 0, \theta > 0$.

```{r}
dlindley_custom <- function(x, theta) {
  th <- theta[1]
  if (th <= 0 || any(x <= 0)) return(rep(0, length(x)))
  (th^2 / (1 + th)) * (1 + x) * exp(-th * x)
}

plindley_custom <- function(x, theta) {
  th <- theta[1]
  1 - (1 + (th * x) / (1 + th)) * exp(-th * x)
}

slindley_custom <- function(x, theta) 1 - plindley_custom(x, theta)

set.seed(123)
x_lindley <- rexp(40, rate = 1.5)

fit_lindley <- lindley_fit(
  data = x_lindley,
  pdf = dlindley_custom,
  cdf = plindley_custom,
  survival = slindley_custom,
  log_prior = function(th) dgamma(th[1], 2, 1, log = TRUE),
  theta0 = c(1.0),
  scheme = "complete",
  loss = "LINEX",
  control = lindley.control(verbose = FALSE)
)

print(fit_lindley)
```
