## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 6,
  fig.height = 4
)

## ----example-exponential------------------------------------------------------
library(gpcihybridIIImpSam)

# 1. User-supplied custom probability density, CDF, and survival 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)

# 2. Observed Hybrid Type-II Censored Data
# n = 10 units placed on test, target r = 3, fixed censoring time Tc = 2.5
x_data <- c(0.4, 0.9, 1.5, 2.3)

# 3. Fit Importance Sampling Model
fit <- gpci_hybrid2_impsam(
  x = 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),
  chain_length = 500,
  burn_in = 100,
  thinning = 1,
  USL = 8,
  LSL = 0,
  target = 4,
  indices = c("Cpy", "Cp", "Cpk", "Cpm", "CNpmc")
)

# 4. Print Summary
print(fit)

## ----summary-methods----------------------------------------------------------
# Full posterior summary
summary(fit)

# Extract 95% HPD credible intervals for capability indices
confint(fit, what = "indices", level = 0.95)

## ----gof-test-----------------------------------------------------------------
dist_exp <- dist_exponential(rate = 0.5)
gof_res <- gof_test_hybrid2(
  fit = fit,
  statistic = "auto",
  p.method = "montecarlo",
  nsim = 50
)
print(gof_res)

