iterate_process <- function(t, gen, uni_cens) {
n_states <- nrow(gen)
to_states <- which(!is.na(rowSums(gen)))
a <- gen[to_states,1]
b <- gen[to_states,2]
haz <- function(t) a * b * t^(b-1)
cumhaz <- function(t) a * t^b
h_t <- Vectorize(haz)(t)
H_t <- Vectorize(cumhaz)(t)
if (is.null(dim(H_t))) {
H_t <- t(as.matrix(H_t))
}
# sojourn_times
u <- array(runif(n = length(H_t)), dim = dim(H_t))
t_sjn <- ((H_t - log(u))/a)^(1/b)
# t_sjn <- (-log(u)/a)^(1/b)
to_index <- apply(t_sjn, 2, which.min)
t_sjn <- t_sjn[to_index + nrow(t_sjn)*seq(0, ncol(t_sjn) - 1)]
to <- to_states[to_index]
return(list(to, t_sjn))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.