| Title: | Importance Sampling Estimation of Generalized Process Capability Indices |
|---|---|
| Description: | Provides a comprehensive generalized framework for parameter estimation and Generalized Process Capability Indices (GPCIs) under uncensored data using Importance Sampling (ImpSam). Supports user-supplied probability density functions (PDF/PMF), cumulative distribution functions (CDF), and survival functions (SF). Computes classical and generalized capability indices including Cpy (Maiti et al., 2010 <doi:10.1080/16843703.2010.11673233>), Spmk (Dey & Saha, 2019 <doi:10.1080/00949655.2019.1671980>), CpTk (Saha et al., 2019), Cpc (Saha et al., 2022 <doi:10.1080/02664763.2021.1971632>), CNpmc (Alotaibi et al., 2022 <doi:10.1155/2022/3135264>), CNpmkc (Saha et al., 2024 <doi:10.1142/S021853932450013X>), CNpk (Saha et al., 2018 <doi:10.1080/21681015.2018.1437793>), and Vannman's Cp(u,v) family. Generates parameter and GPCI MCMC chains via Sampling Importance Resampling (SIR) after burn-in and thinning. Provides point estimates, bias, MSE, risk values, Highest Posterior Density (HPD) intervals at 90, 95, and 99 percent levels of significance, Heidelberger and Welch MCMC convergence diagnostic, and convergence probability. |
| Authors: | Shikhar Tyagi [aut, cre] (ORCID: <https://orcid.org/0000-0003-1606-0844>) |
| Maintainer: | Shikhar Tyagi <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-07 11:21:48 UTC |
| Source: | https://github.com/cran/gpciImpSam |
Computes classical and generalized Process Capability Indices for a given dataset or process distribution parameters under uncensored data.
capability( data = NULL, distribution, USL, LSL, target = (USL + LSL)/2, indices = NULL, u = 1, v = 1, mode = c("moments", "quantile"), fit = TRUE, fit_method = "mle", C0 = 1, C1 = 0, C2 = 1, tolerance_t = USL - LSL, P0 = 0.9973002, LDL = LSL, UDL = USL )capability( data = NULL, distribution, USL, LSL, target = (USL + LSL)/2, indices = NULL, u = 1, v = 1, mode = c("moments", "quantile"), fit = TRUE, fit_method = "mle", C0 = 1, C1 = 0, C2 = 1, tolerance_t = USL - LSL, P0 = 0.9973002, LDL = LSL, UDL = USL )
data |
Numeric vector of observed process data (optional if distribution is supplied with parameters). |
distribution |
A |
USL |
Upper Specification Limit. |
LSL |
Lower Specification Limit. |
target |
Target value of process (defaults to midpoint of USL and LSL). |
indices |
Character vector of index names to evaluate. Default computes all GPCIs:
|
u |
Parameter |
v |
Parameter |
mode |
Mode of computation: |
fit |
Logical. If |
fit_method |
Parameter estimation method ( |
C0, C1, C2
|
Parameters for tolerance loss function (defaults: 1, 0, 1). |
tolerance_t |
Process tolerance span (defaults to |
P0 |
Expected yield baseline (default 0.9973002). |
LDL, UDL
|
Lower and upper desired limits. |
A named numeric vector of evaluated GPCI values.
dist_n <- dist_normal(mean = 10, sd = 1.5) capability( distribution = dist_n, USL = 15, LSL = 5, target = 10, indices = c("Cpy", "Cp", "Cpk", "Cpm", "Cpmk") )dist_n <- dist_normal(mean = 10, sd = 1.5) capability( distribution = dist_n, USL = 15, LSL = 5, target = 10, indices = c("Cpy", "Cp", "Cpk", "Cpm", "Cpmk") )
Computes numerical or analytical mean and variance for a gpci_dist object.
compute_theoretical_moments(distribution)compute_theoretical_moments(distribution)
distribution |
A |
A list with mean and var.
compute_theoretical_moments(dist_normal(mean = 5, sd = 2))compute_theoretical_moments(dist_normal(mean = 5, sd = 2))
Constructor to define a probability distribution for process capability analysis. The distribution can be defined by specifying any one (or more) of its PDF/PMF, CDF, Survival Function (SF), or quantile function. Missing functions are numerically derived.
define_distribution( name, pdf = NULL, cdf = NULL, sf = NULL, quantile = NULL, params = list(), support = c(-Inf, Inf) )define_distribution( name, pdf = NULL, cdf = NULL, sf = NULL, quantile = NULL, params = list(), support = c(-Inf, Inf) )
name |
Character string naming the distribution. |
pdf |
Function representing the probability density function (PDF/PMF) |
cdf |
Function representing the cumulative distribution function (CDF) |
sf |
Function representing the survival function (SF = 1 - CDF) |
quantile |
Function representing the quantile function |
params |
Named list of parameters for the distribution. |
support |
Vector of length 2 defining the lower and upper bounds of support (default |
An object of class gpci_dist.
dist_norm <- define_distribution( name = "Normal", pdf = function(x, mean = 0, sd = 1) dnorm(x, mean, sd), cdf = function(x, mean = 0, sd = 1) pnorm(x, mean, sd), params = list(mean = 0, sd = 1), support = c(-Inf, Inf) )dist_norm <- define_distribution( name = "Normal", pdf = function(x, mean = 0, sd = 1) dnorm(x, mean, sd), cdf = function(x, mean = 0, sd = 1) pnorm(x, mean, sd), params = list(mean = 0, sd = 1), support = c(-Inf, Inf) )
Standard Pre-defined Exponential Distribution
dist_exponential(rate = 1)dist_exponential(rate = 1)
rate |
Rate parameter (default is 1). |
A gpci_dist object.
d_exp <- dist_exponential(rate = 0.5)d_exp <- dist_exponential(rate = 0.5)
Standard Pre-defined Gamma Distribution
dist_gamma(shape = 1, rate = 1)dist_gamma(shape = 1, rate = 1)
shape |
Shape parameter (default is 1). |
rate |
Rate parameter (default is 1). |
A gpci_dist object.
d_gam <- dist_gamma(shape = 2, rate = 1)d_gam <- dist_gamma(shape = 2, rate = 1)
Pre-defined Logistic-Exponential Distribution
dist_logistic_exponential(alpha = 1, lambda = 1)dist_logistic_exponential(alpha = 1, lambda = 1)
alpha |
Scale/shape parameter (default is 1). |
lambda |
Scale/shape parameter (default is 1). |
A gpci_dist object.
d_le <- dist_logistic_exponential(alpha = 1, lambda = 1)d_le <- dist_logistic_exponential(alpha = 1, lambda = 1)
Standard Pre-defined Normal Distribution
dist_normal(mean = 0, sd = 1)dist_normal(mean = 0, sd = 1)
mean |
Distribution mean (default is 0). |
sd |
Distribution standard deviation (default is 1). |
A gpci_dist object.
d_norm <- dist_normal(mean = 10, sd = 2)d_norm <- dist_normal(mean = 10, sd = 2)
Standard Pre-defined Weibull Distribution
dist_weibull(shape = 1, scale = 1)dist_weibull(shape = 1, scale = 1)
shape |
Shape parameter (default is 1). |
scale |
Scale parameter (default is 1). |
A gpci_dist object.
d_weib <- dist_weibull(shape = 2, scale = 5)d_weib <- dist_weibull(shape = 2, scale = 5)
Fits process distribution parameters to observed uncensored numeric data using Maximum Likelihood Estimation (MLE).
fit_distribution(data, distribution, method = "mle", initial = NULL)fit_distribution(data, distribution, method = "mle", initial = NULL)
data |
Numeric vector of observed process observations. |
distribution |
A |
method |
Optimization method (default |
initial |
Named numeric vector or list of initial parameter values. If |
An updated gpci_dist object with estimated parameters.
data_sample <- rnorm(100, mean = 10, sd = 2) dist_fitted <- fit_distribution(data_sample, dist_normal()) dist_fitted$paramsdata_sample <- rnorm(100, mean = 10, sd = 2) dist_fitted <- fit_distribution(data_sample, dist_normal()) dist_fitted$params
Main user interface to fit uncensored data under Importance Sampling and evaluate GPCIs, returning point estimates, parameter chains, GPCI chains, HPD intervals, and convergence diagnostics.
gpci_impsam( data, pdf = NULL, cdf = NULL, sf = NULL, prior = NULL, chain_length = 1000, burn_in = 200, thinning = 1, USL, LSL, target = (USL + LSL)/2, indices = NULL )gpci_impsam( data, pdf = NULL, cdf = NULL, sf = NULL, prior = NULL, chain_length = 1000, burn_in = 200, thinning = 1, USL, LSL, target = (USL + LSL)/2, indices = NULL )
data |
Numeric vector of process observations. |
pdf |
Custom PDF/PMF function |
cdf |
Custom CDF function |
sf |
Custom Survival Function |
prior |
Prior distribution hyperparameters list or log-prior function. |
chain_length |
MCMC chain length (default 1000). |
burn_in |
MCMC burn-in iterations (default 200). |
thinning |
Thinning interval (default 1). |
USL |
Upper Specification Limit. |
LSL |
Lower Specification Limit. |
target |
Target process value. |
indices |
GPCI names to evaluate. |
A list of class "gpciImpSam" with full summary results.
gpci_impsam( data = rnorm(50, 10, 1), pdf = function(x, mean = 0, sd = 1) dnorm(x, mean, sd), cdf = function(x, mean = 0, sd = 1) pnorm(x, mean, sd), chain_length = 300, burn_in = 50, USL = 13, LSL = 7 )gpci_impsam( data = rnorm(50, 10, 1), pdf = function(x, mean = 0, sd = 1) dnorm(x, mean, sd), cdf = function(x, mean = 0, sd = 1) pnorm(x, mean, sd), chain_length = 300, burn_in = 50, USL = 13, LSL = 7 )
Conducts stationarity and relative half-width tests under Heidelberger and Welch's MCMC convergence diagnostic, returning test statistics, status, and convergence probability.
heidelberger_welch(x, alpha = 0.05, eps = 0.1)heidelberger_welch(x, alpha = 0.05, eps = 0.1)
x |
Numeric vector representing an MCMC chain. |
alpha |
Significance level for the test (default is 0.05). |
eps |
Target maximum ratio of half-width to sample mean (default is 0.1). |
A list containing Cramér-von Mises statistic (stat), p-value (pvalue),
stationarity test status (passed), half-width test status (hw_passed),
half-width statistic (hw_stat), and convergence probability (convergence_prob).
samples <- rnorm(1000) heidelberger_welch(samples)samples <- rnorm(1000) heidelberger_welch(samples)
Computes the Highest Posterior Density (HPD) interval for MCMC posterior samples at specified confidence / significance levels (e.g., 90%, 95%, 99%).
hpd_interval(x, prob = 0.95)hpd_interval(x, prob = 0.95)
x |
Numeric vector of sample draws. |
prob |
Credibility level (1 - significance level). Default is 0.95. |
A named numeric vector of length 2 containing lower and upper bounds.
samples <- rnorm(1000, mean = 5, sd = 1) hpd_interval(samples, prob = 0.95)samples <- rnorm(1000, mean = 5, sd = 1) hpd_interval(samples, prob = 0.95)
Generates posterior parameter draws and Generalized Process Capability Index (GPCI) chains using Importance Sampling (Sampling Importance Resampling, SIR) for uncensored data.
impsam_gpci( data, distribution, prior = NULL, chain_length = 1000, burn_in = 200, thinning = 1, USL, LSL, target = (USL + LSL)/2, indices = NULL, u = 1, v = 1, C0 = 1, C1 = 0, C2 = 1, P0 = 0.9973002 )impsam_gpci( data, distribution, prior = NULL, chain_length = 1000, burn_in = 200, thinning = 1, USL, LSL, target = (USL + LSL)/2, indices = NULL, u = 1, v = 1, C0 = 1, C1 = 0, C2 = 1, P0 = 0.9973002 )
data |
Numeric vector of uncensored process data. |
distribution |
A |
prior |
Function representing the joint log-prior density |
chain_length |
Desired length of final retained MCMC chain after burn-in and thinning. Default is 1000. |
burn_in |
Number of initial burn-in samples to discard. Default is 200. |
thinning |
Thinning interval for sampling. Default is 1 (no thinning). |
USL |
Upper Specification Limit. |
LSL |
Lower Specification Limit. |
target |
Process target value (defaults to midpoint of USL and LSL). |
indices |
Character vector of GPCI names to evaluate. Default computes all 13+ indices. |
u, v
|
Vännman's parameters for |
C0, C1, C2
|
Parameters for tolerance loss function (defaults: 1, 0, 1). |
P0 |
Desirable yield baseline (default 0.9973002). |
A list of class "gpciImpSam" containing:
param_chain |
Matrix of retained MCMC parameter draws. |
gpci_chain |
Matrix or data frame of retained GPCI draws. |
point_estimates |
Point estimates of GPCIs based on uncensored data MLE. |
specs |
Specification limits and setup options. |
data_x <- rnorm(50, mean = 10, sd = 1) dist_norm <- dist_normal() fit_imp <- impsam_gpci( data = data_x, distribution = dist_norm, chain_length = 500, burn_in = 100, thinning = 1, USL = 13, LSL = 7 )data_x <- rnorm(50, mean = 10, sd = 1) dist_norm <- dist_normal() fit_imp <- impsam_gpci( data = data_x, distribution = dist_norm, chain_length = 500, burn_in = 100, thinning = 1, USL = 13, LSL = 7 )
Visualizes GPCI posterior density distributions, trace plots, and HPD intervals.
## S3 method for class 'gpciImpSam' plot(x, type = c("density", "trace"), index = NULL, ...)## S3 method for class 'gpciImpSam' plot(x, type = c("density", "trace"), index = NULL, ...)
x |
An object of class |
type |
Type of plot: |
index |
Character string naming the specific GPCI to plot. Default plots the first index. |
... |
Additional graphical parameters. |
Invisible NULL.
data_x <- rnorm(40, mean = 10, sd = 1) fit <- impsam_gpci(data = data_x, distribution = dist_normal(), USL = 13, LSL = 7) plot(fit, type = "density", index = "Cpy")data_x <- rnorm(40, mean = 10, sd = 1) fit <- impsam_gpci(data = data_x, distribution = dist_normal(), USL = 13, LSL = 7) plot(fit, type = "density", index = "Cpy")
Computes estimated value, bias, MSE, Risk value, HPD intervals at 90%, 95%, and 99% significance levels, Heidelberger and Welch MCMC convergence diagnostic, and convergence probability.
## S3 method for class 'gpciImpSam' summary(object, ...)## S3 method for class 'gpciImpSam' summary(object, ...)
object |
An object of class |
... |
Additional arguments. |
A data frame containing diagnostic metrics for each evaluated GPCI.
data_x <- rnorm(40, mean = 10, sd = 1) fit_imp <- impsam_gpci(data = data_x, distribution = dist_normal(), USL = 13, LSL = 7) summary(fit_imp)data_x <- rnorm(40, mean = 10, sd = 1) fit_imp <- impsam_gpci(data = data_x, distribution = dist_normal(), USL = 13, LSL = 7) summary(fit_imp)