sim_marker: Simulate a Number of Observed Marker for an Individual

Description Usage Arguments See Also Examples

View source: R/sim.R

Description

Simulates from

\vec U_i \sim N^{(K)}(\vec 0, Ψ)

\vec Y_{ij} \mid \vec U_i = \vec u_i \sim N^{(r)}(\vec μ(s_{ij}, \vec u_i), Σ)

with

\vecμ(s, \vec u) = \vec o + ≤ft(I \otimes \vec g(s)^\top\right)vec(B) + ≤ft(I \otimes \vec m(s)^\top\right) \vec u.

The number of observations and the observations times, s_{ij}s, are determined from the passed generating functions.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
sim_marker(
  B,
  U,
  sigma_chol,
  r_n_marker,
  r_obs_time,
  m_func,
  g_func,
  offset,
  id = 1L
)

Arguments

B

coefficient matrix for time-varying fixed effects. Use NULL if there is no effect.

U

random effects matrix for time-varying random effects. Use NULL if there is no effects.

sigma_chol

Cholesky decomposition of the noise's covariance matrix.

r_n_marker

function to generate the number of observed markers. Takes an integer for the individual's id.

r_obs_time

function to generate the observations times given the number of observed markers. Takes an integer for the number of markers and an integer for the individual's id.

m_func

basis function for U like poly.

g_func

basis function for B like poly.

offset

numeric vector with non-time-varying fixed effects.

id

integer with id passed to r_n_marker and r_obs_time.

See Also

draw_U, eval_marker

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#####
# example with polynomial basis functions
g_func <- function(x){
  x <- x - 1
  cbind(x^3, x^2, x)
}
m_func <- function(x){
  x <- x - 1
  cbind(x^2, x, 1)
}

# parameters
gamma <- matrix(c(.25, .5, 0, -.4, 0, .3), 3, 2)
Psi <- structure(c(0.18, 0.05, -0.05, 0.1, -0.02, 0.06, 0.05, 0.34, -0.25,
                   -0.06, -0.03, 0.29, -0.05, -0.25, 0.24, 0.04, 0.04,
                   -0.12, 0.1, -0.06, 0.04, 0.34, 0, -0.04, -0.02, -0.03,
                   0.04, 0, 0.1, -0.08, 0.06, 0.29, -0.12, -0.04, -0.08,
                   0.51), .Dim = c(6L, 6L))
B <- structure(c(-0.57, 0.17, -0.48, 0.58, 1, 0.86), .Dim = 3:2)
sig <- diag(c(.6, .3)^2)

# generator functions
r_n_marker <- function(id){
  cat(sprintf("r_n_marker: passed id is %d\n", id))
  # the number of markers is Poisson distributed
  rpois(1, 10) + 1L
}
r_obs_time <- function(id, n_markes){
  cat(sprintf("r_obs_time: passed id is %d\n", id))
  # the observations times are uniform distributed
  sort(runif(n_markes, 0, 2))
}

# simulate marker
set.seed(1)
U <- draw_U(chol(Psi), NCOL(B))
sim_marker(B = B, U = U, sigma_chol = chol(sig), r_n_marker = r_n_marker,
           r_obs_time = r_obs_time, m_func = m_func, g_func = g_func,
           offset = NULL, id = 1L)

SimSurvNMarker documentation built on Jan. 8, 2021, 2:05 a.m.