# compare R version with this function
library(SimSurvNMarker)
set.seed(1)
n <- 100L
n_y <- 3L
ti <- seq(0, 1, length.out = n)
offset <- runif(n_y)
B <- matrix(runif(5L * n_y), nr = 5L)
g_func <- function(x)
cbind(1, x, x^2, x^3, x^4)
U <- matrix(runif(3L * n_y), nr = 3L)
m_func <- function(x)
cbind(1, x, x^2)
r_version <- function(ti, B, g_func, U, m_func, offset){
func <- function(ti)
drop(crossprod(B, drop(g_func(ti))) + crossprod(U, drop(m_func(ti))))
vapply(ti, func, numeric(n_y)) + offset
}
# check that we get the same
stopifnot(isTRUE(all.equal(
c(r_version (ti[1], B, g_func, U, m_func, offset)),
eval_marker(ti[1], B, g_func, U, m_func, offset))))
stopifnot(isTRUE(all.equal(
r_version (ti, B, g_func, U, m_func, offset),
eval_marker(ti, B, g_func, U, m_func, offset))))
# check the computation time
system.time(replicate(100, r_version (ti, B, g_func, U, m_func, offset)))
system.time(replicate(100, eval_marker(ti, B, g_func, U, m_func, offset)))
Run the code above in your browser using DataLab