library(dplyr)
library(gaussquad)
library(MASS)
library(nleqslv)
n=500
beta<-function(t){
0.5*(t+0.5)^2
}
lqrule64 <- legendre.quadrature.rules(64)[[64]]
simdata <- function( beta ) {
cen=1
nstep=20
Sigmat_z <- exp(-abs(outer(1:nstep, 1:nstep, "-")) / nstep)
z <-c(mvrnorm( 1, rep(0,20), Sigmat_z ))
left_time_points <- (0:(nstep - 1)) / nstep
z_fun <- stepfun(left_time_points, c(0,z ))
h_fun <- function(x) { beta(x) * z_fun(x) }
lam_fun <- function(tt) 2 * exp(h_fun(tt))
u <- runif(1)
fail_time <- nleqslv(0, function(ttt)
legendre.quadrature(lam_fun, lower = 0,upper = ttt, lqrule64) + log(u))$x
X <- min(fail_time, cen)
obs=rpois(1, 5)+1
tt= sort(runif(obs, min = 0, max = 1))
obs_times <- tt[which(tt<=cen)]
if (length(obs_times) == 0)
obs_times <- cen
covariates_obscov <-z_fun(obs_times)
return( tibble(X = X,delta = fail_time < cen,
covariates = covariates_obscov,obs_times = obs_times ) ) }
data <- replicate( n, simdata( beta ), simplify = FALSE ) %>% bind_rows(.id = "id")
tv.co.Cox(data,n,l,0.2,bd=c(n^(-0.4),n^(-0.4)),scb=0)
Run the code above in your browser using DataLab