# NOT RUN {
#####
# Fit model with lung data set from survival
# Warning: this has a longer computation time
# }
# NOT RUN {
library(dynamichazard)
.lung <- lung[!is.na(lung$ph.ecog), ]
set.seed(43588155)
pf_fit <- PF_EM(
Surv(time, status == 2) ~ ph.ecog + age,
data = .lung, by = 50, id = 1:nrow(.lung),
Q_0 = diag(1, 3), Q = diag(1, 3),
max_T = 800,
control = list(
N_fw_n_bw = 500,
N_first = 2500,
N_smooth = 2500,
n_max = 50,
n_threads = parallel::detectCores()),
trace = 1)
# Plot state vector estimates
plot(pf_fit, cov_index = 1)
plot(pf_fit, cov_index = 2)
plot(pf_fit, cov_index = 3)
# Plot log-likelihood
plot(pf_fit$log_likes)
# }
# NOT RUN {
#####
# Can be compared with this example from ?coxph in R 3.4.1. Though, the above
# only has a linear effect for age
# }
# NOT RUN {
cox <- coxph(
Surv(time, status) ~ ph.ecog + tt(age), data= .lung,
tt=function(x,t,...) pspline(x + t/365.25))
cox
# }
Run the code above in your browser using DataCamp Workspace