| Title: | Simulating Nonhomogeneous Poisson Point Processes |
| Version: | 1.1.0 |
| Description: | Simulates events from one dimensional nonhomogeneous Poisson point processes (NHPPPs) as per Trikalinos and Sereda (2024, <doi:10.48550/arXiv.2402.00358> and 2024, <doi:10.1371/journal.pone.0311311>). Functions are based on three algorithms that provably sample from a target NHPPP: the time-transformation of a homogeneous Poisson process (of intensity one) via the inverse of the integrated intensity function (Cinlar E, "Theory of stochastic processes" (1975, ISBN:0486497996)); the generation of a Poisson number of order statistics from a fixed density function; and the thinning of a majorizing NHPPP via an acceptance-rejection scheme (Lewis PAW, Shedler, GS (1979) <doi:10.1002/nav.3800260304>). |
| License: | GPL (≥ 3) |
| Imports: | lifecycle, rstream, Rcpp (≥ 1.0.12) |
| LinkingTo: | Rcpp |
| Encoding: | UTF-8 |
| Language: | en |
| RoxygenNote: | 7.3.3 |
| Suggests: | data.table, ggplot2, knitr, rlecuyer, rmarkdown, testthat, tictoc, truncnorm, withr, |
| Config/Needs/website: | rmarkdown |
| URL: | https://bladder-ca.github.io/nhppp/, https://github.com/bladder-ca/nhppp |
| BugReports: | https://github.com/bladder-ca/nhppp/issues |
| VignetteBuilder: | knitr |
| Depends: | R (≥ 2.10) |
| LazyData: | true |
| NeedsCompilation: | yes |
| Packaged: | 2026-11-15 17:37:41 UTC; tom |
| Author: | Thomas Trikalinos |
| Maintainer: | Thomas Trikalinos <thomas_trikalinos@brown.edu> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-15 18:20:02 UTC |
nhppp: Simulating Nonhomogeneous Poisson Point Processes
Description
Simulates events from one dimensional nonhomogeneous Poisson point processes (NHPPPs) as per Trikalinos and Sereda (2024, doi:10.48550/arXiv.2402.00358 and 2024, doi:10.1371/journal.pone.0311311). Functions are based on three algorithms that provably sample from a target NHPPP: the time-transformation of a homogeneous Poisson process (of intensity one) via the inverse of the integrated intensity function (Cinlar E, "Theory of stochastic processes" (1975, ISBN:0486497996)); the generation of a Poisson number of order statistics from a fixed density function; and the thinning of a majorizing NHPPP via an acceptance-rejection scheme (Lewis PAW, Shedler, GS (1979) doi:10.1002/nav.3800260304).
Author(s)
Maintainer: Thomas Trikalinos thomas_trikalinos@brown.edu (ORCID) [copyright holder]
Authors:
Yuliia Sereda sereda_yuliia@brown.edu (ORCID)
See Also
Useful links:
Report bugs at https://github.com/bladder-ca/nhppp/issues
Definite integral of l = exp(intercept + slope*t) at time t
with L(t0) = 0
Description
Definite integral of l = exp(intercept + slope*t) starting at
t0 – only for l+.
Usage
Lambda_exp_form(t, intercept, slope, t0)
Arguments
t |
(double) the time point |
intercept |
(double) the intercept |
slope |
(double) the slope |
t0 |
(double) the starting time |
Inverse of the definite integral of l = exp(intercept + slope*t) at time t
Description
Inverse of the definite integral of l = exp(intercept + slope*t) only for l+.
Usage
Lambda_inv_exp_form(z, intercept, slope, t0)
Arguments
z |
(double) the value of integrated rate for which you want to find the time |
intercept |
(double) the intercept |
slope |
(double) the slope |
t0 |
(double) the starting time |
Inverse of the definite integral of l = intercept + slope*t at time t
Description
Inverse of the definite integral of l = intercept + slope*t only for l+.
Usage
Lambda_inv_linear_form(z, intercept, slope, t0)
Arguments
z |
(double) the value of integrated rate for which you want to find the time |
intercept |
(double) the intercept |
slope |
(double) the slope |
t0 |
(double) the starting time |
Definite integral of l = intercept + slope*t at time t
with L(t0) = 0
Description
Definite integral of l = intercept + slope*t starting at
t0 – only for l+.
Usage
Lambda_linear_form(t, intercept, slope, t0)
Arguments
t |
(double) the time point |
intercept |
(double) the intercept |
slope |
(double) the slope |
t0 |
(double) the starting time |
Human mortality database age and sex specific rates for all cause deaths
Description
This is the 2015 annual death rates from the 2023 version of the Human Mortality Database for the USA.
Usage
annual_mortality_rates_2015
Format
annual_mortality_rates_2015
a data.table with 3 rows and 113 columns.
- birth_cohort
Birth cohort as a calendar year
- sex
sex:
female,male,total.- age_0, ..., age 110+
age-specific death rates
Source
Check the validity of ppp samples in the long event format
Description
Standard checks for a long-format sample
list(id, time, n_draws): ids in range and ascending, times ascending
within id, all times in [t_min, t_max], and the per-process count
contracts. All checks are whole-vector operations.
Usage
check_ppp_long_validity(
x,
t_min,
t_max = NULL,
size = NULL,
atmost1 = FALSE,
atleast1 = FALSE,
atmostk = NULL,
atleastk = NULL
)
Arguments
x |
(list) long event sample with elements |
t_min |
(double | vector) the start of the time interval |
t_max |
(double | vector) optional: the end of the time interval |
size |
(double) optional: the per-process event count (empty processes are exempt, matching the matrix check) |
atmost1 |
(boolean) optional: at most one event per process |
atleast1 |
(boolean) optional: at least one event per process |
atmostk |
(integer) optional: at most |
atleastk |
(integer) optional: at least |
Value
None
Check the validity of ppp samples arranged in matrix format
Description
Standard checks for a matrix of ordered times
(event series in rows, times in columns). Check
that the times in the columns are sorted, have unique values
in [t_min, t_max], and has length size (if applicable).
Usage
check_ppp_sample_validity(
times,
t_min,
t_max = NULL,
size = NULL,
atmost1 = FALSE,
atleast1 = FALSE,
atmostk = NULL,
atleastk = NULL
)
Arguments
times |
(vector, double | matrix) the times to be checked as vectors or matrices (time-vectors in rows) |
t_min |
(double | vector) the start of the time nterval |
t_max |
(double| vector) optional: the end of the time interval; if a vector, its length should match the number of rows of |
size |
(double) optional: the size of the vector |
atmost1 |
(boolean) optional: at most one sample returned |
atleast1 |
(boolean) optional: at least one sample returned |
atmostk |
(integer) optional: at most |
atleastk |
(integer) optional: at least |
Value
None
Check the validity of a ppp vector.
Description
Standard checks for a vector of ordered times. Check
that the times vector is sorted, has unique values, has all values
in [t_min, t_max], and has length size (if applicable).
Usage
check_ppp_vector_validity(
times,
t_min,
t_max = NULL,
size = NULL,
atmost1 = FALSE,
atleast1 = FALSE,
atmostk = NULL,
atleastk = NULL
)
Arguments
times |
(vector, double) the times to be checked |
t_min |
(double) the start of the time nterval |
t_max |
(double) optional: the end of the time interval |
size |
(double) optional: the size of the vector |
atmost1 |
(boolean) optional: at most one sample returned |
atleast1 |
(boolean) optional: at least one sample returned |
atmostk |
(integer) optional: at most |
atleastk |
(integer) optional: at least |
Value
None
Check that two ppp vectors Q-Q agree
Description
Compare that the deciles of two vectors have absolute difference
over average ratios less than threshold
Usage
compare_ppp_vectors(ppp1, ppp2, threshold = 0.15, showQQ = TRUE)
Arguments
ppp1 |
(vector, double) the first vector |
ppp2 |
(vector, double) the second vector |
threshold |
(double) optional: the cutoff for a large absolute threshold |
showQQ |
(boolean) optional: show the QQ plot if the absolute value of the
Difference vs Average ratio in any decile is bigger than the |
Value
None
Generic function for simulating from NHPPPs given the intensity function or the cumulative intensity function.
Description
This is a wrapper to the package's specific functions, and thus somewhat slower. For time-intensive simulations prefer one of the specific functions.
Usage
draw(
Lambda = NULL,
Lambda_inv = NULL,
lambda = NULL,
line_majorizer_intercept = NULL,
line_majorizer_slope = NULL,
line_majorizer_is_loglinear = FALSE,
step_majorizer_vector = NULL,
t_min = NULL,
t_max = NULL,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL
)
Arguments
Lambda |
(function, double vector) the integrated (cumulative) rate of the NHPPP |
Lambda_inv |
(function, double vector) the inverse of ‘Lambda()’ |
lambda |
(function) the instantaneous rate |
line_majorizer_intercept |
The intercept |
line_majorizer_slope |
The slope |
line_majorizer_is_loglinear |
(boolean) if |
step_majorizer_vector |
(vector, double) |
t_min |
(double) the lower bound of the interval |
t_max |
(double) the upper bound of the interval |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
Value
a vector of event times
Examples
# thinning, with a constant majorizer line
x <- draw(
lambda = function(t) 1 + sin(t),
line_majorizer_intercept = 2,
line_majorizer_slope = 0,
t_min = 0, t_max = 10
)
# inversion, conditioned on at least one event
x <- draw(
Lambda = function(t) 2 * t,
Lambda_inv = function(z) z / 2,
t_min = 0, t_max = 10,
atleast1 = TRUE
)
Simulate from a non homogeneous Poisson Point Process (NHPPP) over an interval when you know the cumulative intensity and its inverse.
Description
Sample NHPPP times using the inversion method
Usage
draw_cumulative_intensity(
Lambda,
Lambda_inv,
t_min,
t_max,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL
)
Arguments
Lambda |
(function, double vector) a continuous increasing R to R map which is the integrated rate of the NHPPP |
Lambda_inv |
(function, double vector) the inverse of |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
Value
a vector of event times (t_); if no events realize, a vector of length 0
Simulate from a non homogeneous Poisson Point Process (NHPPP) from (t_min, t_max) (inversion method)
Description
Sample NHPPP times using the inversion method,
optionally using an rstream generator object
Usage
draw_cumulative_intensity_inversion(
Lambda,
Lambda_inv,
t_min,
t_max,
atmost1 = FALSE
)
Arguments
Lambda |
(function, double vector) a continuous increasing R to R map which is the integrated rate of the NHPPP |
Lambda_inv |
(function, double vector) the inverse of |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
atmost1 |
boolean, draw at most 1 event time |
Value
a vector of event times (t_); if no events realize, a vector of length 0
Simulate from a non homogeneous Poisson Point Process (NHPPP) from (t_min, t_max) (order statistics method)
Description
Sample NHPPP times using the order statistics method,
optionally using an rstream generator object.
Usage
draw_cumulative_intensity_orderstats(
Lambda,
Lambda_inv,
t_min,
t_max,
atmost1 = FALSE
)
Arguments
Lambda |
(function, double vector) a continuous increasing R to R map which is the integrated rate of the NHPPP |
Lambda_inv |
(function, double vector) the inverse of |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
atmost1 |
boolean, draw at most 1 event time |
Value
a vector of event times (t_); if no events realize, a vector of length 0
Generic function for simulating from NHPPPs given the intensity function.
Description
Sample from NHPPPs given the intensity function This is a wrapper to the package's specific functions, and thus somewhat slower. For time-intensive simulations prefer one of the specific functions.
Usage
draw_intensity(
lambda,
line_majorizer_intercept = NULL,
line_majorizer_slope = NULL,
line_majorizer_is_loglinear = FALSE,
step_majorizer_vector = NULL,
t_min = NULL,
t_max = NULL,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL
)
Arguments
lambda |
(function) the instantaneous rate |
line_majorizer_intercept |
The intercept |
line_majorizer_slope |
The slope |
line_majorizer_is_loglinear |
(boolean) if |
step_majorizer_vector |
(vector, double) |
t_min |
(double) the lower bound of the interval |
t_max |
(double) the upper bound of the interval |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
must be |
Value
a vector of event times
Simulate from a non homogeneous Poisson Point Process (NHPPP) from (t0, t_max) (thinning method)
Description
Sample NHPPP times using the thinning method
Usage
draw_intensity_line(
lambda,
majorizer_intercept,
majorizer_slope,
t_min,
t_max,
majorizer_is_loglinear = FALSE,
atmost1 = FALSE
)
Arguments
lambda |
(function) the instantaneous rate of the NHPPP. |
majorizer_intercept |
(double) the intercept ( |
majorizer_slope |
(double) the slope (‘beta’) of the loglinear majorizer function. |
t_min |
(double) the lower bound of the time interval. |
t_max |
(double) the upper bound of the time interval. |
majorizer_is_loglinear |
(boolean) if |
atmost1 |
boolean, draw at most 1 event time |
Value
a vector of event times (t_); if no events realize, a vector of length 0
Simulate from a non homogeneous Poisson Point Process (NHPPP) from (t0, t_max) (thinning method) with piecewise constant_majorizer
Description
Sample NHPPP times using the thinning method
Usage
draw_intensity_step(lambda, majorizer_vector, time_breaks, atmost1 = FALSE)
Arguments
lambda |
(function) the instantaneous rate of the NHPPP. A continuous function of time. |
majorizer_vector |
(scalar, double) |
time_breaks |
(vector, double) |
atmost1 |
boolean, draw at most 1 event time |
Value
a vector of event times (t_); if no events realize, a vector of length 0
Special case: Simulate from a non homogeneous Poisson Point Process (NHPPP) from (t_min, t_max) with linear intensity function (inversion method)
Description
Sample NHPPP times from a linear intensity function
using the inversion method, optionally using an rstream
generator
Usage
draw_sc_linear(
intercept,
slope,
t_min,
t_max,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL
)
Arguments
intercept |
(double) the intercept |
slope |
(double) the slope |
t_min |
(double) lower bound of the time interval |
t_max |
(double) upper bound of the time interval |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
Value
a vector of event times (t_); if no events realize, a vector of length 0
Examples
x <- draw_sc_linear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
Special case: Simulate from a non homogeneous Poisson Point Process (NHPPP) from (t_min, t_max) with log-linear intensity function (inversion method)
Description
Sample NHPPP times from an log linear intensity function
using the inversion method, optionally using an rstream
generator
Usage
draw_sc_loglinear(
intercept,
slope,
t_min,
t_max,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL
)
Arguments
intercept |
(double) the intercept in the exponent |
slope |
(double) the slope in the exponent |
t_min |
(double) lower bound of the time interval |
t_max |
(double) upper bound of the time interval |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
Value
a vector of event times (t_); if no events realize, a vector of length 0
Examples
x <- draw_sc_loglinear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
Simulate a piecewise constant-rate Poisson Point Process over (t_min, t_max] (inversion method)
The intervals need not have the same length.
Description
Simulate a piecewise constant-rate Poisson Point Process over (t_min, t_max] (inversion method)
The intervals need not have the same length.
Usage
draw_sc_step(
lambda_vector,
time_breaks,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL
)
Arguments
lambda_vector |
(scalar, double) |
time_breaks |
(vector, double) |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
Value
a vector of event times t if no events realize, it will have 0 length
Examples
x <- draw_sc_step(lambda_vector = rep(1, 5), time_breaks = c(0:5))
Sampling from NHPPPs with piecewise constant intensities with same interval lengths (non-vectorized)
Description
Sampling from NHPPPs with piecewise constant intensities with same interval lengths (non-vectorized)
Usage
draw_sc_step_regular(
Lambda_vector = NULL,
lambda_vector = NULL,
t_min = NULL,
t_max = NULL,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL
)
Arguments
Lambda_vector |
(scalar, double) |
lambda_vector |
(scalar, double) |
t_min |
(scalar, double) lower bound of the time interval |
t_max |
(scalar, double) upper bound of the time interval |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
Value
a vector of event times t if no events realize, it will have 0 length
Examples
x <- draw_sc_step_regular(Lambda_vector = 1:5, t_min = 0, t_max = 5)
Helper functions
Description
helper function that augments
test_that::expect_no_error() to expect no error.
Copied from the R6 source code.
Usage
expect_no_error(expr)
Arguments
expr |
Expression. |
Details
Small utility functions. Not to be exported to the user.
Piecewise constant (step) majorizer for K-Lipschitz functions over an interval
(vectorized over the breaks argument).
Description
Return a piecewise constant (step) majorizer for K-Lipschitz functions
over an interval. The function is vectorized over the breaks argument.
The returned object has the same dimensions as breaks.
Usage
get_step_majorizer(fun, breaks, is_monotone = TRUE, K = 0, fun_args = NULL)
Arguments
fun |
A function object with a single argument |
breaks |
(vector or matrix) The set of |
is_monotone |
(boolean) Is the function monotone? (Default is |
K |
(double) A non-negative number for the Lipschitz cone. (Default is 0.) |
fun_args |
(list) arguments for |
Value
A vector of length M with the values of the piecewise constant majorizer
Examples
get_step_majorizer(fun = abs, breaks = -5:5, is_monotone = FALSE, K = 1)
# a lambda that takes the structured args container
get_step_majorizer(
fun = function(t, a) a$shared$scale * abs(t),
breaks = matrix(rep(-5:5, each = 3), nrow = 3),
is_monotone = FALSE, K = 2,
fun_args = list(shared = list(scale = 2))
)
Numerically evaluate the inverse of a function at a specific point
Description
Numerically evaluate the inverse of a function at a specific point
Usage
inverse_with_uniroot(
f = f,
y,
min_x = 0,
max_x = 1,
min_y = f(min_x),
max_y = f(max_x)
)
Arguments
f |
(function) the function to be inverted; must be continuous and increasing |
y |
(scalar, double) the f(x)=y value in which to evaluate the inverse |
min_x |
(scalar, double) the min of the domain of f() |
max_x |
(scalar, double) the max of the domain of f() |
min_y |
(scalar, double) the min in the range of f() |
max_y |
(scalar, double) the max in the range of f() |
Value
(scalar, double) vector of x=f^(-1)(y): the inverted value
Examples
inverse_with_uniroot(f = function(x) {
2 * x
}, y = 0.5)
Numerically evaluate the inverse of a monotonically increasing continuous function from R to R at specific points.
Description
Numerically evaluate the inverse of a monotonically increasing continuous function from R to R at specific points.
Usage
inverse_with_uniroot_sorted(
f,
y,
range_x = c(0, 10),
range_y = c(f(range_x[1]), f(range_x[2]))
)
Arguments
f |
(function) the function to be inverted; must be continuous and increasing |
y |
(vector, double) the f(x)=y values in which to evaluate the inverse; must be in ascending order |
range_x |
(vector, double) the min and max of the domain of f() |
range_y |
(vector, double) the min and max in the range of f() |
Value
(vector, double) vector of x=f^(-1)(y): the inverted values
Examples
inverse_with_uniroot_sorted(f = function(x) {
2 * x
}, y = c(0, 0.5))
Helper function for the vectorized versions of sampling functions.
Takes the usual ways that lambda_mat and Lambda_mat are specified
and returns Lambda_mat.
Description
Helper function for the vectorized versions of sampling functions.
Takes the usual ways that lambda_mat and Lambda_mat are specified
and returns Lambda_mat.
Usage
make_cumulative_Lambda_matrix(
Lambda_mat = NULL,
lambda_mat = NULL,
interval_duration = NULL
)
Arguments
Lambda_mat |
a matrix of cumulative intensities or missing |
lambda_mat |
a matrix of intensities or missing |
interval_duration |
a vector with the same number of elements as the rows of |
Value
A matrix (r x 2), row-expanded if needed
Helper function for the vectorized versions of sampling functions.
Takes the usual ways that lambda_mat and Lambda_mat are specified
and returns lambda_mat.
Description
Helper function for the vectorized versions of sampling functions.
Takes the usual ways that lambda_mat and Lambda_mat are specified
and returns lambda_mat.
Usage
make_lambda_matrix(
lambda_mat = NULL,
Lambda_mat = NULL,
interval_duration = NULL
)
Arguments
lambda_mat |
a matrix of intensities or missing |
Lambda_mat |
a matrix of cumulative intensities or missing |
interval_duration |
a vector with the same number of elements as the rows of |
Value
A matrix (r x 2), row-expanded if needed
Helper function for the vectorized versions of sampling functions.
Takes the usual ways that range_t is specified
(a 2-vector, a 1 x 2 or an r x 2 matrix) and
returns a r x 2 matrix.
Description
Helper function for the vectorized versions of sampling functions.
Takes the usual ways that range_t is specified
(a 2-vector, a 1 x 2 or an r x 2 matrix) and
returns a r x 2 matrix.
Usage
make_range_t_matrix(range_t, n_rows)
Arguments
range_t |
a 2-vector, a 1 x 2 or an r x 2 matrix |
n_rows |
the number of rows in the fully expanded matrix ( |
Value
A matrix (r x 2), row-expanded if needed
Return matrix with column-wise cumulative sum No checks for arguments is done.
Description
Return matrix with column-wise cumulative sum No checks for arguments is done.
Usage
mat_cumsum_columns(X)
Arguments
X |
(matrix) |
Value
matrix
Return matrix with column-wise cumulative sum
replacing cells larger than ceil with NA.
No checks for arguments is done.
Description
Return matrix with column-wise cumulative sum
replacing cells larger than ceil with NA.
No checks for arguments is done.
Usage
mat_cumsum_columns_with_scalar_ceiling(X, ceil = Inf)
Arguments
X |
(matrix) |
ceil |
(double or Inf) the ceiling to be applied |
Value
matrix
Return matrix with column-wise cumulative sum
replacing cells larger than ceil with NA.
No checks for arguments is done.
Description
Return matrix with column-wise cumulative sum
replacing cells larger than ceil with NA.
No checks for arguments is done.
Usage
mat_cumsum_columns_with_vector_ceiling(X, ceil = Inf)
Arguments
X |
(matrix) |
ceil |
(vector or Inf) the set of ceilings to be applied, per row of |
Value
matrix
Return matrix with column-wise differencing. No checks for arguments is done.
Description
Return matrix with column-wise differencing. No checks for arguments is done.
Usage
mat_diff_columns(X)
Arguments
X |
(matrix) |
Value
matrix
Usage: matrix_cumsum_columns( X )
Description
Usage: matrix_cumsum_columns( X )
Usage
matrix_cumsum_columns(X)
Usage: matrix_cumsum_columns_inplace( X )
Description
Usage: matrix_cumsum_columns_inplace( X )
Usage
matrix_cumsum_columns_inplace(X)
Usage: matrix_diff_columns( X )
Description
Usage: matrix_diff_columns( X )
Usage
matrix_diff_columns(X)
Usage: matrix_diff_columns_inplace( X )
Description
Usage: matrix_diff_columns_inplace( X )
Usage
matrix_diff_columns_inplace(X)
Simulate a homogeneous Poisson Point Process in (t_min, t_max]
Description
Simulate a homogeneous Poisson Point Process in (t_min, t_max]
Usage
ppp(
rate,
t_min,
t_max,
atmost1 = FALSE,
tol = 10^-6,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL
)
Arguments
rate |
(scalar, double) constant instantaneous rate |
t_min |
(scalar, double) the lower bound of the time interval |
t_max |
(scalar, double) the upper bound of the time interval |
atmost1 |
boolean, report at most 1 event time (alias for
|
tol |
the probability that we will have more than the drawn events in (t_min, t_max] |
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
Value
a vector of event times t if no events realize, it will have 0 length
Examples
x <- ppp(rate = 1, t_min = 0, t_max = 10, tol = 10^-6)
Simulate a homogeneous Poisson Point Process over (t_min, t_max] (order statistics method)
Description
Internal function – not to be exported.
Same as ppp but uses the Order Statistics algorithm.
Usage
ppp2(rate, t_min, t_max, atmost1 = FALSE)
Arguments
rate |
(scalar, double) constant instantaneous rate |
t_min |
(scalar, double) the lower bound of the time interval |
t_max |
(scalar, double) the upper bound of the time interval |
atmost1 |
boolean, draw at most 1 event time |
Value
a vector of event times t if no events realize, it will have 0 length
Examples
x <- ppp(rate = 1, t_min = 0, t_max = 10, tol = 10^-6)
Simulate exactly n points from a homogeneous Poisson Point Process over (t_min, t_max]
Description
Simulate exactly n points from a homogeneous Poisson Point Process over (t_min, t_max]
Usage
ppp_exactly_n(n, t_min, t_max)
Arguments
n |
(int) the number of points to be simulated |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
Value
a vector of event times of size n
Examples
x <- ppp_exactly_n(n = 10, t_min = 0, t_max = 10)
Simulate specific number of points from a homogeneous Poisson Point Process over (t_min, t_max]
Description
Usage
ppp_n(size, range_t = c(0, 10), rng_stream = NULL)
Arguments
size |
(int) the number of points to be simulated |
range_t |
(vector, double) min and max of the time interval |
rng_stream |
an |
Value
a vector of event times of size size
Examples
x <- ppp_n(size = 10, range_t = c(0, 10))
Simulate n events from a homogeneous Poisson Point Process.
Description
Simulate n events from a homogeneous Poisson Point Process.
Usage
ppp_next_n(n = 1, rate = 1, t_min = 0, rng_stream = deprecated())
Arguments
n |
scalar number of samples |
rate |
scalar instantaneous rate |
t_min |
scalar for the starting time value |
rng_stream |
Value
a vector with event times t (starting from t_min)
Examples
x <- ppp_next_n(n = 10, rate = 1, t_min = 0)
Simulate a homogeneous Poisson Point Process over (t_min, t_max] (order statistics method)
Description
Usage
ppp_orderstat(range_t = c(0, 10), rate = 1, rng_stream = NULL, atmost1 = FALSE)
Arguments
range_t |
(vector, double) min and max of the time interval |
rate |
(scalar, double) constant instantaneous rate |
rng_stream |
an |
atmost1 |
boolean, draw at most 1 event time |
Value
a vector of event times t if no events realize, it will have 0 length
Examples
x <- ppp_orderstat(range_t = c(0, 10), rate = 1)
Simulate a homogeneous Poisson Point Process over (t_min, t_max]
Description
Usage
ppp_sequential(
range_t = c(0, 10),
rate = 1,
tol = 10^-6,
rng_stream = NULL,
atmost1 = FALSE
)
Arguments
range_t |
(vector, double) min and max of the time interval |
rate |
(scalar, double) constant instantaneous rate |
tol |
the probability that we will have more than the drawn events in (t_min, t_max] |
rng_stream |
an |
atmost1 |
boolean, draw at most 1 event time |
Value
a vector of event times t if no events realize, it will have 0 length
Examples
x <- ppp_sequential(range_t = c(0, 10), rate = 1, tol = 10^-6)
Truncated Poisson random samples (basic R)
Description
Sample from a Poisson distribution conditional on the count
being in [k_min, k_max], by inversion of the CDF restricted to the
truncation region (upper-tail parameterization, accurate when the region
is deep in the right tail). k_min = 1, k_max = Inf is the zero-truncated
distribution (rztpois()).
Usage
rbtpois(n, lambda, k_min = 1, k_max = Inf)
Arguments
n |
Integer, number of samples |
lambda |
Positive number (scalar or vector), the mean of the original (untruncated) Poisson distribution |
k_min |
Non-negative integer, the minimum count conditioned on |
k_max |
Positive integer or |
Value
a vector of counts (all in [k_min, k_max]) of size n
Examples
rbtpois(10, 1, k_min = 3)
rbtpois(10, 1, k_min = 0, k_max = 2)
Read code from text file as string
Description
Read code from text file as string
Usage
read_code(codeFile)
Arguments
codeFile |
Path to file |
Value
codeFile contents as a character string
Truncated Poisson random samples from rstream objects
Description
Sample from rstream objects a Poisson count conditional on
being in [k_min, k_max] (see rbtpois()).
Usage
rng_stream_rbtpois(
size = 1,
lambda = 1,
k_min = 1,
k_max = Inf,
rng_stream = NULL
)
Arguments
size |
Integer, number of samples |
lambda |
Positive number, the mean of the original (untruncated) Poisson distribution |
k_min |
Non-negative integer, the minimum count conditioned on |
k_max |
Positive integer or |
rng_stream |
( |
Value
a vector of counts (all in [k_min, k_max]) of size size
Examples
rng_stream_rbtpois(10, lambda = 1, k_min = 2)
Exponential random samples from rstream objects
Description
Sample from rstream objects
Usage
rng_stream_rexp(size = 1, rate = 1, rng_stream = NULL)
Arguments
size |
Integer, number of samples |
rate |
Positive number, the rate (i.e., 1/mean) |
rng_stream |
( |
Value
a vector of exponential variates of size size
Examples
rng_stream_rexp(10)
Poisson random samples from rstream objects
Description
Sample from rstream objects
Usage
rng_stream_rpois(size = 1, lambda = 1, rng_stream = NULL)
Arguments
size |
Integer, number of samples |
lambda |
Positive number, the mean |
rng_stream |
( |
Value
a vector of counts of size size
Examples
rng_stream_rpois(10)
Uniform random samples from rstream objects
Description
Sample from rstream objects
Usage
rng_stream_runif(size = 1, minimum = 0, maximum = 1, rng_stream = NULL)
Arguments
size |
Integer, number of samples |
minimum |
Lower bound |
maximum |
Upper bound |
rng_stream |
( |
Value
a vector of uniform variates of size size
Examples
rng_stream_runif(10)
Zero-truncated Poisson random samples from rstream objects
Description
Sample from rstream objects
Usage
rng_stream_rztpois(size = 1, lambda = 1, rng_stream = NULL)
Arguments
size |
Integer, number of samples |
lambda |
Positive number, the mean of the original (untruncated) Poisson distribution |
rng_stream |
( |
Value
a vector of non zero counts of size size
Examples
rng_stream_rztpois(10)
Zero-truncated Poisson random samples (basic R)
Description
Sample zero-truncated Poisson random samples (basic R)
Usage
rztpois(n, lambda)
Arguments
n |
Integer, number of samples |
lambda |
Positive number, the mean of the original (untruncated) Poisson distribution |
Value
a vector of non zero counts of size n
Examples
rztpois(10, 1)
rztpois(10, 1:10)
Simpson's method to integrate a univariate function.
Description
Simpson's method to integrate a univariate continuous function.
Faster that R's integrate() and precise enough, but does not do any checks.
The error is at most M (b-a)^5/(180 n^4) where M is the maximum of
the fourth derivative of the integrand in the interval [a, b].
Usage
simpson_num_integr(f, a, b, n)
Arguments
f |
function that takes a single argument |
a |
the lower limit of integration |
b |
the upper limit of integration |
n |
integer, number of integration points with a and b |
Value
numeric, the integration value examples #expect 1 simpson_num_integr(sin, 0, pi/2, 100) #max error for simpson_num_integr(sin, 0, pi/2, 100) is 5.312842e-10 1 * (pi/2 - 0)^5/(180 * 100^4)
Long event format
Description
Internal helpers for the long ("output = "long"") event
representation: list(id, time, n_draws) with one entry per event.
id is the 1-based point-process index, ascending; time is ascending
within id. A point process with zero events contributes no entries (its
id is absent); n_draws distinguishes "no events" from "not sampled".
No NA appears in long output.
Vectorized generic function for simulating from NHPPPs given the intensity function or the cumulative intensity function
Description
This is a wrapper to the package's specific functions, and thus slightly slower. For time-intensive simulations prefer one of the specific functions.
Usage
vdraw(
lambda = NULL,
lambda_args = NULL,
Lambda_maj_matrix = NULL,
lambda_maj_matrix = NULL,
Lambda = NULL,
Lambda_inv = NULL,
Lambda_args = NULL,
Lambda_inv_args = NULL,
t_min = NULL,
t_max = NULL,
rate_matrix_t_min = NULL,
rate_matrix_t_max = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL,
budget_cap = NULL,
atmostB = NULL,
output = c("matrix", "long")
)
Arguments
lambda |
(function) intensity function, vectorized |
lambda_args |
(list) arguments for |
Lambda_maj_matrix |
(matrix) integrated intensity rates at the end of each interval |
lambda_maj_matrix |
(matrix) intensity rates, one per interval |
Lambda |
(function, double vector) an increasing function which is the integrated rate of the NHPPP. It should take a vectorized argument t for times and an optional arguments list. |
Lambda_inv |
(function, double vector) the inverse of |
Lambda_args |
(list) arguments for BOTH |
Lambda_inv_args |
(list) deprecated; pass one structured |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
t_max |
(scalar | vector | column matrix) is the upper bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
rate_matrix_t_min |
(scalar | vector | column matrix) is the lower bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
rate_matrix_t_max |
(scalar | vector | column matrix) the upper bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
budget_cap |
|
atmostB |
deprecated alias for |
output |
(string) |
Value
a vector of event times
Examples
# thinning (lambda and a majorizer matrix)
x <- vdraw(
lambda = function(t, ...) 1 + sin(t),
lambda_maj_matrix = matrix(rep(2, 50), nrow = 10),
rate_matrix_t_min = 0,
rate_matrix_t_max = 5
)
# inversion (Lambda and its inverse), conditioned on at least one event
x <- vdraw(
Lambda = function(t) 2 * t,
Lambda_inv = function(z) z / 2,
t_min = 0, t_max = rep(5, 10),
atleast1 = TRUE
)
Vectorized simulation from a non homogeneous Poisson Point Process (NHPPP) from (t_min, t_max) given the cumulative intensity function and its inverse
Description
Sample NHPPP times using the cumulative intensity function and its inverse.
Usage
vdraw_cumulative_intensity(
Lambda,
Lambda_inv,
t_min,
t_max,
Lambda_args = NULL,
Lambda_inv_args = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL,
output = c("matrix", "long")
)
Arguments
Lambda |
(function, double vector) an increasing function which is the integrated rate of the NHPPP. It should take a vectorized argument t for times and an optional arguments list. |
Lambda_inv |
(function, double vector) the inverse of |
t_min |
(scalar | vector | column matrix) the lower bound of the interval for each sampled point process The length of this argument is the number of point processes that should be drawn. |
t_max |
(scalar | vector | column matrix) the upper bound of the interval for each sampled point process The length of this argument is the number of point processes that should be drawn. |
Lambda_args |
(list) arguments for BOTH |
Lambda_inv_args |
(list) deprecated; pass one structured |
tol |
the tolerange for the calulations. |
atmost1 |
boolean, report at most 1 event time per sampled point
process (alias for |
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
output |
(string) |
Value
a matrix of event times with one row per sampled point process,
or the long event format if output = "long".
Examples
Z <- vdraw_cumulative_intensity(
Lambda = function(t) t^1.5,
Lambda_inv = function(z) z^(1 / 1.5),
t_min = 0,
t_max = rep(2, 10)
)
# arguments in the structured container; conditioned on exactly two events
Z <- vdraw_cumulative_intensity(
Lambda = function(t, a) t^a$shared$p,
Lambda_inv = function(z, a) z^(1 / a$shared$p),
t_min = 0,
t_max = rep(2, 10),
Lambda_args = list(shared = list(p = 1.5)),
generate_at_least_K = 2, generate_at_most_K = 2
)
Vectorized sampling from a non homogeneous Poisson Point Process (NHPPP) from an interval (thinning method) with piecewise constant_majorizers (C++)
Description
Vectorized sampling from a non homogeneous Poisson Point Process (NHPPP) from an interval (thinning method) with piecewise constant_majorizers. The majorizers are step functions over equal-length time intevals.
Usage
vdraw_intensity(
lambda = NULL,
lambda_args = NULL,
Lambda_maj_matrix = NULL,
lambda_maj_matrix = NULL,
rate_matrix_t_min = NULL,
rate_matrix_t_max = NULL,
t_min = NULL,
t_max = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL,
budget_cap = NULL,
atmostB = NULL
)
Arguments
lambda |
(function) intensity function, vectorized |
lambda_args |
(list) arguments for |
Lambda_maj_matrix |
(matrix) integrated intensity rates at the end of each interval |
lambda_maj_matrix |
(matrix) intensity rates, one per interval |
rate_matrix_t_min |
(scalar | vector | column matrix) is the lower bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
rate_matrix_t_max |
(scalar | vector | column matrix) the upper bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
t_max |
(scalar | vector | column matrix) is the upper bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 accepted event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
budget_cap |
|
atmostB |
deprecated alias for |
Value
a matrix of event times (columns) per draw (rows) NAs are structural empty spots
Examples
x <- vdraw_intensity(
lambda = function(x, ...) 0.1 * x,
lambda_maj_matrix = matrix(rep(1, 5), nrow = 1),
rate_matrix_t_min = 1,
rate_matrix_t_max = 5
)
# shared and per-row lambda arguments in the structured container,
# conditioned on at least one event
l <- function(t, a) a$shared$scale * t^a$row_args$exponent
x <- vdraw_intensity(
lambda = l,
lambda_args = list(
shared = list(scale = 0.1),
row_args = data.frame(exponent = seq(1, 1.9, by = 0.1))
),
lambda_maj_matrix = matrix(rep(3, 50), nrow = 10),
rate_matrix_t_min = 1,
rate_matrix_t_max = 5,
generate_at_least_K = 1
)
Vectorized sampling from NHPPPs given the intensity function, with piecewise constant majorizers over arbitrary interval bounds (C++)
Description
Vectorized thinning sampler: candidate times are proposed from a piecewise
constant majorizer and accepted with probability
lambda(t) / lambda_maj(interval of t). Unlike the sc_step samplers,
lambda is an arbitrary (vectorized) R function — the step structure only
concerns the majorizer. The majorizer intervals need not have the same
length: their bounds are given in time_breaks, either once for all point
processes or per point process. This generalizes
vdraw_intensity(), which assumes equal-length ("regular") intervals.
Usage
vdraw_intensity_step(
lambda = NULL,
lambda_args = NULL,
Lambda_maj_matrix = NULL,
lambda_maj_matrix = NULL,
time_breaks = NULL,
t_min = NULL,
t_max = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL,
budget_cap = NULL
)
Arguments
lambda |
(function) intensity function, vectorized |
lambda_args |
(list) arguments for |
Lambda_maj_matrix |
(matrix) integrated majorizer intensity rates at the end of each interval |
lambda_maj_matrix |
(matrix) majorizer intensity rates, one per interval |
time_breaks |
(vector | matrix) the bounds of the majorizer intervals.
With |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of |
t_max |
(scalar | vector | column matrix) the upper bound
of a subinterval of |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 accepted event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
budget_cap |
|
Value
a matrix of event times (columns) per draw (rows); NAs are structural empty spots
Examples
x <- vdraw_intensity_step(
lambda = function(x, ...) 0.1 * x,
lambda_maj_matrix = matrix(rep(1, 5), nrow = 1),
time_breaks = c(1, 1.5, 3, 4, 4.5, 5)
)
# conditioned on exactly two events
x <- vdraw_intensity_step(
lambda = function(x, ...) 0.1 * x,
lambda_maj_matrix = matrix(rep(1, 50), nrow = 10),
time_breaks = c(1, 1.5, 3, 4, 4.5, 5),
generate_at_least_K = 2, generate_at_most_K = 2
)
Vectorized sampling from a non homogeneous Poisson Point Process (NHPPP) given the intensity function with piecewise constant_majorizers (C++)
Description
Vectorized sampling from a non homogeneous Poisson Point Process (NHPPP) using the intensity function and piecewise constant_majorizers. The majorizers are step functions over equal-length time intevals.
Usage
vdraw_intensity_step_regular_cpp(
lambda = NULL,
lambda_args = NULL,
Lambda_maj_matrix = NULL,
lambda_maj_matrix = NULL,
rate_matrix_t_min = NULL,
rate_matrix_t_max = NULL,
t_min = NULL,
t_max = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
generate_at_least_K = NULL,
budget_cap = NULL,
atmostB = NULL
)
Arguments
lambda |
(function) intensity function, vectorized |
lambda_args |
(list) arguments for |
Lambda_maj_matrix |
(matrix) integrated intensity rates at the end of each interval |
lambda_maj_matrix |
(matrix) intensity rates, one per interval |
rate_matrix_t_min |
(scalar | vector | column matrix) is the lower bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
rate_matrix_t_max |
(scalar | vector | column matrix) the upper bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
t_max |
(scalar | vector | column matrix) is the upper bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
generate_at_least_K |
|
budget_cap |
|
atmostB |
deprecated alias for |
Value
a matrix of event times (columns) per draw (rows) NAs are structural empty spots
Vectorized sampling from NHPPPs with piecewise constant intensities over arbitrary interval bounds (C++)
Description
Simulate piecewise constant-rate Poisson Point Processes (inversion method)
where the intervals need not have the same length. The interval bounds are
given in time_breaks, either once for all point processes or per point
process. This generalizes vdraw_sc_step_regular(), which assumes
equal-length ("regular") intervals.
Usage
vdraw_sc_step(
lambda_matrix = NULL,
Lambda_matrix = NULL,
time_breaks = NULL,
t_min = NULL,
t_max = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL,
budget_cap = NULL,
atmostB = NULL,
output = c("matrix", "long")
)
Arguments
lambda_matrix |
(matrix) intensity rates, one per interval |
Lambda_matrix |
(matrix) integrated intensity rates at the end of each interval |
time_breaks |
(vector | matrix) the bounds of the intervals over which
the rates apply. With |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of |
t_max |
(scalar | vector | column matrix) the upper bound
of a subinterval of |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
budget_cap |
|
atmostB |
deprecated alias for |
output |
(string) |
Value
a matrix of event times t, with rows corresponding to the sampled
point processes, or the long event format if output = "long".
Examples
# one set of interval bounds for all point processes
x <- vdraw_sc_step(
lambda_matrix = matrix(rep(1, 50), nrow = 10),
time_breaks = c(100, 100.5, 102, 106, 109, 110)
)
# separate interval bounds per point process
x <- vdraw_sc_step(
lambda_matrix = matrix(rep(1, 50), nrow = 10),
time_breaks = matrix(rep(c(100, 100.5, 102, 106, 109, 110), each = 10), nrow = 10) + 0:9
)
# condition on 2 to 4 events and report only the earliest two
x <- vdraw_sc_step(
lambda_matrix = matrix(rep(1, 50), nrow = 10),
time_breaks = c(100, 100.5, 102, 106, 109, 110),
generate_at_least_K = 2, generate_at_most_K = 4,
report_first_K = 2
)
Vectorized sampling from NHPPPs with piecewise constant intensities with same interval lengths
Description
Simulate a piecewise constant-rate Poisson Point Process over (t_min, t_max] (inversion method)
where the intervals have the same length (are "regular").
Usage
vdraw_sc_step_regular(
lambda_matrix = NULL,
Lambda_matrix = NULL,
rate_matrix_t_min = NULL,
rate_matrix_t_max = NULL,
t_min = NULL,
t_max = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
atleast1 = FALSE,
generate_at_least_K = NULL,
generate_at_most_K = NULL,
budget_cap = NULL,
atmostB = NULL,
output = c("matrix", "long")
)
Arguments
lambda_matrix |
(matrix) intensity rates, one per interval |
Lambda_matrix |
(matrix) integrated intensity rates at the end of each interval |
rate_matrix_t_min |
(scalar | vector | column matrix) is the lower bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
rate_matrix_t_max |
(scalar | vector | column matrix) the upper bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
t_max |
(scalar | vector | column matrix) is the upper bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
atleast1 |
boolean, condition on at least 1 event (alias for
|
generate_at_least_K |
|
generate_at_most_K |
|
budget_cap |
|
atmostB |
deprecated alias for |
output |
(string) |
Value
a matrix of event times t, with rows corresponding to the sampled
point processes, or the long event format if output = "long"
if no events realize, it will have 0 length
Examples
x <- vdraw_sc_step_regular(
Lambda_matrix = matrix(1:5, nrow = 1),
rate_matrix_t_min = 100,
rate_matrix_t_max = 110
)
Vectorized sampling from NHPPPs with piecewise constant intensities with same interval lengths (C++)
Description
Simulate a piecewise constant-rate Poisson Point Process over (t_min, t_max] (inversion method)
where the intervals have the same length (are "regular").
Usage
vdraw_sc_step_regular_cpp(
lambda_matrix = NULL,
Lambda_matrix = NULL,
rate_matrix_t_min = NULL,
rate_matrix_t_max = NULL,
t_min = NULL,
t_max = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
budget_cap = NULL,
atmostB = NULL,
output = c("matrix", "long")
)
Arguments
lambda_matrix |
(matrix) intensity rates, one per interval |
Lambda_matrix |
(matrix) integrated intensity rates at the end of each interval |
rate_matrix_t_min |
(scalar | vector | column matrix) is the lower bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
rate_matrix_t_max |
(scalar | vector | column matrix) the upper bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
t_max |
(scalar | vector | column matrix) is the upper bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
budget_cap |
|
atmostB |
deprecated alias for |
output |
(string) |
Value
a matrix of event times t, with rows corresponding to the sampled
point processes, or the long event format if output = "long".
Examples
x <- vdraw_sc_step_regular_cpp(
Lambda_matrix = matrix(1:5, nrow = 1),
rate_matrix_t_min = 100,
rate_matrix_t_max = 110
)
Vectorized sampling from a zero-truncated non homogeneous Poisson Point Process (NHPPP) from an interval (thinning method) with piecewise constant_majorizers
Description
Vectorized sampling from a zero-truncated non homogeneous Poisson Point Process (NHPPP) from an interval (thinning method) with piecewise constant_majorizers. The majorizers are step functions over equal-length time intevals.
Usage
vztdraw_intensity(
lambda = NULL,
lambda_args = NULL,
Lambda_maj_matrix = NULL,
lambda_maj_matrix = NULL,
range_t = NULL,
tol = 10^-6,
atmost1 = FALSE,
...
)
Arguments
lambda |
(function) a vectorized intensity function, with one or two arguments. The first is time. The optional second is a named list with additional arguments. |
lambda_args |
(list) arguments for |
Lambda_maj_matrix |
(matrix) for the majorizeintegrated intensity rates at the end of each interval |
lambda_maj_matrix |
(matrix) intensity rates, one per interval |
range_t |
(vector, or matrix) |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, draw at most 1 event time |
... |
(any) other arguments (ignored – used for flexibility in calling from other functions) |
Value
a matrix of event times (columns) per draw (rows) NAs are structural empty spots
Vectorized sampling from a K-truncated NHPPP given the intensity function, with piecewise constant majorizers over arbitrary interval bounds (R)
Description
Thinning sampler conditional on the accepted event count lying in
[generate_at_least_K, generate_at_most_K] (generate_at_least_K = 1
alone is the zero-truncated process), with majorizer intervals of
arbitrary length (time_breaks, as in vdraw_sc_step()).
Conditioning is by rejection: candidate realizations are proposed from the
majorizer conditioned on at least K1 majorizer events (only the lower
bound may be pushed into the proposal — at least K1 accepted events
implies at least K1 majorizer events, whereas an upper bound on the
majorizer count would over-restrict and bias the accepted law), thinned
against lambda, and rows whose surviving count falls outside [K1, K2]
are resampled until the condition holds. The per-round acceptance
probability degrades in the strictness of the bounds and in the looseness
of the majorizer, so a tight majorizer matters much more here than in the
unconditional sampler. There is no iteration cap.
Special case K1 = K2 = K (exactly K events): only under-counts are
rejected; rows with more than K survivors are salvaged by keeping a
uniformly random size-K subset of the events. This is exact — given the
count, event times are conditionally iid, so the subset is an exact draw
from the exactly-K law for every surviving count alike — and avoids the
near-zero acceptance probability of two-sided rejection when the target
integrated intensity is large relative to K.
Usage
vztdraw_intensity_step(
lambda = NULL,
lambda_args = NULL,
Lambda_maj_matrix = NULL,
lambda_maj_matrix = NULL,
time_breaks = NULL,
t_min = NULL,
t_max = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
generate_at_least_K = 1,
generate_at_most_K = NULL,
budget_cap = NULL
)
Arguments
lambda |
(function) intensity function, vectorized |
lambda_args |
(list) arguments for |
Lambda_maj_matrix |
(matrix) integrated majorizer intensity rates at the end of each interval |
lambda_maj_matrix |
(matrix) majorizer intensity rates, one per interval |
time_breaks |
(vector | matrix) the bounds of the majorizer intervals.
With |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of |
t_max |
(scalar | vector | column matrix) the upper bound
of a subinterval of |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, report at most 1 event time (alias for
|
report_first_K |
|
report_last_K |
|
generate_at_least_K |
non-negative integer: condition on at least K accepted events. The default 1 is the zero-truncated process. |
generate_at_most_K |
|
budget_cap |
|
Vectorized sampling from a K-truncated non homogeneous Poisson Point Process (NHPPP) from an interval (thinning method) with piecewise constant majorizers (R)
Description
Vectorized thinning sampler conditional on the accepted event count lying
in [generate_at_least_K, generate_at_most_K] (generate_at_least_K = 1
alone, the default, is the zero-truncated process).
The majorizers are step functions over equal-length time intervals.
Conditioning is by rejection: candidate realizations are proposed from the
majorizer conditioned on at least K1 majorizer events (only the lower
bound may be pushed into the proposal — at least K1 accepted events
implies at least K1 majorizer events, whereas an upper bound on the
majorizer count would over-restrict and bias the accepted law), thinned
against lambda, and rows whose surviving count falls outside
[K1, K2] are resampled until the condition holds. The per-round
acceptance probability degrades in the strictness of the bounds and in
the looseness of the majorizer, so a tight majorizer matters much more
here than in the unconditional sampler. There is no iteration cap.
Special case K1 = K2 = K (exactly K events): only under-counts are
rejected; rows with more than K survivors are salvaged by keeping a
uniformly random size-K subset of the events. This is exact — given the
count, event times are conditionally iid, so the subset is an exact draw
from the exactly-K law for every surviving count alike — and avoids the
near-zero acceptance probability of two-sided rejection when the target
integrated intensity is large relative to K.
Usage
vztdraw_intensity_step_regular(
lambda = NULL,
lambda_args = NULL,
Lambda_maj_matrix = NULL,
lambda_maj_matrix = NULL,
rate_matrix_t_min = NULL,
rate_matrix_t_max = NULL,
t_min = NULL,
t_max = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
generate_at_least_K = 1,
generate_at_most_K = NULL,
...
)
Arguments
lambda |
(function) intensity function, vectorized |
lambda_args |
(list) arguments for |
Lambda_maj_matrix |
(matrix) integrated intensity rates at the end of each interval |
lambda_maj_matrix |
(matrix) intensity rates, one per interval |
rate_matrix_t_min |
(scalar | vector | column matrix) is the lower bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
rate_matrix_t_max |
(scalar | vector | column matrix) the upper bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
t_max |
(scalar | vector | column matrix) is the upper bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, report at most 1 event time of the conditioned
process (alias for |
report_first_K |
|
report_last_K |
|
generate_at_least_K |
non-negative integer: condition on at least K accepted events. The default 1 is the zero-truncated process. |
generate_at_most_K |
|
... |
absorbed (for wrapper compatibility) |
Vectorized sampling from zero-truncated NHPPPs with piecewise constant intensities over arbitrary interval bounds (C++)
Description
Simulate piecewise constant-rate Poisson Point Processes conditional on
observing at least one event, where the intervals need not have the same
length. The interval bounds are given in time_breaks, either once for all
point processes or per point process. This generalizes the zero-truncated
regular-grid sampler used by vdraw_sc_step_regular(atleast1 = TRUE).
Usage
vztdraw_sc_step(
lambda_matrix = NULL,
Lambda_matrix = NULL,
time_breaks = NULL,
t_min = NULL,
t_max = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
generate_at_least_K = 1,
generate_at_most_K = NULL,
budget_cap = NULL,
output = c("matrix", "long")
)
Arguments
lambda_matrix |
(matrix) intensity rates, one per interval |
Lambda_matrix |
(matrix) integrated intensity rates at the end of each interval |
time_breaks |
(vector | matrix) the bounds of the intervals over which
the rates apply. With |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of |
t_max |
(scalar | vector | column matrix) the upper bound
of a subinterval of |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, report at most 1 event time of the conditioned
process (alias for |
report_first_K |
|
report_last_K |
|
generate_at_least_K |
non-negative integer: condition on at least K events in the sampled (sub)interval. The default 1 is the zero-truncated process. |
generate_at_most_K |
|
budget_cap |
|
output |
(string) |
Value
a matrix of event times t, with rows corresponding to the sampled
point processes, or the long event format if output = "long".
Examples
x <- vztdraw_sc_step(
lambda_matrix = matrix(rep(1, 50), nrow = 10),
time_breaks = c(100, 100.5, 102, 106, 109, 110)
)
# equivalently, via the general conditioning option
x <- vdraw_sc_step(
lambda_matrix = matrix(rep(1, 50), nrow = 10),
time_breaks = c(100, 100.5, 102, 106, 109, 110),
generate_at_least_K = 1
)
Vectorized sampling from zero-truncated NHPPPs with piecewise constant intensities with same interval lengths
Description
Simulate a piecewise constant-rate Poisson Point Process over (t_min, t_max] (inversion method)
where the intervals have the same length (are "regular"), conditional on
the event count lying in [generate_at_least_K, generate_at_most_K]
(generate_at_least_K = 1 alone, the default, is the zero-truncated
process).
Usage
vztdraw_sc_step_regular_cpp(
lambda_matrix = NULL,
Lambda_matrix = NULL,
rate_matrix_t_min = NULL,
rate_matrix_t_max = NULL,
t_min = NULL,
t_max = NULL,
tol = 10^-6,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
generate_at_least_K = 1,
generate_at_most_K = NULL,
budget_cap = NULL,
output = c("matrix", "long")
)
Arguments
lambda_matrix |
(matrix) intensity rates, one per interval |
Lambda_matrix |
(matrix) integrated intensity rates at the end of each interval |
rate_matrix_t_min |
(scalar | vector | column matrix) is the lower bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
rate_matrix_t_max |
(scalar | vector | column matrix) the upper bound of the time interval for each row of (Lambda|lambda)_maj_matrix. The length of this argument is the number of point processes that should be drawn. |
t_min |
(scalar | vector | column matrix) is the lower bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
t_max |
(scalar | vector | column matrix) is the upper bound
of a subinterval of (rate_matrix_t_min, rate_matrix_t_max]. If set,
times are sampled from the subinterval.
If omitted, it is equivalent to |
tol |
(scalar, double) tolerance for the number of events |
atmost1 |
boolean, report at most 1 event time of the conditioned
process (alias for |
report_first_K |
|
report_last_K |
|
generate_at_least_K |
non-negative integer: condition on at least K events in the sampled (sub)interval. The default 1 is the zero-truncated process. |
generate_at_most_K |
|
budget_cap |
|
output |
(string) |
Value
a matrix of event times t, with rows corresponding to the sampled
point processes, or the long event format if output = "long".
Simulate from a zero-truncated non homogeneous Poisson Point Process (zt-NHPPP) from (t_min, t_max) (order statistics method)
Description
Sample zero-truncated NHPPP times using the order statistics method,
optionally using an rstream generator
Usage
ztdraw_cumulative_intensity(
Lambda,
Lambda_inv,
t_min,
t_max,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
generate_at_least_K = 1,
generate_at_most_K = NULL
)
Arguments
Lambda |
(function, double vector) a continuous increasing R to R map which is the integrated rate of the NHPPP |
Lambda_inv |
(function, double vector) the inverse of |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
atmost1 |
(boolean) report at most 1 event time of the conditioned
process (alias for |
report_first_K |
|
report_last_K |
|
generate_at_least_K |
non-negative integer: condition on at least K events in the interval. The default 1 is the zero-truncated process. |
generate_at_most_K |
|
Value
a vector of event times of the conditioned process
Generic function for simulating from zero-truncated NHPPPs given the intensity function.
Description
Sample from zero-truncated NHPPP given the intensity function This is a wrapper to the package's specific functions, and thus somewhat slower. For time-intensive simulations prefer one of the specific functions.
Usage
ztdraw_intensity(
lambda,
line_majorizer_intercept = NULL,
line_majorizer_slope = NULL,
line_majorizer_is_loglinear = FALSE,
step_majorizer_vector = NULL,
t_min = NULL,
t_max = NULL,
atmost1 = FALSE
)
Arguments
lambda |
(function) the instantaneous rate |
line_majorizer_intercept |
The intercept |
line_majorizer_slope |
The slope |
line_majorizer_is_loglinear |
(boolean) if |
step_majorizer_vector |
(vector, double) |
t_min |
(double) the lower bound of the interval |
t_max |
(double) the upper bound of the interval |
atmost1 |
boolean, draw at most 1 event time |
Value
a vector of at least 1 event times
Simulate size samples from a zero-truncated non homogeneous Poisson Point Process (zt-NHPPP) from
(t0, t_max) (thinning method)
Description
Sample zero-truncated NHPPP intensity times using the thinning method
Usage
ztdraw_intensity_line(
lambda,
majorizer_intercept,
majorizer_slope,
t_min,
t_max,
majorizer_is_loglinear = FALSE,
atmost1 = FALSE
)
Arguments
lambda |
(function) the instantaneous rate of the NHPPP. |
majorizer_intercept |
(double) the intercept ( |
majorizer_slope |
(double) the slope (‘beta’) of the loglinear majorizer function. |
t_min |
(double) the lower bound of the time interval. |
t_max |
(double) the upper bound of the time interval. |
majorizer_is_loglinear |
(boolean) if |
atmost1 |
boolean, draw at most 1 event time |
Value
a vector of at least 1 event times
Simulate from a zero-truncated non homogeneous Poisson Point Process (NHPPP) from (t0, t_max) (thinning method) with piecewise constant_majorizer
Description
Sample zero-truncated NHPPP times using the thinning method
Usage
ztdraw_intensity_step(lambda, majorizer_vector, time_breaks, atmost1 = FALSE)
Arguments
lambda |
(function) the instantaneous rate of the NHPPP. A continuous function of time. |
majorizer_vector |
(scalar, double) |
time_breaks |
(vector, double) |
atmost1 |
boolean, draw at most 1 event time |
Value
a vector of event times (t_) with at least one element
Simulate size samples from a zero-truncated non homogeneous Poisson Point Process (zt-NHPPP) from
(t_min, t_max) with linear intensity function
Description
Sample zero-truncated NHPPP times from a linear intensity function
using the inversion method, optionally using an rstream
generator
Usage
ztdraw_sc_linear(
intercept,
slope,
t_min,
t_max,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
generate_at_least_K = 1,
generate_at_most_K = NULL
)
Arguments
intercept |
(double) the intercept |
slope |
(double) the slope |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
atmost1 |
(boolean) report at most 1 event time of the conditioned
process (alias for |
report_first_K |
|
report_last_K |
|
generate_at_least_K |
non-negative integer: condition on at least K events in the interval. The default 1 is the zero-truncated process. |
generate_at_most_K |
|
Value
a vector of event times of the conditioned process
Examples
x <- ztdraw_sc_linear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
Simulate from a zero-truncated non homogeneous Poisson Point Process (zt-NHPPP) from (t_min, t_max) with a log-linear intensity function
Description
Sample zt-NHPPP times from an log-linear intensity function
Usage
ztdraw_sc_loglinear(
intercept,
slope,
t_min,
t_max,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
generate_at_least_K = 1,
generate_at_most_K = NULL
)
Arguments
intercept |
(double) the intercept in the exponent |
slope |
(double) the slope in the exponent |
t_min |
(double) the lower bound of the time interval |
t_max |
(double) the upper bound of the time interval |
atmost1 |
boolean, report at most 1 event time of the conditioned
process (alias for |
report_first_K |
|
report_last_K |
|
generate_at_least_K |
non-negative integer: condition on at least K events in the interval. The default 1 is the zero-truncated process. |
generate_at_most_K |
|
Value
a vector of event times of the conditioned process
Examples
x <- ztdraw_sc_loglinear(intercept = 0, slope = 0.2, t_min = 0, t_max = 10)
Simulate a count-conditioned homogeneous Poisson Point Process over (t_min, t_max]
Description
Simulate a constant-rate Poisson Point Process conditional on
the event count lying in [generate_at_least_K, generate_at_most_K]
(generate_at_least_K = 1 alone, the default, is the zero-truncated
process; generate_at_least_K = generate_at_most_K = K conditions on
exactly K events).
Usage
ztppp(
rate,
t_min,
t_max,
atmost1 = FALSE,
report_first_K = NULL,
report_last_K = NULL,
generate_at_least_K = 1,
generate_at_most_K = NULL
)
Arguments
rate |
(scalar, double) constant instantaneous rate |
t_min |
(scalar, double) lower bound of the time interval |
t_max |
(scalar, double) upper bound of the time interval |
atmost1 |
boolean, report at most 1 event time of the conditioned
process (alias for |
report_first_K |
|
report_last_K |
|
generate_at_least_K |
non-negative integer: condition on at least K
events in |
generate_at_most_K |
|
Value
a vector of event times
Examples
x <- ztppp(t_min = 0, t_max = 10, rate = 0.001)