View source: R/rprimarycensored.R
| rprimarycensored | R Documentation |
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) and minimum delay (L). The function allows for custom primary event distributions and delay distributions.
rprimarycensored(
n,
rdist,
pwindow = 1,
swindow = 1,
L = -Inf,
D = Inf,
rprimary = stats::runif,
rprimary_args = list(),
oversampling_factor = 1.2,
...
)
rpcens(
n,
rdist,
pwindow = 1,
swindow = 1,
L = -Inf,
D = Inf,
rprimary = stats::runif,
rprimary_args = list(),
oversampling_factor = 1.2,
...
)
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 |
L |
Minimum delay (lower truncation point). Defaults to |
D |
Maximum delay (upper truncation point). If finite, the distribution is truncated at D. If set to Inf, no upper 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. |
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) with parameters phi, defined between 0 and the primary event window (pwindow):
p \sim f_p(\phi), \quad p \in [0, pwindow]
Generate delays (d) from the specified delay distribution (f_d) with parameters theta:
d \sim f_d(\theta)
Calculate the total delays (t) by adding the primary event times and the delays:
t = p + d
Apply upper truncation to remove delays >= D:
t_{upper} = \{t \mid t < D\}
Round the delays to the nearest secondary event window (swindow):
t_{rounded} = \lfloor \frac{t_{upper}}{swindow} \rfloor
\times swindow
Apply lower truncation on the rounded values to ensure observed delays are >= L:
t_{valid} = \{t_{rounded} \mid t_{rounded} \geq L\}
The function oversamples to account for potential truncation and generates additional samples if needed to reach the desired number of valid samples.
Vector of random samples from the primary event censored distribution censored by the secondary event window.
Primary event censored distribution functions
dprimarycensored(),
pprimarycensored(),
qprimarycensored()
# 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
)
# Example: Left-truncated distribution (e.g., for generation intervals)
rprimarycensored(10, rlnorm, L = 1, D = 10, meanlog = 0, sdlog = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.