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,
pwindow = 1,
D = Inf,
dprimary = stats::dunif,
dprimary_name = NULL,
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. |
pwindow |
Primary event window |
D |
Maximum delay (truncation point). If finite, the distribution is truncated at D. If set to Inf, no truncation is applied. Defaults to Inf. |
dprimary |
Function to generate the probability density function
(PDF) of primary event times. This function should take a value |
dprimary_name |
A string specifying the name of the primary event
distribution function. If NULL, the function name is extracted using
|
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
)
fit_norm <- fitdistdoublecens(
delay_data,
distr = "norm",
start = list(mean = 0, sd = 1),
D = D, pwindow = pwindow
)
summary(fit_norm)