rprimarycensored {primarycensored} | R Documentation |
Generate random samples from a primary event censored distribution
Description
This function generates random samples from a primary event censored distribution. It adjusts the distribution by accounting for the primary event distribution and potential truncation at a maximum delay (D). The function allows for custom primary event distributions and delay distributions.
Usage
rprimarycensored(
n,
rdist,
pwindow = 1,
swindow = 1,
D = Inf,
rprimary = stats::runif,
rprimary_args = list(),
oversampling_factor = 1.2,
...
)
rpcens(
n,
rdist,
pwindow = 1,
swindow = 1,
D = Inf,
rprimary = stats::runif,
rprimary_args = list(),
oversampling_factor = 1.2,
...
)
Arguments
n |
Number of random samples to generate. |
rdist |
Function to generate random samples from the delay distribution
for example |
pwindow |
Primary event window |
swindow |
Integer specifying the window size for rounding the delay
(default is 1). If |
D |
Maximum delay (truncation point). If finite, the distribution is truncated at D. If set to Inf, no truncation is applied. Defaults to Inf. |
rprimary |
Function to generate random samples from the primary
distribution (default is |
rprimary_args |
List of additional arguments to be passed to rprimary. |
oversampling_factor |
Factor by which to oversample the number of samples to account for truncation (default is 1.2). |
... |
Additional arguments to be passed to the distribution function. |
Details
The mathematical formulation for generating random samples from a primary event censored distribution is as follows:
Generate primary event times (p) from the specified primary event distribution (f_p) within the primary event window (pwindow):
p \sim f_p(x), \quad 0 \leq x \leq pwindow
Generate delays (d) from the specified delay distribution (f_d) with parameters theta:
d \sim f_d(x; \theta)
Calculate the total delays (t) by adding the primary event times and the delays:
t = p + d
Apply truncation to ensure that the delays are within the specified range [0, D]:
t_{truncated} = \{t \mid 0 \leq t < D\}
Round the truncated delays to the nearest secondary event window (swindow):
t_{valid} = \lfloor \frac{t_{truncated}}{swindow} \rfloor \times swindow
The function oversamples to account for potential truncation and generates additional samples if needed to reach the desired number of valid samples.
Value
Vector of random samples from the primary event censored distribution censored by the secondary event window.
See Also
Primary event censored distribution functions
dprimarycensored()
,
pprimarycensored()
Examples
# Example: Lognormal distribution with uniform primary events
rprimarycensored(10, rlnorm, meanlog = 0, sdlog = 1)
# Example: Lognormal distribution with exponential growth primary events
rprimarycensored(
10, rlnorm,
rprimary = rexpgrowth, rprimary_args = list(r = 0.2),
meanlog = 0, sdlog = 1
)