Description Usage Arguments Examples
A simulation function simulating log normal frialties in dimension n >= 1. In particular one can simulate correlated frailties.
1 |
n |
number of frailties to be simulated. |
sigma |
covariance matrix. |
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | ############## Simulating correlated frailties
jump_types <- matrix(
c(NA,"exp", "exp",
"exp", NA, "exp",
NA, NA, NA), 3, 3, byrow = T)
tmat <- tmat_function(jump_types)
### Form parameter list acording to tmat numbers
lambda <- matrix(c(NA, 0.12, 0.03,
0.15, NA, 0.1,
NA, NA, NA), 3, 3, byrow = T)
# frailty distribution
Sigma <- matrix(c(0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0), 4, 4, byrow = T)
# Z_12, Z_13, Z_21, Z_23
diag(Sigma) <- log(c(1.0, 0.3, 1.5, 0.4) + 1)
Sigma[1,2] <- Sigma[2,1] <- log(1 + 1)
Sigma[1,3] <- Sigma[3,1] <- log(1 - 0.3)
Sigma[1,4] <- Sigma[4,1] <- log(1 + 0.5)
Sigma[2,3] <- Sigma[3,2] <- log(1 - 0.1)
Sigma[2,4] <- Sigma[4,2] <- log(1 + 0.2)
Sigma[3,4] <- Sigma[4,3] <- log(1 - 0.5)
Sigma <- nearPD(Sigma)$mat
frail <- rlog_norm(n = 1000, Sigma)
lambda_update <- function(lambda, vsts, state, jump_time, i, id){
# individual frailty at transition 3
if(state[i] == 1){
lambda[1,2] <- 0.12 * frail[id,1]
lambda[1,3] <- 0.03 * frail[id,2]
}
if(state[i] == 2){
lambda[2,1] <- 0.15 * frail[id,3]
lambda[2,3] <- 0.1 * frail[id,4]
}
lambda
}
par_list2 <- list(lambda = lambda)
data_sim <- sim_fun(init_probs = c(1,0,0), jump_types, pars = par_list2,
cens_time = 1000, nbr = 1000, hist_dep = T)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.