# NOT RUN {
### Example 1:
### - event-times generated from a Cox's PH model with unit baseline hazard
### and time-varying covariates generated from independent standard normal
### distributions over the intervals (0,s_1], (s_1,s_2], ..., (s_1,s_J].
### - censoring times generated from an exponential distribution truncated
### above s_J.
### - covariates in the incidence (cure) component generated from independent
### standard normal distributions.
# Define the sample size
N <- 250
# Define the time intervals for the time-varying covariates
S <- seq(0.1, 5, by=0.1)
# Define the true regression coefficients (incidence and latency)
b0 <- c(1,-1,0,1,0)
beta0 <- c(1,0,-1,0)
# Define the parameter of the truncated exponential distribution (censoring)
lambdaC <- 1.5
# Simulate the data
data1 <- penPHcure.simulate(N = N,S = S,
b0 = b0,
beta0 = beta0,
lambdaC = lambdaC)
### Example 2:
### Similar to the previous example, but with a baseline hazard function
### defined as lambda_0(t) = 3t^2.
# Define the sample size
N <- 250
# Define the time intervals for the time-varying covariates
S <- seq(0.1, 5, by=0.1)
# Define the true regression coefficients (incidence and latency)
b0 <- c(1,-1,0,1,0)
beta0 <- c(1,0,-1,0)
# Define the parameter controlling the shape of the baseline hazard function
gamma <- 3
# Simulate the data
data2 <- penPHcure.simulate(N = N,S = S,
b0 = b0,
beta0 = beta0,
gamma = gamma)
### Example 3:
### Simulation with covariates in the cure and survival components generated
### from multivariate normal (MVN) distributions with specific means,
### standard deviations and correlation matrices.
# Define the sample size
N <- 250
# Define the time intervals for the time-varying covariates
S <- seq(0.1, 5, by=0.1)
# Define the true regression coefficients (incidence and latency)
b0 <- c(-1,-1,0,1,0)
beta0 <- c(1,0,-1,0)
# Define the means of the MVN distribution (incidence and latency)
mean_CURE <- c(-1,0,1,2)
mean_SURV <- c(2,1,0,-1)
# Define the std. deviations of the MVN distribution (incidence and latency)
sd_CURE <- c(0.5,1.5,1,0.5)
sd_SURV <- c(0.5,1,1.5,0.5)
# Define the correlation matrix of the MVN distribution (incidence and latency)
cor_CURE <- matrix(NA,4,4)
for (p in 1:4)
for (q in 1:4)
cor_CURE[p,q] <- 0.8^abs(p - q)
cor_SURV <- matrix(NA,4,4)
for (p in 1:4)
for (q in 1:4)
cor_SURV[p,q] <- 0.8^abs(p - q)
# Simulate the data
data3 <- penPHcure.simulate(N = N,S = S,
b0 = b0,
beta0 = beta0,
mean_CURE = mean_CURE,
mean_SURV = mean_SURV,
sd_CURE = sd_CURE,
sd_SURV = sd_SURV,
cor_CURE = cor_CURE,
cor_SURV = cor_SURV)
### Example 4:
### Simulation with covariates in the cure and survival components from a
### data generating process specified by the user.
# Define the sample size
N <- 250
# Define the time intervals for the time-varying covariates
S <- seq(0.1, 5, by=0.1)
# Define the true regression coefficients (incidence and latency)
b0 <- c(1,-1,0,1,0)
beta0 <- c(1,0,-1,0)
# As an example, we simulate data with covariates following independent
# standard uniform distributions. But the user could provide random draws
# from any other distribution. Be careful!!! X should be a matrix of size
# N x length(b0) and Z an array of size length(S) x length(beta0) x N.
X <- matrix(runif(N*(length(b0)-1)),N,length(b0)-1)
Z <- array(runif(N*length(S)*length(beta0)),c(length(S),length(beta0),N))
data4 <- penPHcure.simulate(N = N,S = S,
b0 = b0,
beta0 = beta0,
X = X,
Z = Z)
### Example 5:
### Simulation with censoring times from a data generating process
### specified by the user
# Define the sample size
N <- 250
# Define the time intervals for the time-varying covariates
S <- seq(0.1, 5, by=0.1)
# Define the true regression coefficients (incidence and latency)
b0 <- c(1,-1,0,1,0)
beta0 <- c(1,0,-1,0)
# As an example, we simulate data with censoring times following
# a standard uniform distribution between 0 and S_J.
# Be careful!!! C should be a numeric vector of length N.
C <- runif(N)*max(S)
data5 <- penPHcure.simulate(N = N,S = S,
b0 = b0,
beta0 = beta0,
C = C)
# }
Run the code above in your browser using DataLab