# NOT RUN {
burnin <- 50
nmc <- 150
thin <- 1
y.sd <- 1 # standard deviation of the response
p <- 100 # number of predictors
ntrain <- 100 # training size
ntest <- 50 # test size
n <- ntest + ntrain # sample size
q <- 10 # number of true predictos
beta.t <- c(sample(x = c(1, -1), size = q, replace = TRUE), rep(0, p - q)) # randomly assign sign
Sigma <- matrix(0.9, nrow = p, ncol = p)
for(j in 1:p)
{
Sigma[j, j] <- 1
}
x <- mvtnorm::rmvnorm(n, mean = rep(0, p), sigma = Sigma) # correlated design matrix
zmean <- x %*% beta.t
tmean <- x %*% beta.t
yCorr <- 0.5
yCov <- matrix(c(1, yCorr, yCorr, 1), nrow = 2)
y <- mvtnorm::rmvnorm(n, sigma = yCov)
t <- y[, 1] + tmean
z <- ifelse((y[, 2] + zmean) > 0, 1, 0)
X <- scale(as.matrix(x)) # standarization
z <- as.numeric(as.matrix(c(z)))
t <- as.numeric(as.matrix(c(t)))
T <- exp(t) # AFT model
C <- rgamma(n, shape = 1.75, scale = 3) # 42% censoring time
time <- pmin(T, C) # observed time is min of censored and true
status = time == T # set to 1 if event is observed
ct <- as.matrix(cbind(time = time, status = status)) # censored time
# Training set
ztrain <- z[1:ntrain]
cttrain <- ct[1:ntrain, ]
Xtrain <- X[1:ntrain, ]
# Test set
ztest <- z[(ntrain + 1):n]
cttest <- ct[(ntrain + 1):n, ]
Xtest <- X[(ntrain + 1):n, ]
posterior.fit.joint <- aftprobiths(ct = cttrain, z = ztrain, X = Xtrain,
burn = burnin, nmc = nmc, thin = thin,
Xtest = Xtest, cttest = cttest, ztest = ztest)
posterior.fit.joint$Beta.sHat
# }
Run the code above in your browser using DataLab