| Title: | EM Algorithm for Parameter Estimation Under Censoring Schemes |
|---|---|
| Description: | Performs parameter estimation using the Expectation-Maximization (EM) algorithm of Dempster, Laird, and Rubin (1977) <doi:10.1111/j.2517-6161.1977.tb01600.x> for arbitrary univariate probability distributions under numerous censoring and truncation schemes. Users supply the probability density function (PDF), cumulative distribution function (CDF), survival function, initial parameter vector, support bounds, and observed data; the package automatically estimates parameters using the EM algorithm under the specified censoring scheme. Supported schemes include complete data, right censoring, left censoring, interval censoring, random censoring, block random censoring, Type-I censoring, Type-II censoring, progressive Type-II censoring (Balakrishnan and Aggarwala (2000, ISBN:978-1-4612-1334-5)), progressive first failure censoring, joint Type-I censoring, joint Type-II censoring, balanced joint progressive Type-II censoring, hybrid censoring, hybrid Type-I censoring, hybrid Type-II censoring, Type-I hybrid censoring, Type-II progressively hybrid censoring, doubly Type-II censoring, middle censoring, right truncation, and left truncation. Standard errors are computed via the observed information matrix (numerical Hessian), the Louis (1982) <doi:10.1111/j.2517-6161.1982.tb01203.x> method, and the supplemented EM (SEM) algorithm of Meng and Rubin (1991) <doi:10.1080/01621459.1991.10475130>. The package also provides confidence intervals, model selection criteria (AIC, BIC, AICc, HQIC), goodness-of-fit statistics (Kolmogorov-Smirnov, Cramer-von Mises, Anderson-Darling), residual analysis (randomized quantile residuals, generalized residuals), parametric bootstrap methods, Aitken acceleration for convergence improvement, and comprehensive visualization tools. References: Wu and Kus (2009) <doi:10.1016/j.csda.2009.03.010>, Kundu and Joarder (2006) <doi:10.1016/j.csda.2005.05.002>, Iyer, Jammalamadaka, and Kundu (2008) <doi:10.1016/j.jspi.2007.03.062>, Banerjee and Kundu (2008) <doi:10.1109/TR.2008.916890>, Prajapati, Mitra, and Kundu (2019) <doi:10.1007/s13571-018-0167-0>, Mondal and Kundu (2020) <doi:10.1080/03610926.2018.1554128>, Ding and Gui (2023) <doi:10.3390/math11092003>. |
| Authors: | Shikhar Tyagi [aut, cre] (ORCID: <https://orcid.org/0000-0003-1606-0844>), Arvind Pandey [aut], Bhupendra Singh [aut], Vrijesh Tripathi [aut] |
| Maintainer: | Shikhar Tyagi <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-09-27 09:36:42 UTC |
| Source: | https://github.com/cran/UniCensorEM |
Compute Akaike Information Criterion.
## S3 method for class 'emfit' AIC(object, ...)## S3 method for class 'emfit' AIC(object, ...)
object |
an emfit object. |
... |
additional arguments (ignored). |
AIC value.
Compute Bayesian Information Criterion.
## S3 method for class 'emfit' BIC(object, ...)## S3 method for class 'emfit' BIC(object, ...)
object |
an emfit object. |
... |
additional arguments (ignored). |
BIC value.
Compute bootstrap standard errors and confidence intervals.
bootstrap_se( object, B = 1000, type = "parametric", ci_type = "percentile", level = 0.95, parallel = FALSE, ... )bootstrap_se( object, B = 1000, type = "parametric", ci_type = "percentile", level = 0.95, parallel = FALSE, ... )
object |
an emfit object. |
B |
number of bootstrap replicates (default 1000). |
type |
bootstrap type: "parametric" or "nonparametric" (default "parametric"). |
ci_type |
confidence interval type: "normal", "percentile", "bca", or "basic" (default "percentile"). |
level |
confidence level (default 0.95). |
parallel |
logical; use parallel computing (default FALSE). |
... |
additional arguments. |
List containing bootstrap estimates, standard errors, and confidence intervals.
Extract parameter estimates.
## S3 method for class 'emfit' coef(object, ...)## S3 method for class 'emfit' coef(object, ...)
object |
an emfit object. |
... |
additional arguments (ignored). |
Named vector of parameter estimates.
Compute standard errors for EM estimates
compute_se( theta_star, x, pdf, cdf, survival, scheme, status, time2, censor_params, lower, upper, method = "hessian", em_control = em.control() )compute_se( theta_star, x, pdf, cdf, survival, scheme, status, time2, censor_params, lower, upper, method = "hessian", em_control = em.control() )
theta_star |
converged parameter estimates. |
x |
observed data. |
pdf |
probability density function. |
cdf |
cumulative distribution function. |
survival |
survival function. |
scheme |
censoring scheme name. |
status |
censoring status vector. |
time2 |
upper interval bounds. |
censor_params |
additional censoring parameters. |
lower |
lower support bound. |
upper |
upper support bound. |
method |
standard error estimation method: "hessian", "louis", or "sem". |
em_control |
control parameters for EM algorithm. |
A list containing:
hessian |
the estimated observed information matrix |
vcov |
the variance-covariance matrix |
se |
the standard errors |
Compute confidence intervals for parameter estimates.
## S3 method for class 'emfit' confint(object, parm = NULL, level = 0.95, ...)## S3 method for class 'emfit' confint(object, parm = NULL, level = 0.95, ...)
object |
an emfit object. |
parm |
parameter indices (default: all parameters). |
level |
confidence level (default 0.95). |
... |
additional arguments (ignored). |
Matrix of confidence intervals.
Creates a reusable distribution specification for EM parameter estimation. At minimum, the PDF must be supplied. CDF and survival functions are required for most censoring schemes.
dist_spec_em( pdf = NULL, cdf = NULL, survival = NULL, lower = 0, upper = Inf, name = "custom" )dist_spec_em( pdf = NULL, cdf = NULL, survival = NULL, lower = 0, upper = Inf, name = "custom" )
pdf |
function; probability density function f(x, theta). |
cdf |
function; cumulative distribution function F(x, theta). |
survival |
function; survival function S(x, theta) = 1 - F(x, theta). |
lower |
numeric; lower support bound (default 0). |
upper |
numeric; upper support bound (default Inf). |
name |
character label for output (default "custom"). |
An object of class "dist_spec_em", which is a list with
elements pdf, cdf, survival (user-supplied
functions or NULL), lower and upper (support bounds),
and name (character label).
# Exponential(rate) distribution exp_dist <- dist_spec_em( pdf = function(x, theta) theta[1] * exp(-theta[1] * x), cdf = function(x, theta) 1 - exp(-theta[1] * x), survival = function(x, theta) exp(-theta[1] * x), lower = 0, upper = Inf, name = "Exponential" )# Exponential(rate) distribution exp_dist <- dist_spec_em( pdf = function(x, theta) theta[1] * exp(-theta[1] * x), cdf = function(x, theta) 1 - exp(-theta[1] * x), survival = function(x, theta) exp(-theta[1] * x), lower = 0, upper = Inf, name = "Exponential" )
Compute diagnostic information for EM algorithm convergence.
em_diagnostics(object, ...)em_diagnostics(object, ...)
object |
an emfit object. |
... |
additional arguments (ignored). |
List of diagnostic measures.
Performs parameter estimation using the EM algorithm for arbitrary univariate distributions under specified censoring schemes.
em_fit( data, pdf, cdf = NULL, survival = NULL, theta0, scheme = "complete", status = NULL, time2 = NULL, censor_params = list(), lower = 0, upper = Inf, control = em.control() )em_fit( data, pdf, cdf = NULL, survival = NULL, theta0, scheme = "complete", status = NULL, time2 = NULL, censor_params = list(), lower = 0, upper = Inf, control = em.control() )
data |
observed data vector or data frame with columns x and status. |
pdf |
probability density function f(x, theta). |
cdf |
cumulative distribution function F(x, theta). |
survival |
survival function S(x, theta) = 1 - F(x, theta). |
theta0 |
initial parameter vector. |
scheme |
censoring scheme name (see details). |
status |
censoring status vector (optional, extracted from data if data frame). |
time2 |
upper interval bounds for interval censoring (optional). |
censor_params |
list of additional censoring scheme parameters. |
lower |
lower support bound (default 0). |
upper |
upper support bound (default Inf). |
control |
list of control parameters from em.control(). |
An object of class "emfit" containing:
par |
parameter estimates |
value |
final log-likelihood |
counts |
number of iterations |
convergence |
convergence status (0 = success) |
message |
convergence message |
hessian |
observed information matrix |
std.error |
standard errors |
par_path |
parameter values at each iteration |
lik_path |
log-likelihood values at each iteration |
q_path |
Q-function values at each iteration |
time |
elapsed time in seconds |
scheme |
censoring scheme used |
data |
input data |
control |
control parameters |
Complete (uncensored) data
Right censoring
Left censoring
Interval censoring
Random censoring
Block random censoring
Type-I (time-terminated) censoring
Type-II (failure-terminated) censoring
Progressive Type-II censoring
Progressive first failure censoring
Joint Type-I censoring
Joint Type-II censoring
Balanced joint progressive Type-II censoring
Hybrid censoring
Hybrid Type-I censoring
Hybrid Type-II censoring
Type-I hybrid censoring
Type-II progressively hybrid censoring
Doubly Type-II censoring
Middle censoring
Right truncation
Left truncation
set.seed(123) pdf <- function(x, theta) theta[1] * exp(-theta[1] * x) cdf <- function(x, theta) 1 - exp(-theta[1] * x) survival <- function(x, theta) exp(-theta[1] * x) # Generate right-censored data x_true <- rexp(50, rate = 1.5) cens <- 1.0 status <- ifelse(x_true <= cens, 1, 0) x_obs <- pmin(x_true, cens) # Fit using EM fit <- em_fit( data = x_obs, pdf = pdf, cdf = cdf, survival = survival, theta0 = c(1.0), scheme = "right_censor", status = status, lower = 0.001, upper = 100, control = em.control(maxit = 500, tol = 1e-6) ) summary(fit)set.seed(123) pdf <- function(x, theta) theta[1] * exp(-theta[1] * x) cdf <- function(x, theta) 1 - exp(-theta[1] * x) survival <- function(x, theta) exp(-theta[1] * x) # Generate right-censored data x_true <- rexp(50, rate = 1.5) cens <- 1.0 status <- ifelse(x_true <= cens, 1, 0) x_obs <- pmin(x_true, cens) # Fit using EM fit <- em_fit( data = x_obs, pdf = pdf, cdf = cdf, survival = survival, theta0 = c(1.0), scheme = "right_censor", status = status, lower = 0.001, upper = 100, control = em.control(maxit = 500, tol = 1e-6) ) summary(fit)
Sets control parameters for the EM algorithm optimization.
em.control( maxit = 1000, tol = 1e-08, reltol = 1e-08, emtol = 1e-10, method = "BFGS", se_method = "hessian", trace = FALSE, aitken = FALSE, verbose = FALSE )em.control( maxit = 1000, tol = 1e-08, reltol = 1e-08, emtol = 1e-10, method = "BFGS", se_method = "hessian", trace = FALSE, aitken = FALSE, verbose = FALSE )
maxit |
maximum number of EM iterations (default 1000). |
tol |
convergence tolerance for parameter changes (default 1e-8). |
reltol |
relative convergence tolerance (default 1e-8). |
emtol |
tolerance for Q-function convergence (default 1e-10). |
method |
optimization method for M-step: "BFGS", "L-BFGS-B", "Nelder-Mead", "CG", "SANN", "Brent", or "nlminb" (default "BFGS"). |
se_method |
standard error estimation method: "hessian", "louis", or "sem" (default "hessian"). |
trace |
logical; print iteration progress (default FALSE). |
aitken |
logical; use Aitken acceleration (default FALSE). |
verbose |
logical; detailed output (default FALSE). |
A list of control parameters.
ctrl <- em.control(maxit = 500, tol = 1e-6, method = "BFGS")ctrl <- em.control(maxit = 500, tol = 1e-6, method = "BFGS")
Extract fitted values (estimated survival probabilities at observed times).
## S3 method for class 'emfit' fitted(object, ...)## S3 method for class 'emfit' fitted(object, ...)
object |
an emfit object. |
... |
additional arguments (ignored). |
Vector of fitted survival probabilities.
Compute generalized residuals for censored survival data.
generalized_residuals(object, ...)generalized_residuals(object, ...)
object |
an emfit object. |
... |
additional arguments. |
Vector of generalized residuals.
Get number of cores
get_ncores()get_ncores()
Number of available cores.
Compute various goodness-of-fit statistics for the fitted model.
gof_stats(object, ...)gof_stats(object, ...)
object |
an emfit object. |
... |
additional arguments (ignored). |
Named vector of goodness-of-fit statistics.
Extract the log-likelihood value.
## S3 method for class 'emfit' logLik(object, ...)## S3 method for class 'emfit' logLik(object, ...)
object |
an emfit object. |
... |
additional arguments (ignored). |
Log-likelihood value.
Compute various information criteria for model selection.
model_selection(object, ...)model_selection(object, ...)
object |
an emfit object. |
... |
additional arguments (ignored). |
Named vector of information criteria.
Computes the log-likelihood of the observed data under the specified censoring scheme.
observed_loglik( data, pdf, cdf, survival, theta, scheme, status = NULL, time2 = NULL, censor_params = list(), lower = 0, upper = Inf )observed_loglik( data, pdf, cdf, survival, theta, scheme, status = NULL, time2 = NULL, censor_params = list(), lower = 0, upper = Inf )
data |
observed data vector. |
pdf |
probability density function. |
cdf |
cumulative distribution function. |
survival |
survival function. |
theta |
parameter vector. |
scheme |
censoring scheme name. |
status |
censoring status vector (optional). |
time2 |
upper interval bounds (optional for interval censoring). |
censor_params |
additional censoring scheme parameters (list). |
lower |
lower support bound. |
upper |
upper support bound. |
Log-likelihood value.
Create diagnostic plots for residuals.
plot_residuals(object, type = "cox-snell", which = c(1, 2, 3), ...)plot_residuals(object, type = "cox-snell", which = c(1, 2, 3), ...)
object |
an emfit object. |
type |
type of residuals (default "cox-snell"). |
which |
which plots: 1 = histogram, 2 = QQ plot, 3 = residuals vs fitted, 4 = residuals vs order (default: c(1, 2, 3)). |
... |
additional graphical parameters. |
Invisibly, the emfit object.
Create diagnostic plots for EM algorithm fit.
## S3 method for class 'emfit' plot(x, which = c(1, 2, 3), ask = TRUE, ...)## S3 method for class 'emfit' plot(x, which = c(1, 2, 3), ask = TRUE, ...)
x |
an emfit object. |
which |
which plots to display: 1 = parameter convergence, 2 = log-likelihood convergence, 3 = Q-function, 4 = histogram with fitted density, 5 = QQ plot, 6 = residual plot (default: c(1, 2, 3)). |
ask |
logical; pause between plots (default: TRUE). |
... |
additional graphical parameters. |
Invisibly, the emfit object.
Predict survival probabilities or quantiles for new data.
## S3 method for class 'emfit' predict(object, newdata = NULL, type = "survival", ...)## S3 method for class 'emfit' predict(object, newdata = NULL, type = "survival", ...)
object |
an emfit object. |
newdata |
new data values. |
type |
type of prediction: "survival", "cdf", or "quantile" (default "survival"). |
... |
additional arguments. |
Predicted values.
Print method for bootstrap_emfit objects
## S3 method for class 'bootstrap_emfit' print(x, ...)## S3 method for class 'bootstrap_emfit' print(x, ...)
x |
a bootstrap_emfit object. |
... |
additional arguments (ignored). |
Invisibly, the bootstrap_emfit object.
Print method for dist_spec_em
## S3 method for class 'dist_spec_em' print(x, ...)## S3 method for class 'dist_spec_em' print(x, ...)
x |
a |
... |
ignored. |
Invisibly, the input dist_spec_em object.
Print method for em_diagnostics objects
## S3 method for class 'em_diagnostics' print(x, ...)## S3 method for class 'em_diagnostics' print(x, ...)
x |
an em_diagnostics object. |
... |
additional arguments (ignored). |
Invisibly, the em_diagnostics object.
Print method for emfit objects
## S3 method for class 'emfit' print(x, ...)## S3 method for class 'emfit' print(x, ...)
x |
an emfit object. |
... |
additional arguments (ignored). |
Invisibly, the emfit object.
Print method for summary.emfit objects
## S3 method for class 'summary.emfit' print(x, ...)## S3 method for class 'summary.emfit' print(x, ...)
x |
a summary.emfit object. |
... |
additional arguments (ignored). |
Invisibly, the summary.emfit object.
Computes the Q-function (expected complete log-likelihood) for the EM algorithm.
q_function( theta, theta_old, data, pdf, cdf, survival, scheme, status = NULL, time2 = NULL, censor_params = list(), lower = 0, upper = Inf )q_function( theta, theta_old, data, pdf, cdf, survival, scheme, status = NULL, time2 = NULL, censor_params = list(), lower = 0, upper = Inf )
theta |
parameter vector to maximize over. |
theta_old |
current parameter estimates. |
data |
observed data. |
pdf |
probability density function. |
cdf |
cumulative distribution function. |
survival |
survival function. |
scheme |
censoring scheme name. |
status |
censoring status vector. |
time2 |
upper interval bounds. |
censor_params |
additional censoring parameters. |
lower |
lower support bound. |
upper |
upper support bound. |
Q-function value.
Compute randomized quantile residuals for censored data.
randomized_quantile_residuals(object, n_sim = 1, ...)randomized_quantile_residuals(object, n_sim = 1, ...)
object |
an emfit object. |
n_sim |
number of simulations for randomization (default 1). |
... |
additional arguments. |
Vector of randomized quantile residuals.
Compute various types of residuals for diagnostic purposes.
residual_analysis(object, type = "cox-snell", ...)residual_analysis(object, type = "cox-snell", ...)
object |
an emfit object. |
type |
type of residuals: "cox-snell", "martingale", "deviance", "pearson", "score", or "schoenfeld" (default "cox-snell"). |
... |
additional arguments. |
Vector of residuals.
Compute residuals from the fitted model.
## S3 method for class 'emfit' residuals(object, type = "cox-snell", ...)## S3 method for class 'emfit' residuals(object, type = "cox-snell", ...)
object |
an emfit object. |
type |
type of residuals: "cox-snell", "martingale", "deviance", "pearson", or "response" (default "cox-snell"). |
... |
additional arguments. |
Vector of residuals.
Summary method for emfit objects
## S3 method for class 'emfit' summary(object, ...)## S3 method for class 'emfit' summary(object, ...)
object |
an emfit object. |
... |
additional arguments (ignored). |
A list with summary information.
Extract the variance-covariance matrix of parameter estimates.
## S3 method for class 'emfit' vcov(object, ...)## S3 method for class 'emfit' vcov(object, ...)
object |
an emfit object. |
... |
additional arguments (ignored). |
Variance-covariance matrix.