View source: R/fitdistdoublecens.R
| fitdistdoublecens | R Documentation |
This function wraps the custom approach for fitting distributions to doubly censored data using fitdistrplus and primarycensored. It handles primary censoring (when the primary event time is not known exactly), secondary censoring (when the secondary event time is interval-censored), and right truncation (when events are only observed up to a maximum delay).
fitdistdoublecens(
censdata,
distr,
left = "left",
right = "right",
pwindow = "pwindow",
D = "D",
dprimary = stats::dunif,
dprimary_name = lifecycle::deprecated(),
dprimary_args = list(),
truncation_check_multiplier = 2,
...
)
The distr parameter specifies the base name of the distribution. The
function automatically looks up the corresponding density (d) and
cumulative distribution (p) functions by prepending these prefixes to the
distribution name. For example:
distr = "gamma" uses dgamma() and pgamma()
distr = "lnorm" uses dlnorm() and plnorm()
distr = "weibull" uses dweibull() and pweibull()
Any distribution available in base R or loaded packages can be used, as long
as the corresponding d<distr> and p<distr> functions exist and follow
standard R distribution function conventions (first argument is x for
density, q for CDF).
This function creates custom density and CDF functions that account for
primary censoring, secondary censoring, and truncation using
dprimarycensored() and pprimarycensored(). These custom functions are
then passed to fitdistrplus::fitdist() for maximum likelihood estimation.
The function handles varying observation windows across observations, making it suitable for real-world data where truncation times or censoring windows may differ between observations.
An object of class "fitdist" as returned by fitdistrplus::fitdist.
Modelling wrappers for external fitting packages
pcd_as_stan_data(),
pcd_cmdstan_model()
# Example with normal distribution
set.seed(123)
n <- 1000
true_mean <- 5
true_sd <- 2
pwindow <- 2
swindow <- 2
D <- 10
samples <- rprimarycensored(
n, rnorm,
mean = true_mean, sd = true_sd,
pwindow = pwindow, swindow = swindow, D = D
)
delay_data <- data.frame(
left = samples,
right = samples + swindow,
pwindow = rep(pwindow, n),
D = rep(D, n)
)
fit_norm <- fitdistdoublecens(
delay_data,
distr = "norm",
start = list(mean = 0, sd = 1)
)
summary(fit_norm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.