fitdistdoublecens {primarycensored} | R Documentation |
Fit a distribution to doubly censored data
Description
This function wraps the custom approach for fitting distributions to doubly censored data using fitdistrplus and primarycensored.
Usage
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,
...
)
Arguments
censdata |
A data frame with columns 'left' and 'right' representing
the lower and upper bounds of the censored observations. Unlike
|
distr |
A character string naming the distribution to be fitted. |
left |
Column name for lower bound of observed values (default: "left"). |
right |
Column name for upper bound of observed values (default: "right"). |
pwindow |
Column name for primary window (default: "pwindow"). |
D |
Column name for maximum delay (truncation point). If finite, the distribution is truncated at D. If set to Inf, no truncation is applied. (default: "D"). |
dprimary |
Function to generate the probability density function
(PDF) of primary event times. This function should take a value |
dprimary_name |
|
dprimary_args |
List of additional arguments to be passed to
dprimary. For example, when using |
truncation_check_multiplier |
Numeric multiplier to use for checking if the truncation time D is appropriate relative to the maximum delay. Set to NULL to skip the check. Default is 2. |
... |
Additional arguments to be passed to |
Details
This function temporarily assigns and then removes functions from the global environment in order to work with fitdistr. Users should be aware of this behaviour, especially if they have existing functions with the same names in their global environment.
Value
An object of class "fitdist" as returned by fitdistrplus::fitdist.
See Also
Modelling wrappers for external fitting packages
pcd_as_stan_data()
,
pcd_cmdstan_model()
Examples
# 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)