The Beta-Danish Distribution for Lifetime Data Analysis
Overview
Implements the four-parameter Beta-Danish distribution and its three-parameter Exponentiated Danish submodel for survival, reliability and lifetime data analysis, following Ahmad and Danish (2025) doi:10.2478/jamsi-2025-0010. Density, distribution, quantile, survival, hazard and random generation functions are evaluated so as to retain accuracy in the heavy upper tail, where the survival function is regularly varying. Estimation covers maximum likelihood for complete and right-censored samples, ridge-penalized fitting for weakly identified regimes, a grouped likelihood for times recorded on a coarse grid, and Bayesian sampling. Inference provides log-scale Wald and profile likelihood intervals, together with a reparameterization in terms of the identified composite of the two shape parameters. Structural properties include raw, incomplete and conditional moments with their existence conditions, Shannon, Renyi and Tsallis entropies, mean residual life, mean deviations, Lorenz and Bonferroni curves, probability weighted moments, order statistics, stress-strength reliability, hazard shape classification and the tail index. Regression modules cover accelerated failure time models, mixture and promotion-time cure models, and competing risks with Aalen-Johansen comparison and Gray's test. Analyses can be run directly from a delimited text file or spreadsheet.
Visualisation
bd_ttt_plot()draws the scaled total time on test transform, a distribution-free read on hazard shape before any model is fitted. It returns the plotting coordinates and a suggested shape label, so it can be compared againstbd_hazard_shape()from the fitted parameters.bd_profile_plot()draws a profile log-likelihood with the critical threshold and the resulting interval marked. Where the curve never returns below the threshold the plot says there is no finite upper bound, rather than implying one at the edge of the grid.plot()method forbd_bayesobjects, giving trace and posterior density panels and restoring the graphical parameters on exit.- The introduction and competing-risks vignettes cover the new functions.
Show all changes in 0.3.0Hide the rest of the changes in 0.3.0
Competing risks and simulation
fit_bd_competing()accepts covariates, either as a one-sided formula withdataor as a matrix. Each cause carries its own coefficient vector acting on the time scale,T_j = T_0j * exp(x'gamma_j), so a covariate may accelerate one cause and retard another. The intercept is dropped, since each cause already has its own scale parameter.fit_bd_competing(submodel = TRUE)fits Exponentiated Danish cause-specific kernels, and the fit now goes through the same degeneracy guard as the univariate model.cif_betadanish()gains anxargument for the covariate values at which to evaluate the cumulative incidence, defaulting to the reference subject. A covariate effect folds exactly into the scale parameter, since scaling time by lambda mapsktok/lambda.- **Simulation studies**:
bd_simulation_study()for the univariate model,bd_simulation_cure()andbd_simulation_competing(), alongsidesimulate_bd_competing_data(). Each reports bias, RMSE, the ratio of mean estimated standard error to empirical standard deviation, and Wald coverage. Replicates with no admissible optimum are counted rather than dropped.
Estimation and inference
fit_betadanish(grouped = TRUE)uses the grouped likelihood for times recorded on a coarse grid. An event attcontributeslog{F(t + delta/2) - F(t - delta/2)}rather thanlog f(t). The increment is inferred from the spacing of the times unlessdeltais supplied, and a warning now fires when the times look grid-recorded but the point-density likelihood is being used, which understates every standard error.fit_betadanish(penalty = )adds a ridge penalty on the log-parameter scale for the weakly identified regime, shrinking toward the unpenalised optimum unlesspenalty_centersays otherwise. The reportedlogLikis the **unpenalised** log-likelihood evaluated at the penalised estimate, so AIC, BIC and likelihood ratio tests stay comparable with unpenalised fits. The objective actually maximised is kept separately aspenalised_logLik.bd_wald_ci()builds Wald intervals on the log scale and exponentiates, so they cannot cross zero. The symmetric interval on the natural scale does exactly that for a weakly identified tail index.bd_profile_ci()inverts the likelihood ratio test for one parameter. When the profile stays inside the critical region to the top of the grid it returnsInfand says so: an unbounded interval is a result, and the honest report is a lower bound rather than a point estimate.bd_identified_coef()reports the four-parameter fit as(ac, b, k). Near the lower tailaandcenter almost entirely through their product, so the composite is estimated precisely while the two separately are not. The log-likelihood is unchanged: this is a reparametrisation, not a different model.
Theoretical properties
- **Moments**:
bd_moments(),bd_moment_summary(),bd_incomplete_moment()andbd_conditional_moment(). Every integral is taken on the finite Beta(a, b) scale under the substitutionu = G(z), so there is no series truncation. The existence conditionb > ris enforced: a moment that does not exist returnsInfrather than a large finite number from a truncated sum. - **Ageing and inequality**:
bd_mrl()andbd_rmrl()for mean residual life and mean inactivity time,bd_mean_deviation(),bd_lorenz(),bd_bonferroni()andbd_pwm(). - **Entropies**:
bd_entropy_shannon()now uses the closed form, withmethod = "quadrature"retained as an independent cross-check.bd_entropy_renyi()andbd_entropy_tsallis()are new. The quadraturebd_entropy_shannon()that shipped in 0.2.0 fromR/entropy.Ris superseded by the closed form and that file is removed. The signature changes from(a, b, c, k, subdivisions, rel.tol)to(a, b, c, k, terms, method, rel.tol, subdivisions). Named calls are unaffected; a positional call passingsubdivisionsfifth would now setterms. The old behaviour is available asmethod = "quadrature". The closed form's series terms decay likei^-(b+1), so plain truncation is accurate for largeband not for smallb. Against high-precision integration the untruncated-tail sum atM = 2000is out by about1e-8atb = 3but by about0.11atb = 0.5. An analytic Euler-Maclaurin tail is now added, restoring agreement to roughly eight digits throughout. - **Reliability**:
bd_stress_strength()forR = P(X > Y)withXthe strength, evaluated on the Beta scale of the stress variable. - **Shape**:
bd_hazard_shape()classifies the hazard as increasing, decreasing, bathtub or upside-down bathtub using Glaser'seta(t) = -f'(t)/f(t), formed analytically, and reports the mode. - **Order statistics**:
bd_order_stat_cdf()andbd_order_stat_moments(), alongside the existingbd_order_stat_pdf(). - **Tail behaviour**:
bd_tail_index()records that the survival function is regularly varying with index-b, thatE(Z^r)is finite exactly whenb > r, that the moment generating function does not exist, and that the distribution lies in the Frechet domain of attraction. - **Exponentiated Danish API**:
ded(),ped(),qed(),red(),sed()andhed()name thea = 1submodel directly instead of requiringdbetadanish(x, 1, b, c, k).
Datasets
- **
brain_cancerhas been removed.** The dataset of 500 brain cancer patients that shipped in 0.1.0 and 0.2.0 is no longer included, and the AFT example in the README now usesmelanoma. The entry under 0.1.0 below is left as written, since it records what that release actually contained. - **
guinea_pigadded** (Bjerkedal 1960, n = 72): survival times in days of guinea pigs injected with virulent tubercle bacilli. This is the reference case for a well-identified four-parameter fit, with \eqn{\hat b = 3.64} (SE 1.20) sitting about 2.2 standard errors clear of the \eqn{b = 1} ridge. Onremissionandcarbon_fibresthe parent model sits on the flat \eqn{(a, c)} direction instead, so without this dataset no built-in example showed the full model behaving well. - **
inst/extdata/added** with four example CSVs -- complete, censored, covariate and competing-risks -- so that examples and vignettes can demonstrate the file-driven workflow.
File-driven analysis
- **
bd_analyze_csv()** reads a delimited or Excel file, fits the requested model, assembles tidy result tables, and optionally writes those tables and the diagnostic figures to a directory. It covers the univariate, AFT, cure and competing-risks paths. Nothing is written to disk unlessoutput_diris supplied, and each fit is attempted independently so one failure is recorded rather than fatal. - **
bd_csv_template()** writes a correctly shaped skeleton CSV in any of four layouts, so the expected column structure can be seen rather than read about. print,summaryandplotmethods for the newbd_analysisclass.- New vignette: "Analysing Your Own Data from a CSV File".
Data input
read_survival_data()gainscause_col,sep,dec,encoding,na.strings,drop_naandquiet, and will guess the time and status columns when they are not named. Guessing deliberately excludes names such ascensor, whose polarity differs between conventions.- The
bd_data_reportattribute now also records which columns were read_survival_data(covar_cols = "all")retains every column that is not part of the response. Columns that are dropped are now named in a message and recorded in the report, rather than disappearing silently. used and whether the times look recorded on a coarse grid.
Correctness fixes
- **Degenerate optima are no longer reported as fits.** The Beta-Danish likelihood has ridges along which the objective can be driven arbitrarily high with no finite maximiser: as
kandcgrow withc/kfixed, the family collapses to a Frechet-type limit.optim_multistart()selected purely on the highest log-likelihood behind nothing but a finiteness test, so a runaway beat every honest optimum. A four-parameter fit on thetransplantdata returned a log-likelihood of+5.2e77on 91 observations, and the resulting likelihood ratio test reported a chi-squared statistic of1.0e78.fit_betadanish(),fit_bd_aft()andfit_bd_cure()now search over a deterministic start grid before any random starts, and accept only admissible optima: shape parameters bounded by 500, scale within1e-8to1e8, and a plausible per-observation log-likelihood. The thresholds and the start grid are those already used by the thesis analysis pipeline, so the two now agree. - The fitted object records
starts_ok,starts_rejectedandloglik_spread. Warnings fire when starts are discarded as degenerate and when the accepted optima span more than two log-likelihood units, which is the signal thatn_startsis too low for the surface. plot.bd_aft()andplot.bd_cure()now produce the Cox-Snell residual plot. Both looked up the shape parameters ascoefficients["b"]andcoefficients["c"], butfit_bd_aft()andfit_bd_cure()store them aslog_bandlog_c. The lookup returnedNA, the internal guard caught it, and the functions returned without drawing anything. The lookup is fixed and the values are exponentiated back to the natural scale.dbetadanish()is now accurate in the far right tail. The term \eqn{\log\{1 - G(t)\}} was formed aslog1p(-exp(log_G)), which pins at aboutlog(1e-16)onceGrounds to one, flooring the log-density near -36.8 regardless of its true value. It is now formed aslog(-expm1(-c * log1p(1/(k*t)))), which holds full relative precision for everyk*t > 0.pbetadanish()computes the survival function through the beta mirror identity \eqn{1 - I_y(a,b) = I_{1-y}(b,a)}, so a probability near one is never subtracted from one.qbetadanish()obtains \eqn{1 - u} directly from \eqn{1 - q\beta(p; a, b) = q\beta(p; b, a)} with the tail flag reversed. The previous route computedy^(1/c) / (k * (1 - y^(1/c))), which loses all significant digits asuapproaches one. Round-trip accuracy now holds top = 1 - 1e-13.hbetadanish()no longer substitutes-700for an exhausted log-survival. A positive density with zero survival givesInf, an honest divergent hazard, and the indeterminate case givesNaN.- The density, distribution, quantile, survival and hazard functions now recycle their parameters element-wise against
x,qorp, following the usual convention for R distribution functions. fit_betadanish()recordsnpar,nobs,nevent,AICandBICon the fitted object, andreport_betadanish()computes information criteria through thelogLikmethod. Both previously omitted AIC and BIC silently.summary.bd_aft()andsummary.bd_cure()report shape parameters on the natural scale with delta-method standard errors and an exponentiated log-scale confidence interval, separately from the regression coefficients. No Wald test is reported for a shape parameter, since the implied null lies outside the parameter space.read_survival_data()selects columns by name rather than by position, so a covariate namedtimeorstatusno longer collides with the response. Covariates keep their original type. The returned data frame carries abd_data_reportattribute.extract_surv_data()validates times and the event indicator up front and reports a clear error rather than failing inside the optimiser.
New
sbetadanish(), an explicit survival function.fit_betadanish()gainscheck_identifiability. It warns when the optimiser reports a poor code, when the information matrix is singular, when \eqn{\hat b} is within two standard errors of the \eqn{b = 1} non-identifiability ridge, and when the fitted correlation between \eqn{\hat a} and \eqn{\hat c} exceeds 0.95 in absolute value. The Identifiability section of?fit_betadanishexplains each case.
Documentation
?fit_betadanishdocuments the \eqn{b = 1} ridge and the lower-tail \eqn{(a, c)} confounding.?fit_bd_competingdocuments the Tsiatis (1975) non-identifiability result and the direction of bias under latent dependence.?BetaDanishrecords that \eqn{S(t) \propto t^{-b}} in the upper tail and hence that \eqn{E(X^r)} is finite if and only if \eqn{b > r}.- The
a = 1submodel is called the Exponentiated Danish (ED) throughout, in line with the underlying thesis. "Complementary Exponentiated Danish (CED)" has been removed. - Carbon fibre breaking stress is given in GPa. It was previously written "Gba", and the typo was whitelisted in
inst/WORDLIST, which is why the spell check never caught it. - The
melanomahelp page reported six columns and documented seven.
Tests
- Regression tests pin the tail behaviour of the distribution functions. The survival function is regularly varying with index \eqn{-b}, so the slope of \eqn{\log S} against \eqn{\log t} must approach \eqn{-b}. The previous implementation cannot pass this test, which is why the tail defects went unnoticed.
- Smoke tests added for
fit_bd_aft(),fit_bd_cure(),plot.bd_aft()andplot.bd_cure(), none of which were previously covered.
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK2 OK2026-05-21
Documentation
- Help pages
- 59 (1 internal)includes a package overview page
- Examples that run
- 66%29 run in a plain check · 13 only when donttest examples are enabled (R CMD check --as-cran) · 2 never run
- Exported functions with examples
- 83%
- Documented parameters
- 87%
- Return-value docs
- 100%
- Help pages citing references
- 5%
Downloads
Repository
Releases over time
11 development-tooling and community-health practices detected across 7 families in the upstream repository
Checks run against github.com/bilal-aiou/betadanish on 2026-10-18.
The R CMD check workflow runs on Linux, macOS and Windows, and on R-devel
GitHub Pages site last deployed 2026-08-01 · The repository has a site deploy workflow
pkgdown site last built 2026-06-03, before release 0.3.0 (2026-07-31)
Show all practicesHide 3 practices
Dependencies
Installing BetaDanish adds 6 packages (2 with compiled code, 3.1 MB of source tarballs). Heaviest: sandwich 1.4 MB, maxLik 791 KB, zoo 675 KB.
Code & Tests
Datasets
People & History
Pick two releases to compare their code metrics.
- 0.3.0Latest2026-07-31 · current release · diff ↗ ·
added 35 exports
bd_analyze_csv, bd_bonferroni, bd_conditional_moment, bd_csv_template, bd_entropy_renyi, bd_entropy_tsallis, bd_hazard_shape, bd_identified_coef, bd_incomplete_moment, bd_lorenz, bd_mean_deviation, bd_moment_summary, bd_moments, bd_mrl, bd_order_stat_cdf, bd_order_stat_moments, bd_profile_ci, bd_profile_plot, bd_pwm, bd_rmrl, bd_simulation_competing, bd_simulation_cure, bd_simulation_study, bd_stress_strength, bd_tail_index, bd_ttt_plot, bd_wald_ci, ded, hed, ped and 5 more - 0.2.02026-06-04 · diff ↗ ·
added 4 exports
bayes_betadanish, bd_entropy_shannon, bd_order_stat_pdf, cif_compare - 0.1.02026-05-20
- RR 4.6.0 released · 2026-04-24
Package metadata
- First published
- 2026-05-20
- Total releases
- 3 / 1 yrs
- License
- GPL-3 OSI
- Minimum R
- ≥ 3.5
- Bundled data
- 4.7 KB / 7 files
- Download size
- 227 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("BetaDanish")The package provides a citation file that builds its entry when R runs it. Run citation() to see it.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-22, which the citation names so these numbers can be found later. More on citing and the projects behind them.