data("smart")
x <- as.matrix(smart[, -c(1, 2)])
time <- smart$TEVENT
event <- smart$EVENT
y <- survival::Surv(time, event)
# Fit Cox model with lasso penalty
fit <- fit_lasso(x, y, nfolds = 5, rule = "lambda.1se", seed = 11)
# Model calibration by fitting the original data directly
cal.fitting <- calibrate(
x, time, event,
model.type = "lasso",
alpha = 1, lambda = fit$lambda,
method = "fitting",
pred.at = 365 * 9, ngroup = 5,
seed = 1010
)
# Model calibration by 5-fold cross-validation
cal.cv <- calibrate(
x, time, event,
model.type = "lasso",
alpha = 1, lambda = fit$lambda,
method = "cv", nfolds = 5,
pred.at = 365 * 9, ngroup = 5,
seed = 1010
)
print(cal.fitting)
summary(cal.fitting)
plot(cal.fitting)
print(cal.cv)
summary(cal.cv)
plot(cal.cv)
# # Test fused lasso, SCAD, and Mnet models
# data(smart)
# x = as.matrix(smart[, -c(1, 2)])[1:500, ]
# time = smart$TEVENT[1:500]
# event = smart$EVENT[1:500]
# y = survival::Surv(time, event)
#
# set.seed(1010)
# cal.fitting = calibrate(
# x, time, event, model.type = "flasso",
# lambda1 = 5, lambda2 = 2,
# method = "fitting",
# pred.at = 365 * 9, ngroup = 5,
# seed = 1010)
#
# cal.boot = calibrate(
# x, time, event, model.type = "scad",
# gamma = 3.7, alpha = 1, lambda = 0.03,
# method = "bootstrap", boot.times = 10,
# pred.at = 365 * 9, ngroup = 5,
# seed = 1010)
#
# cal.cv = calibrate(
# x, time, event, model.type = "mnet",
# gamma = 3, alpha = 0.3, lambda = 0.03,
# method = "cv", nfolds = 5,
# pred.at = 365 * 9, ngroup = 5,
# seed = 1010)
#
# cal.repcv = calibrate(
# x, time, event, model.type = "flasso",
# lambda1 = 5, lambda2 = 2,
# method = "repeated.cv", nfolds = 5, rep.times = 3,
# pred.at = 365 * 9, ngroup = 5,
# seed = 1010)
#
# print(cal.fitting)
# summary(cal.fitting)
# plot(cal.fitting)
#
# print(cal.boot)
# summary(cal.boot)
# plot(cal.boot)
#
# print(cal.cv)
# summary(cal.cv)
# plot(cal.cv)
#
# print(cal.repcv)
# summary(cal.repcv)
# plot(cal.repcv)
Run the code above in your browser using DataLab