Convenience tools and broom-style tidiers for the
durmod package.
durmod (Simen Gaure) estimates a piecewise-constant mixed proportional
hazard competing risk model with the NPMLE. The numerics are excellent
but the surrounding ergonomics — building the formula, choosing control
parameters, validating the data, extracting tidy results — are sparse, so
most users end up writing the same boilerplate in every project.
durmodtools packages that boilerplate as a thin layer on top. It does
not modify or fork durmod; it depends on it.
durmod is no longer maintained on CRAN, so install it directly from
Simen Gaure's GitHub:
# install.packages("remotes")
remotes::install_github("sgaure/durmod")durmod has a C++ backend (Rcpp + OpenMP), so you'll need a working C++
toolchain:
- Windows — install Rtools matching your R version.
- macOS — install Xcode command-line tools (
xcode-select --install) and an OpenMP-enabled clang (the easiest path is via Homebrew:brew install libomp). - Linux — most distributions already have everything.
Then install durmodtools:
remotes::install_github("forlop/durmodtools")library(durmodtools) # auto-loads durmod
data(durdata, package = "durmod")
# Build the formula declaratively (no need to remember ID() / D() / S() / C())
f <- build_formula(
outcome = "d",
id = "id",
duration = "duration",
state = "alpha + 1",
covariates = c("x1", "x2"),
conditional = list(job = "alpha")
)
# Validate the design before launching a long mphcrm run
risksets <- list(unemp = c("job", "program"), onprogram = "job")
validate_design(f, durdata, risksets = risksets)
# Bundled control-parameter presets
ctrl <- control_preset("default", threads = 4)
# or: control_preset("fast") # 3 iters, no Fisher — for testing the spec
# or: control_preset("careful") # 50 iters + numerical Hessian — for inference
# Configurable logging callback (replaces hand-written ones)
ctrl$callback <- logging_callback(show = c("default", "distribution"))
fit <- mphcrm(f, data = durdata, risksets = risksets, control = ctrl)# Information criteria across iterations
model_info(fit)
# Pick the best iteration by AIC, BIC, or logLik
best <- select_iter(fit, by = "AIC")
# Tidy coefficient table (broom / modelsummary / gt compatible)
tidy(best, conf.int = TRUE)
# One-row fit summary
glance(best)
# Wald confidence intervals
confint(best, level = 0.95)
# Per-level factor estimates with SE/CI (no more grep + geninv + sqrt(diag(...)))
factor_effects(best, transition = "job", factor_name = "x1")res <- mphcrm_robust(f, data = durdata, risksets = risksets,
n_runs = 5,
control = control_preset("default", threads = 4))
res$summary # AIC / BIC / npoints across the 5 fits| function | what it does |
|---|---|
build_formula(...) |
declarative constructor for mphcrm's special-syntax formula |
validate_design(...) |
pre-flight check of formula, data, and risksets |
control_preset(...) |
mphcrm.control() presets: "fast" / "default" / "careful" |
logging_callback(...) |
configurable progress + intermediate-save callback |
mphcrm_robust(...) |
run mphcrm N times with different seeds; return all + summary |
| function | what it does |
|---|---|
model_info(fit) |
tibble of logLik / AIC / BIC / df / nobs across all iterations |
select_iter(fit, by = ...) |
pick one iteration by AIC, BIC, logLik, or npoints |
tidy(opt, conf.int = TRUE) |
broom-style coefficient table |
glance(opt) |
broom-style one-row fit summary |
confint(opt, level = 0.95) |
Wald confidence intervals for all coefficients |
factor_effects(opt, tr, f) |
per-level estimates with SE/CI for one (transition × factor) |
predict(opt, newdata) |
placeholder — interface defined, implementation pending |
vignette("pre-estimation", package = "durmodtools")— formula building, validation, control presets.vignette("extracting-results", package = "durmodtools")— accessors, tidiers, factor effects.vignette("mphcrm-output-reference", package = "durmodtools")— what a fittedmphcrmobject carries: every metric, the source-of-truth R formula behind it, and how to interpret it.
durmodtools does not modify durmod. It depends on it (pinned in
DESCRIPTION to a tested minimum version) and registers S3 methods on
durmod's mphcrm.opt and mphcrm.list classes. If durmod is updated
upstream, durmodtools should continue to work provided the output
structure is unchanged; the test suite is designed to catch silent breakage.
Artistic-2.0, matching durmod. Original durmod © Simen Gaure.
durmodtools is a companion package, written with the goal that its
contents could be folded into durmod upstream at any time.