sim_pcd: Simulate panel count data with a time-varying covariate

View source: R/simulate.R

sim_pcdR Documentation

Simulate panel count data with a time-varying covariate

Description

Generates data from the design used in the simulation study of Sun et al. (2024), which is a convenient source of examples and test cases.

Usage

sim_pcd(
  n,
  beta = c(1, -1),
  lambda = function(t) 8/(1 + t),
  tau = 2,
  frailty = 0,
  exam_mean = 4,
  lambda_max = NULL,
  digits = 2
)

Arguments

n

Number of subjects.

beta

Length two coefficient vector for x1 and x2.

lambda

Baseline rate function, vectorised over t.

tau

Maximum follow-up time.

frailty

Variance of a gamma frailty with mean one that multiplies each subject's rate. Zero, the default, gives a genuine Poisson process; a positive value produces overdispersed counts that violate the Poisson assumption while leaving the rate model intact.

exam_mean

Mean of the zero-truncated Poisson distribution from which the number of examinations per subject is drawn.

lambda_max

Optional upper bound for lambda on ⁠[0, tau]⁠, used by the thinning algorithm. The default takes the maximum over a fine grid, which is reliable unless lambda oscillates very rapidly.

digits

Number of decimal places to round examination times to, or NA to leave them unrounded. Rounding follows the design of the paper and of Wellner and Zhang (2007): examinations then tie across subjects, which is realistic for scheduled visits and keeps the pooled grid, and hence the cost of fitting, from growing quadratically in the sample size.

Details

The time-varying covariate is a single step, x_1(t) = X_{11} I(t \le U_1) + X_{12} I(t > U_1), with X_{11}, X_{12} \sim U(0, 1) and U_1 \sim U(0, \tau). The time-invariant covariate x2 is U(0, 1). Events follow a nonhomogeneous Poisson process with rate r \lambda(t) \exp(\beta' X(t)), where r is one unless frailty is positive. Examination times are the order statistics of a uniform sample on (0, \bar T) with \bar T \sim U(0.9\tau, \tau).

Value

A tibble in counting process form with columns id, tstart, tstop, count, x1 and x2. Rows are intervals over which the covariates are constant; count is the number of events since the previous examination and is NA on rows that only record a covariate change.

References

Sun, D., Guo, Y., Li, Y., Tu, W. and Sun, J. (2024). A robust approach for regression analysis of panel count data. Bernoulli 30(4), 3251–3275. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.3150/23-BEJ1713")}

Examples

set.seed(42)
d <- sim_pcd(5, beta = c(1, -1), lambda = function(t) 8 / (1 + t))
head(d)

# Overdispersed counts: the rate model still holds, the Poisson one does not.
od <- sim_pcd(5, frailty = 1)

pcdreg documentation built on Nov. 10, 2026, 5:09 p.m.