Package {UniCensorEM}


Type: Package
Title: EM Algorithm for Parameter Estimation Under Censoring Schemes
Version: 0.1.0
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>.
License: GPL-3
Depends: R (≥ 4.0.0)
Imports: stats, graphics, grDevices, utils, methods, numDeriv
Suggests: testthat (≥ 3.0.0), maxLik, bbmle, survival, boot, future, furrr, parallel, foreach, doParallel, ggplot2, cubature, pracma, knitr, rmarkdown
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.3.3
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2026-07-19 23:17:39 UTC; shikhar tyagi
Author: Shikhar Tyagi ORCID iD [aut, cre], Arvind Pandey [aut], Bhupendra Singh [aut], Vrijesh Tripathi [aut]
Maintainer: Shikhar Tyagi <shikhar1093tyagi@gmail.com>
Repository: CRAN
Date/Publication: 2026-07-28 16:50:16 UTC

UniCensorEM: EM Algorithm for Parameter Estimation Under Censoring Schemes

Description

The UniCensorEM package performs parameter estimation using the Expectation-Maximization (EM) Algorithm for arbitrary univariate probability distributions under numerous censoring schemes.

Distribution specification

Users supply the probability density function (PDF), cumulative distribution function (CDF), and survival function along with initial parameter values. The package automatically constructs the observed likelihood, complete likelihood, Q-function, and performs the EM iterations.

Censoring schemes

The package supports 23 censoring schemes including complete data, right censoring, left censoring, interval censoring, random censoring, Type-I, Type-II, progressive Type-II, and many more specialized schemes.

Main functions

em_fit

Main function for EM parameter estimation

em.control

Control parameters for EM algorithm

dist_spec_em

Define distribution for EM estimation

bootstrap_se

Bootstrap standard errors

gof_stats

Goodness-of-fit statistics

model_selection

Model selection criteria

S3 methods

print.emfit

Print emfit objects

summary.emfit

Summary of emfit objects

plot.emfit

Diagnostic plots

coef.emfit

Extract parameter estimates

vcov.emfit

Variance-covariance matrix

confint.emfit

Confidence intervals

logLik.emfit

Log-likelihood

AIC.emfit

Akaike Information Criterion

BIC.emfit

Bayesian Information Criterion

residuals.emfit

Residuals

fitted.emfit

Fitted values

predict.emfit

Predictions

Diagnostics

em_diagnostics

EM convergence diagnostics

residual_analysis

Comprehensive residual analysis

randomized_quantile_residuals

Randomized quantile residuals

plot_residuals

Residual diagnostic plots

Author(s)

Shikhar Tyagi shikhar1093tyagi@gmail.com

References

Nagar, D., Kumar, M., and Krishna, H. (2026). Estimation under various censoring schemes using the EM algorithm.


Single bootstrap iteration

Description

Single bootstrap iteration

Usage

.bootstrap_iteration(object, b, type)

Arguments

object

emfit object.

b

iteration number.

type

bootstrap type.

Value

Parameter estimates from bootstrap sample.


Check convergence status

Description

Check convergence status

Usage

.check_convergence(fit)

Arguments

fit

emfit object.

Value

TRUE if converged, FALSE otherwise.


Check for numerical issues

Description

Check for numerical issues

Usage

.check_numerical(value, name = "value")

Arguments

value

numeric value to check.

name

name of the value for error message.

Value

TRUE if valid, otherwise stops with error.


Parallel computing support for UniCensorEM

Description

Functions to enable parallel computation for bootstrap and other intensive operations. Check if parallel computing is available

Usage

.check_parallel()

Value

TRUE if parallel package is available, FALSE otherwise.


Compute conditional expectation E_theta_old(log f(X; theta) | X in (L, R))

Description

Compute conditional expectation E_theta_old(log f(X; theta) | X in (L, R))

Usage

.compute_conditional_expectation(
  L,
  R,
  pdf,
  cdf,
  survival,
  theta,
  theta_old,
  lower,
  upper
)

Format parameter names

Description

Format parameter names

Usage

.format_param_names(theta, prefix = "theta")

Arguments

theta

parameter vector.

prefix

prefix for parameter names.

Value

Named vector with formatted parameter names.


Generate parametric bootstrap sample

Description

Generate parametric bootstrap sample

Usage

.generate_parametric_sample(object, n)

Get censoring scheme description

Description

Get censoring scheme description

Usage

.get_scheme_description(scheme)

Arguments

scheme

censoring scheme name.

Value

Character description of the scheme.


Numerical integration for E(X | L < X < U)

Description

Numerical integration for E(X | L < X < U)

Usage

.integrate_conditional_interval(L, U, pdf, cdf, theta, lower, upper)

Numerical integration for E(X | X < t)

Description

Numerical integration for E(X | X < t)

Usage

.integrate_conditional_left(t, pdf, cdf, theta, lower, upper)

Numerical integration for E(X | X > t)

Description

Numerical integration for E(X | X > t)

Usage

.integrate_conditional_right(t, pdf, survival, theta, lower, upper)

Compute numerical Hessian of negative log-likelihood

Description

Compute numerical Hessian of negative log-likelihood

Usage

.numerical_hessian(
  theta,
  x,
  pdf,
  cdf,
  survival,
  scheme,
  status,
  time2,
  censor_params
)

Fallback finite difference Hessian computation

Description

Fallback finite difference Hessian computation

Usage

.numerical_hessian_fallback(theta, f)

Parallel bootstrap

Description

Perform bootstrap in parallel using future or parallel package.

Usage

.parallel_bootstrap(object, B, type, ncores, ...)

Arguments

object

an emfit object.

B

number of bootstrap replicates.

type

bootstrap type.

ncores

number of cores to use.

...

additional arguments.

Value

Bootstrap results.


Safe division

Description

Compute division with protection against division by zero.

Usage

.safe_div(numerator, denominator, eps = 1e-10)

Arguments

numerator

numerator.

denominator

denominator.

eps

small positive constant to avoid division by zero.

Value

numerator / (denominator + eps).


Safe log function

Description

Compute log with protection against numerical issues.

Usage

.safe_log(x, eps = 1e-10)

Arguments

x

numeric value.

eps

small positive constant to avoid log(0).

Value

log(x + eps).


Set up parallel cluster

Description

Set up parallel cluster

Usage

.setup_cluster(ncores = get_ncores())

Arguments

ncores

number of cores to use (default: get_ncores()).

Value

Cluster object or NULL if parallel not available.


Stop parallel cluster

Description

Stop parallel cluster

Usage

.stop_cluster(cl)

Arguments

cl

cluster object.


Validate parameter bounds

Description

Validate parameter bounds

Usage

.validate_bounds(theta, lower, upper)

Arguments

theta

parameter vector.

lower

lower bound.

upper

upper bound.

Value

TRUE if valid, otherwise stops with error.


Validate distribution functions

Description

Check if user-supplied distribution functions are valid.

Usage

.validate_dist_functions(pdf, cdf, survival, theta, x)

Arguments

pdf

probability density function.

cdf

cumulative distribution function.

survival

survival function.

theta

test parameter vector.

x

test data vector.

Value

TRUE if valid, otherwise stops with error.


Validate EM algorithm inputs

Description

Validate EM algorithm inputs

Usage

.validate_em_inputs(data, pdf, cdf, survival, theta0, scheme, control)

Validate censoring status vector

Description

Validate censoring status vector

Usage

.validate_status(status, scheme)

Arguments

status

censoring status vector.

scheme

censoring scheme name.

Value

TRUE if valid, otherwise stops with error.


AIC method for emfit objects

Description

Compute Akaike Information Criterion.

Usage

## S3 method for class 'emfit'
AIC(object, ...)

Arguments

object

an emfit object.

...

additional arguments (ignored).

Value

AIC value.


BIC method for emfit objects

Description

Compute Bayesian Information Criterion.

Usage

## S3 method for class 'emfit'
BIC(object, ...)

Arguments

object

an emfit object.

...

additional arguments (ignored).

Value

BIC value.


Bootstrap standard errors for emfit objects

Description

Compute bootstrap standard errors and confidence intervals.

Usage

bootstrap_se(
  object,
  B = 1000,
  type = "parametric",
  ci_type = "percentile",
  level = 0.95,
  parallel = FALSE,
  ...
)

Arguments

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.

Value

List containing bootstrap estimates, standard errors, and confidence intervals.


Coefficient method for emfit objects

Description

Extract parameter estimates.

Usage

## S3 method for class 'emfit'
coef(object, ...)

Arguments

object

an emfit object.

...

additional arguments (ignored).

Value

Named vector of parameter estimates.


Compute complete-data log-likelihood

Description

Compute complete-data log-likelihood

Usage

complete_loglik(data_complete, pdf, theta)

Compute standard errors for EM estimates

Description

Compute standard errors for EM estimates

Usage

compute_se(
  theta_star,
  x,
  pdf,
  cdf,
  survival,
  scheme,
  status,
  time2,
  censor_params,
  lower,
  upper,
  method = "hessian",
  em_control = em.control()
)

Arguments

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.

Value

A list containing:

hessian

the estimated observed information matrix

vcov

the variance-covariance matrix

se

the standard errors


Confidence interval method for emfit objects

Description

Compute confidence intervals for parameter estimates.

Usage

## S3 method for class 'emfit'
confint(object, parm = NULL, level = 0.95, ...)

Arguments

object

an emfit object.

parm

parameter indices (default: all parameters).

level

confidence level (default 0.95).

...

additional arguments (ignored).

Value

Matrix of confidence intervals.


Define a univariate distribution for EM estimation

Description

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.

Usage

dist_spec_em(
  pdf = NULL,
  cdf = NULL,
  survival = NULL,
  lower = 0,
  upper = Inf,
  name = "custom"
)

Arguments

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").

Value

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).

Examples

# 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"
)

E-step: Compute conditional expectations

Description

Computes the conditional expectations needed for the EM algorithm based on the censoring scheme.

Usage

e_step(
  data,
  pdf,
  cdf,
  survival,
  theta,
  scheme,
  status,
  time2,
  censor_params,
  lower,
  upper
)

Arguments

data

observed data vector.

pdf

probability density function.

cdf

cumulative distribution function.

survival

survival function.

theta

current parameter vector.

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.

Value

List containing conditional expectations and sufficient statistics.


E-step for complete data

Description

E-step for complete data

Usage

e_step_complete(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params,
  lower,
  upper
)

E-step for interval censoring

Description

For interval-censored observations, compute E(X | L < X < U).

Usage

e_step_interval_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params,
  lower,
  upper
)

E-step for left censoring

Description

For left-censored observations, compute E(X | X < t).

Usage

e_step_left_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params,
  lower,
  upper
)

E-step for left truncation

Description

E-step for left truncation

Usage

e_step_left_truncation(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params,
  lower,
  upper
)

E-step for middle censoring

Description

E-step for middle censoring

Usage

e_step_middle_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params,
  lower,
  upper
)

E-step for progressive Type-II censoring

Description

E-step for progressive Type-II censoring

Usage

e_step_progressive_type2_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params,
  lower,
  upper
)

E-step for random censoring

Description

E-step for random censoring

Usage

e_step_random_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params,
  lower,
  upper
)

E-step for right censoring

Description

For right-censored observations, compute E(X | X > t) using the conditional distribution.

Usage

e_step_right_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params,
  lower,
  upper
)

E-step for right truncation

Description

E-step for right truncation

Usage

e_step_right_truncation(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params,
  lower,
  upper
)

E-step for Type-I censoring

Description

E-step for Type-I censoring

Usage

e_step_type1_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params,
  lower,
  upper
)

E-step for Type-II censoring

Description

E-step for Type-II censoring

Usage

e_step_type2_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params,
  lower,
  upper
)

Control parameters for EM algorithm

Description

Sets control parameters for the EM algorithm optimization.

Usage

em.control(
  maxit = 1000,
  tol = 1e-08,
  reltol = 1e-08,
  emtol = 1e-10,
  method = "BFGS",
  se_method = "hessian",
  trace = FALSE,
  aitken = FALSE,
  verbose = FALSE
)

Arguments

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).

Value

A list of control parameters.

Examples

ctrl <- em.control(maxit = 500, tol = 1e-6, method = "BFGS")

EM diagnostics

Description

Compute diagnostic information for EM algorithm convergence.

Usage

em_diagnostics(object, ...)

Arguments

object

an emfit object.

...

additional arguments (ignored).

Value

List of diagnostic measures.


Main EM algorithm for parameter estimation under censoring

Description

Performs parameter estimation using the EM algorithm for arbitrary univariate distributions under specified censoring schemes.

Usage

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()
)

Arguments

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().

Value

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

Supported censoring schemes

"complete"

Complete (uncensored) data

"right_censor"

Right censoring

"left_censor"

Left censoring

"interval_censor"

Interval censoring

"random_censor"

Random censoring

"block_random_censor"

Block random censoring

"type1_censor"

Type-I (time-terminated) censoring

"type2_censor"

Type-II (failure-terminated) censoring

"progressive_type2_censor"

Progressive Type-II censoring

"progressive_first_failure"

Progressive first failure censoring

"joint_type1_censor"

Joint Type-I censoring

"joint_type2_censor"

Joint Type-II censoring

"bjpt2_censor"

Balanced joint progressive Type-II censoring

"hybrid_censor"

Hybrid censoring

"hybrid_type1_censor"

Hybrid Type-I censoring

"hybrid_type2_censor"

Hybrid Type-II censoring

"type1_hybrid_censor"

Type-I hybrid censoring

"progressive_hybrid_type2_censor"

Type-II progressively hybrid censoring

"doubly_type2_censor"

Doubly Type-II censoring

"middle_censor"

Middle censoring

"right_truncation"

Right truncation

"left_truncation"

Left truncation

Examples

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)

Fitted values method for emfit objects

Description

Extract fitted values (estimated survival probabilities at observed times).

Usage

## S3 method for class 'emfit'
fitted(object, ...)

Arguments

object

an emfit object.

...

additional arguments (ignored).

Value

Vector of fitted survival probabilities.


Generalized residuals

Description

Compute generalized residuals for censored survival data.

Usage

generalized_residuals(object, ...)

Arguments

object

an emfit object.

...

additional arguments.

Value

Vector of generalized residuals.


Extract group parameters from global parameter vector

Description

Extract group parameters from global parameter vector

Usage

get_group_theta(theta, group_index, scheme)

Get number of cores

Description

Get number of cores

Usage

get_ncores()

Value

Number of available cores.


Goodness-of-fit statistics

Description

Compute various goodness-of-fit statistics for the fitted model.

Usage

gof_stats(object, ...)

Arguments

object

an emfit object.

...

additional arguments (ignored).

Value

Named vector of goodness-of-fit statistics.


Log-likelihood method for emfit objects

Description

Extract the log-likelihood value.

Usage

## S3 method for class 'emfit'
logLik(object, ...)

Arguments

object

an emfit object.

...

additional arguments (ignored).

Value

Log-likelihood value.


M-step: Maximize Q-function

Description

Maximizes the Q-function to obtain updated parameter estimates.

Usage

m_step(
  theta_old,
  e_step_result,
  pdf,
  cdf,
  survival,
  scheme,
  method,
  lower,
  upper,
  raw_data,
  status,
  time2,
  censor_params
)

Arguments

theta_old

previous parameter vector.

e_step_result

result from E-step containing complete data and expectations.

pdf

probability density function.

cdf

cumulative distribution function.

survival

survival function.

scheme

censoring scheme name.

method

optimization method.

lower

lower support bound.

upper

upper support bound.

raw_data

raw observed data.

status

censoring status vector.

time2

upper interval bounds.

censor_params

additional censoring parameters.

Value

List containing updated parameters and Q-function value.


Model selection criteria for emfit objects

Description

Compute various information criteria for model selection.

Usage

model_selection(object, ...)

Arguments

object

an emfit object.

...

additional arguments (ignored).

Value

Named vector of information criteria.


Placeholder functions for other censoring schemes Observed likelihood for block random censoring

Description

Placeholder functions for other censoring schemes Observed likelihood for block random censoring

Usage

obs_lik_block_random_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params
)

Observed likelihood for complete data

Description

Observed likelihood for complete data

Usage

obs_lik_complete(data, pdf, cdf, survival, theta, status, time2, censor_params)

Observed likelihood for interval censoring

Description

Observed likelihood for interval censoring

Usage

obs_lik_interval_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params
)

Observed likelihood for left censoring

Description

Observed likelihood for left censoring

Usage

obs_lik_left_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params
)

Observed likelihood for left truncation

Description

Observed likelihood for left truncation

Usage

obs_lik_left_truncation(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params
)

Observed likelihood for middle censoring

Description

Observed likelihood for middle censoring

Usage

obs_lik_middle_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params
)

Observed likelihood for progressive Type-II censoring

Description

Observed likelihood for progressive Type-II censoring

Usage

obs_lik_progressive_type2_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params
)

Observed likelihood for random censoring

Description

Observed likelihood for random censoring

Usage

obs_lik_random_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params
)

Observed likelihood for right censoring

Description

Observed likelihood for right censoring

Usage

obs_lik_right_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params
)

Observed likelihood for right truncation

Description

Observed likelihood for right truncation

Usage

obs_lik_right_truncation(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params
)

Observed likelihood for Type-I censoring

Description

Observed likelihood for Type-I censoring

Usage

obs_lik_type1_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params
)

Observed likelihood for Type-II censoring

Description

Observed likelihood for Type-II censoring

Usage

obs_lik_type2_censor(
  data,
  pdf,
  cdf,
  survival,
  theta,
  status,
  time2,
  censor_params
)

Compute observed log-likelihood

Description

Computes the log-likelihood of the observed data under the specified censoring scheme.

Usage

observed_loglik(
  data,
  pdf,
  cdf,
  survival,
  theta,
  scheme,
  status = NULL,
  time2 = NULL,
  censor_params = list(),
  lower = 0,
  upper = Inf
)

Arguments

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.

Value

Log-likelihood value.


BFGS optimization

Description

BFGS optimization

Usage

optim_bfgs(theta0, neg_q, lower, upper)

Brent optimization (1D only)

Description

Brent optimization (1D only)

Usage

optim_brent(theta0, neg_q, lower, upper)

Conjugate Gradient optimization

Description

Conjugate Gradient optimization

Usage

optim_cg(theta0, neg_q, lower, upper)

L-BFGS-B optimization with bounds

Description

L-BFGS-B optimization with bounds

Usage

optim_lbfgsb(theta0, neg_q, lower, upper)

Nelder-Mead optimization

Description

Nelder-Mead optimization

Usage

optim_nelder(theta0, neg_q, lower, upper)

nlminb optimization

Description

nlminb optimization

Usage

optim_nlminb(theta0, neg_q, lower, upper)

Simulated Annealing optimization

Description

Simulated Annealing optimization

Usage

optim_sann(theta0, neg_q, lower, upper)

Parse and map censoring/truncation schemes to a unified representation

Description

Parse and map censoring/truncation schemes to a unified representation

Usage

parse_censoring_scheme(
  data,
  scheme,
  status = NULL,
  time2 = NULL,
  censor_params = list(),
  lower = 0,
  upper = Inf
)

Arguments

data

user-supplied data.

scheme

censoring scheme name.

status

censoring status vector.

time2

upper interval bounds.

censor_params

additional parameters.

lower

lower support bound.

upper

upper support bound.

Value

A list of groups, where each group has:

obs_data

numeric vector of observed points

cens_intervals

data.frame with L, R, w

trunc_regions

data.frame with L, R, n_obs


Parse joint censoring schemes

Description

Parse joint censoring schemes

Usage

parse_joint_schemes(data, scheme, censor_params, lower, upper)

Plot method for emfit objects

Description

Create diagnostic plots for EM algorithm fit.

Usage

## S3 method for class 'emfit'
plot(x, which = c(1, 2, 3), ask = TRUE, ...)

Arguments

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.

Value

Invisibly, the emfit object.


Plot histogram with fitted density

Description

Plot histogram with fitted density

Usage

plot_histogram_fit(x, ...)

Plot log-likelihood convergence

Description

Plot log-likelihood convergence

Usage

plot_loglik_convergence(x, ...)

Plot parameter convergence

Description

Plot parameter convergence

Usage

plot_parameter_convergence(x, ...)

Plot Q-function values

Description

Plot Q-function values

Usage

plot_q_function(x, ...)

Plot Q-Q plot

Description

Plot Q-Q plot

Usage

plot_qq_plot(x, ...)

Residual diagnostics plot

Description

Create diagnostic plots for residuals.

Usage

plot_residuals(object, type = "cox-snell", which = c(1, 2, 3), ...)

Arguments

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.

Value

Invisibly, the emfit object.


Predict method for emfit objects

Description

Predict survival probabilities or quantiles for new data.

Usage

## S3 method for class 'emfit'
predict(object, newdata = NULL, type = "survival", ...)

Arguments

object

an emfit object.

newdata

new data values.

type

type of prediction: "survival", "cdf", or "quantile" (default "survival").

...

additional arguments.

Value

Predicted values.


Print method for bootstrap_emfit objects

Description

Print method for bootstrap_emfit objects

Usage

## S3 method for class 'bootstrap_emfit'
print(x, ...)

Arguments

x

a bootstrap_emfit object.

...

additional arguments (ignored).

Value

Invisibly, the bootstrap_emfit object.


Print method for dist_spec_em

Description

Print method for dist_spec_em

Usage

## S3 method for class 'dist_spec_em'
print(x, ...)

Arguments

x

a dist_spec_em object.

...

ignored.

Value

Invisibly, the input dist_spec_em object.


Print method for em_diagnostics objects

Description

Print method for em_diagnostics objects

Usage

## S3 method for class 'em_diagnostics'
print(x, ...)

Arguments

x

an em_diagnostics object.

...

additional arguments (ignored).

Value

Invisibly, the em_diagnostics object.


Print method for emfit objects

Description

Print method for emfit objects

Usage

## S3 method for class 'emfit'
print(x, ...)

Arguments

x

an emfit object.

...

additional arguments (ignored).

Value

Invisibly, the emfit object.


Print method for summary.emfit objects

Description

Print method for summary.emfit objects

Usage

## S3 method for class 'summary.emfit'
print(x, ...)

Arguments

x

a summary.emfit object.

...

additional arguments (ignored).

Value

Invisibly, the summary.emfit object.


Q-function for complete data

Description

Q-function for complete data

Usage

q_func_complete(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  status,
  time2,
  censor_params
)

Q-function for interval censoring

Description

Q-function for interval censoring

Usage

q_func_interval_censor(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  status,
  time2,
  censor_params
)

Q-function for left censoring

Description

Q-function for left censoring

Usage

q_func_left_censor(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  status,
  time2,
  censor_params
)

Q-function for left truncation

Description

Q-function for left truncation

Usage

q_func_left_truncation(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  status,
  time2,
  censor_params
)

Q-function for middle censoring

Description

Q-function for middle censoring

Usage

q_func_middle_censor(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  status,
  time2,
  censor_params
)

Q-function for progressive Type-II censoring

Description

Q-function for progressive Type-II censoring

Usage

q_func_progressive_type2_censor(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  status,
  time2,
  censor_params
)

Q-function for random censoring

Description

Q-function for random censoring

Usage

q_func_random_censor(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  status,
  time2,
  censor_params
)

Q-function for right censoring

Description

Q-function for right censoring

Usage

q_func_right_censor(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  status,
  time2,
  censor_params
)

Q-function for right truncation

Description

Q-function for right truncation

Usage

q_func_right_truncation(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  status,
  time2,
  censor_params
)

Q-function for Type-I censoring

Description

Q-function for Type-I censoring

Usage

q_func_type1_censor(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  status,
  time2,
  censor_params
)

Q-function for Type-II censoring

Description

Q-function for Type-II censoring

Usage

q_func_type2_censor(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  status,
  time2,
  censor_params
)

Compute Q-function

Description

Computes the Q-function (expected complete log-likelihood) for the EM algorithm.

Usage

q_function(
  theta,
  theta_old,
  data,
  pdf,
  cdf,
  survival,
  scheme,
  status = NULL,
  time2 = NULL,
  censor_params = list(),
  lower = 0,
  upper = Inf
)

Arguments

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.

Value

Q-function value.


Randomized quantile residuals

Description

Compute randomized quantile residuals for censored data.

Usage

randomized_quantile_residuals(object, n_sim = 1, ...)

Arguments

object

an emfit object.

n_sim

number of simulations for randomization (default 1).

...

additional arguments.

Value

Vector of randomized quantile residuals.


Comprehensive residual analysis for emfit objects

Description

Compute various types of residuals for diagnostic purposes.

Usage

residual_analysis(object, type = "cox-snell", ...)

Arguments

object

an emfit object.

type

type of residuals: "cox-snell", "martingale", "deviance", "pearson", "score", or "schoenfeld" (default "cox-snell").

...

additional arguments.

Value

Vector of residuals.


Residuals method for emfit objects

Description

Compute residuals from the fitted model.

Usage

## S3 method for class 'emfit'
residuals(object, type = "cox-snell", ...)

Arguments

object

an emfit object.

type

type of residuals: "cox-snell", "martingale", "deviance", "pearson", or "response" (default "cox-snell").

...

additional arguments.

Value

Vector of residuals.


Summary method for emfit objects

Description

Summary method for emfit objects

Usage

## S3 method for class 'emfit'
summary(object, ...)

Arguments

object

an emfit object.

...

additional arguments (ignored).

Value

A list with summary information.


Variance-covariance matrix method for emfit objects

Description

Extract the variance-covariance matrix of parameter estimates.

Usage

## S3 method for class 'emfit'
vcov(object, ...)

Arguments

object

an emfit object.

...

additional arguments (ignored).

Value

Variance-covariance matrix.