| Title: | Masked-Cause Likelihood Models for Series Systems with Arbitrary Hazard Components |
|---|---|
| Description: | Likelihood-based inference for series systems with masked component cause of failure, using arbitrary dynamic failure rate component distributions. Computes log-likelihood, score, Hessian, and maximum likelihood estimates for masked data satisfying conditions C1, C2, C3 under general component hazard functions. Implements the 'series_md' protocol defined in the 'maskedcauses' package. |
| Authors: | Alexander Towell [aut, cre] |
| Maintainer: | Alexander Towell <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-05-24 09:28:42 UTC |
| Source: | https://github.com/queelius/maskedhaz |
Assumptions for masked-cause DFR series systems
## S3 method for class 'dfr_series_md' assumptions(model, ...)## S3 method for class 'dfr_series_md' assumptions(model, ...)
model |
A |
... |
Additional arguments (unused). |
Character vector of model assumptions.
model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) assumptions(model)model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) assumptions(model)
Method for cause_probability that returns a
closure computing for each component, marginalized
over the system failure time T via Monte Carlo integration. By Theorem 5,
this equals .
## S3 method for class 'dfr_series_md' cause_probability(model, ...)## S3 method for class 'dfr_series_md' cause_probability(model, ...)
model |
A |
... |
Additional arguments passed to the returned closure. |
A function with signature function(par, ...) returning an
m-vector where element j gives P(K=j | theta).
model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2), dfr_exponential(0.3) )) cp_fn <- cause_probability(model) set.seed(1) cp_fn(par = c(0.1, 0.2, 0.3), n_mc = 2000)model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2), dfr_exponential(0.3) )) cp_fn <- cause_probability(model) set.seed(1) cp_fn(par = c(0.1, 0.2, 0.3), n_mc = 2000)
Component hazard for a masked-cause DFR series system
## S3 method for class 'dfr_series_md' component_hazard(x, j, ...)## S3 method for class 'dfr_series_md' component_hazard(x, j, ...)
x |
A |
j |
Component index. |
... |
Additional arguments passed to the closure. |
A closure computing component j's hazard.
model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) h1 <- component_hazard(model, 1) h1(t = 5, par = 0.1) # 0.1 (constant exponential hazard)model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) h1 <- component_hazard(model, 1) h1(t = 5, par = 0.1) # 0.1 (constant exponential hazard)
Method for conditional_cause_probability that
returns a closure computing for each
component. By Theorem 6 of the foundational paper, this equals
.
## S3 method for class 'dfr_series_md' conditional_cause_probability(model, ...)## S3 method for class 'dfr_series_md' conditional_cause_probability(model, ...)
model |
A |
... |
Additional arguments passed to the returned closure. |
A function with signature function(t, par, ...) returning an
n x m matrix where column j gives P(K=j | T=t, theta).
model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2), dfr_exponential(0.3) )) ccp_fn <- conditional_cause_probability(model) ccp_fn(t = c(1, 5, 10), par = c(0.1, 0.2, 0.3))model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2), dfr_exponential(0.3) )) ccp_fn <- conditional_cause_probability(model) ccp_fn(t = c(1, 5, 10), par = c(0.1, 0.2, 0.3))
Constructs a likelihood model for series systems with masked component cause
of failure, where components are arbitrary dfr_dist
distributions. Supports exact, right-censored, left-censored, and
interval-censored observations with candidate sets satisfying C1-C2-C3.
dfr_series_md( series = NULL, components = NULL, par = NULL, n_par = NULL, lifetime = "t", lifetime_upper = "t_upper", omega = "omega", candset = "x" )dfr_series_md( series = NULL, components = NULL, par = NULL, n_par = NULL, lifetime = "t", lifetime_upper = "t_upper", omega = "omega", candset = "x" )
series |
A |
components |
A list of |
par |
Optional concatenated parameter vector. |
n_par |
Optional integer vector of parameter counts per component. |
lifetime |
Column name for system lifetime (default |
lifetime_upper |
Column name for interval upper bound (default
|
omega |
Column name for observation type (default |
candset |
Column prefix for candidate set indicators (default
|
The model computes the masked-cause log-likelihood for series systems where the system lifetime is the minimum of independent component lifetimes, and the causing component is partially observed through candidate sets.
Observation types (stored in the omega column):
"exact"Failed at time t, cause masked among candidates
"right"Right-censored: survived past time t
"left"Left-censored: failed before time t
"interval"Failed in interval (t, t_upper)
Masking conditions:
Failed component is in candidate set with probability 1
Uniform probability for candidate sets given component cause
Masking probabilities independent of system parameters
An object of class
c("dfr_series_md", "series_md", "likelihood_model").
is_dfr_series_md for the type predicate,
dfr_dist_series for the series distribution,
loglik for the likelihood interface
library(flexhaz) library(serieshaz) # From components model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2), dfr_exponential(0.3) )) # From pre-built series sys <- dfr_dist_series(list( dfr_weibull(shape = 2, scale = 100), dfr_exponential(0.05) )) model2 <- dfr_series_md(series = sys)library(flexhaz) library(serieshaz) # From components model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2), dfr_exponential(0.3) )) # From pre-built series sys <- dfr_dist_series(list( dfr_weibull(shape = 2, scale = 100), dfr_exponential(0.05) )) model2 <- dfr_series_md(series = sys)
Returns a solver function that finds the maximum likelihood estimates for component parameters given masked series system data.
## S3 method for class 'dfr_series_md' fit(object, ...)## S3 method for class 'dfr_series_md' fit(object, ...)
object |
A |
... |
Additional arguments (currently unused). |
Uses optim to maximize the log-likelihood. The score
function (gradient) is computed from the same loglik closure
via grad, and the Hessian at the MLE via
hessian. One-parameter problems auto-upgrade from
Nelder-Mead to BFGS with a warning, because Nelder-Mead is unreliable in
one dimension.
A solver function with signature
function(df, par, method = "Nelder-Mead", ..., control = list())
that returns a fisher_mle object.
model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) set.seed(1) df <- rdata(model)(theta = c(0.1, 0.2), n = 200, tau = 10, p = 0) solver <- fit(model) result <- solver(df, par = c(0.15, 0.15)) coef(result)model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) set.seed(1) df <- rdata(model)(theta = c(0.1, 0.2), n = 200, tau = 10, p = 0) solver <- fit(model) result <- solver(df, par = c(0.15, 0.15)) coef(result)
Returns a Hessian function computed via numerical differentiation of the
log-likelihood using hessian.
## S3 method for class 'dfr_series_md' hess_loglik(model, ...)## S3 method for class 'dfr_series_md' hess_loglik(model, ...)
model |
A |
... |
Additional arguments (currently unused). |
A function with signature function(df, par, ...) returning
the Hessian matrix.
model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) set.seed(1) df <- rdata(model)(theta = c(0.1, 0.2), n = 50, tau = 10, p = 0.3) H_fn <- hess_loglik(model) H_fn(df, par = c(0.1, 0.2))model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) set.seed(1) df <- rdata(model)(theta = c(0.1, 0.2), n = 50, tau = 10, p = 0.3) H_fn <- hess_loglik(model) H_fn(df, par = c(0.1, 0.2))
Test whether an object is a dfr_series_md
is_dfr_series_md(x)is_dfr_series_md(x)
x |
Object to test. |
Logical scalar.
model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) is_dfr_series_md(model) # TRUE is_dfr_series_md(42) # FALSEmodel <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) is_dfr_series_md(model) # TRUE is_dfr_series_md(42) # FALSE
Returns a log-likelihood function for a series system with masked component cause of failure. Supports four observation types: exact failures, right-censored, left-censored, and interval-censored.
## S3 method for class 'dfr_series_md' loglik(model, ...)## S3 method for class 'dfr_series_md' loglik(model, ...)
model |
A |
... |
Additional arguments (currently unused). |
Log-likelihood contributions by observation type:
"exact") "right") "left") "interval")The exact and right-censored paths use vectorized hazard / cumulative hazard
calls. Left and interval censoring require per-row numerical integration
via integrate.
The returned closure caches validated and decoded masked-data extracted
from the data frame across repeated calls with the same df, so that
the O(n) validation cost is paid only once per optim/numDeriv
sweep. The cache is per-closure, kept in the closure's enclosing
environment. This is safe for sequential use; if you share the same
closure object across forked workers (e.g. parallel::mcparallel),
concurrent writes to the cache are possible but only affect performance,
not correctness.
A function with signature function(df, par, ...) that computes
the log-likelihood.
model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) set.seed(1) df <- rdata(model)(theta = c(0.1, 0.2), n = 50, tau = 10, p = 0.3) ll_fn <- loglik(model) ll_fn(df, par = c(0.1, 0.2))model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) set.seed(1) df <- rdata(model)(theta = c(0.1, 0.2), n = 50, tau = 10, p = 0.3) ll_fn <- loglik(model) ll_fn(df, par = c(0.1, 0.2))
Number of components in a masked-cause DFR series system
## S3 method for class 'dfr_series_md' ncomponents(x, ...)## S3 method for class 'dfr_series_md' ncomponents(x, ...)
x |
A |
... |
Additional arguments (unused). |
Integer, the number of components.
model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2), dfr_exponential(0.3) )) ncomponents(model) # 3model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2), dfr_exponential(0.3) )) ncomponents(model) # 3
Print method for dfr_series_md
## S3 method for class 'dfr_series_md' print(x, ...)## S3 method for class 'dfr_series_md' print(x, ...)
x |
A |
... |
Additional arguments (unused). |
Invisibly returns x.
model <- dfr_series_md(components = list( dfr_weibull(shape = 2, scale = 100), dfr_exponential(0.05) )) print(model)model <- dfr_series_md(components = list( dfr_weibull(shape = 2, scale = 100), dfr_exponential(0.05) )) print(model)
Returns a function that generates random masked series system data from the
model's data-generating process (DGP). Uses
sample_components for component lifetimes
and applies right-censoring and masking satisfying C1-C2-C3.
## S3 method for class 'dfr_series_md' rdata(model, ...)## S3 method for class 'dfr_series_md' rdata(model, ...)
model |
A |
... |
Additional arguments (currently unused). |
A function with signature function(theta, n, tau = Inf, p = 0, ...)
that returns a data frame with columns for lifetime, observation type, and
candidate sets.
model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) set.seed(1) df <- rdata(model)(theta = c(0.1, 0.2), n = 20, tau = 10, p = 0.3) head(df)model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) set.seed(1) df <- rdata(model)(theta = c(0.1, 0.2), n = 20, tau = 10, p = 0.3) head(df)
Returns a score (gradient) function computed via numerical differentiation
of the log-likelihood using grad.
## S3 method for class 'dfr_series_md' score(model, ...)## S3 method for class 'dfr_series_md' score(model, ...)
model |
A |
... |
Additional arguments (currently unused). |
A function with signature function(df, par, ...) returning
the gradient vector.
model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) set.seed(1) df <- rdata(model)(theta = c(0.1, 0.2), n = 50, tau = 10, p = 0.3) s_fn <- score(model) s_fn(df, par = c(0.1, 0.2))model <- dfr_series_md(components = list( dfr_exponential(0.1), dfr_exponential(0.2) )) set.seed(1) df <- rdata(model)(theta = c(0.1, 0.2), n = 50, tau = 10, p = 0.3) s_fn <- score(model) s_fn(df, par = c(0.1, 0.2))