Function to fit dynamic hazard models using state space models.
ddhazard(formula, data, model = "logit", by, max_T, id, a_0, Q_0, Q = Q_0,
order = 1, weights, control = list(), verbose = F)data.frame or environment containing the outcome and co-variates.
"logit" or "exponential" for the logistic link function in the first case or for the continuous time model in the latter case.
interval length of the bins in which parameters are fixed.
end of the last interval interval.
vector of ids for each row of the in the design matrix.
vector \(a_0\) for the initial coefficient vector for the first iteration (optional). Default is estimates from static model (see static_glm).
covariance matrix for the prior distribution.
initial covariance matrix for the state equation.
order of the random walk.
weights to use if e.g. a skewed sample is used.
list of control variables (see the control section below).
TRUE if you want status messages during execution.
A list with class ddhazard. The list contains
formulathe passed formula.
callthe matched call.
state_vecs2D matrix with the estimated state vectors (regression parameters) in each bin.
state_vars3D array with smoothed variance estimates for each state vector.
lag_one_cov3D array with lagged correlation matrix for each for each change in the state vector. Only present when the model is logit and the method is EKF.
n_riskthe number of observations in each interval.
timesthe interval borders.
risk_setthe object from get_risk_obj if saved.
datathe data argument if saved.
weightsweights used in estimation if saved.
idids used to match rows in data to individuals.
orderorder of the random walk.
F_matrix which map from one state vector to the next.
methodmethod used in the E-step.
est_Q_0TRUE if Q_0 was estimated in the EM-algorithm.
familyRcpp Module with C++ functions used for estimation given the model argument.
discrete_hazard_functhe hazard function corresponding to the model argument.
termsthe terms object used.
has_fixed_interceptTRUE if the model has a time-invariant intercept.
xleva record of the levels of the factors used in fitting.
The control argument allows you to pass a list to select additional parameters. See vignette("ddhazard", "dynamichazard") for more information. Unspecified elements of the list will yield default values.
methodset to the method to use in the E-step. Either "EKF" for the Extended Kalman Filter, "UKF" for the Unscented Kalman Filter, "SMA" for the sequential posterior mode approximation method or "GMA" for the global mode approximation method. "EKF" is the default.
LRlearning rate.
NR_epstolerance for the Extended Kalman filter. Default is NULL which means that no extra iteration is made in the correction step.
alphahyper parameter \(\alpha\) in the unscented Kalman Filter.
betahyper parameter \(\beta\) in the unscented Kalman Filter.
kappahyper parameter \(\kappa\) in the unscented Kalman Filter.
n_maxmaximum number of iteration in the EM-algorithm.
epstolerance parameter for the EM-algorithm.
est_Q_0TRUE if you want the EM-algorithm to estimate Q_0. Default is FALSE.
save_risk_setTRUE if you want to save the list from get_risk_obj used to estimate the model. It may be needed for later calls to e.g., residuals, plot and logLike.
save_dataTRUE if you want to keep the data argument. It may be needed for later calls to e.g., residuals, plot and logLike.
denom_termterm added to denominators in either the EKF or UKF.
n_threadsmaximum number of threads to use.
fixed_parems_startstarting value for fixed terms.
fixed_terms_methodthe method used to estimate the fixed effects. Either 'M_step' or 'E_step' for estimation in the M-step or E-step respectively.
Q_0_term_for_fixed_E_stepthe diagonal value of the initial covariance matrix, Q_0, for the fixed effects if fixed effects are estimated in the E-step.
eps_fixed_paremstolerance used in the M-step of the Fisher's scoring algorithm for the fixed effects.
permuTRUE if the risk sets should be permutated before computation. This is TRUE by default for posterior mode approximation method and FALSE for all other methods.
posterior_versionthe implementation version of the posterior approximation method. Either "woodbury" or "cholesky".
GMA_max_repmaximum number of iterations in the correction step if method = 'GMA'.
GMA_NR_epstolerance for the convergence criteria for the relative change in the norm of the coefficients in the correction step if method = 'GMA'.
This function can be used to estimate survival models where the regression parameters follows a given order random walk. The order is specified by the order argument. 1. and 2. order random walks is implemented. The regression parameters are updated at time by, 2by, ..., max_T. See the vignette("ddhazard", "dynamichazard") for details.
All filter methods needs a state covariance matrix Q_0 and state vector a_0. An estimate from a time-invariant model is used for a_0 if it is not supplied (the same model you would get from static_glm). A diagonal matrix with large entries is recommended for Q_0. What is large dependents on the data set and model. Further, a covariance matrix for the first iteration Q is needed. The Q and a_0 are estimated with an EM-algorithm.
The model is specified through the model argument. The logistic model is where outcomes are binned into the intervals. Be aware that there can be "loss" of information due to binning. It is key for the logit model that the id argument is provided if individuals in the data set have time-varying co-variates. The the exponential model use an exponential model for the arrival times where there is no "loss" information due to binning.
It is recommended to see the Shiny app demo for this function by calling ddhazard_app().
Fahrmeir, Ludwig. Dynamic modelling and penalized likelihood estimation for discrete time survival data. Biometrika 81.2 (1994): 317-330.
Durbin, James, and Siem Jan Koopman. Time series analysis by state space methods. No. 38. Oxford University Press, 2012.
plot, residuals, predict, static_glm, ddhazard_app, ddhazard_boot
# NOT RUN {
# example with first order model
library(dynamichazard)
fit <- ddhazard(
Surv(time, status == 2) ~ log(bili), pbc, id = pbc$id, max_T = 3600,
Q_0 = diag(1, 2), Q = diag(1e-4, 2), by = 50,
control = list(method = "GMA"))
plot(fit)
# example with second order model
fit <- ddhazard(
Surv(time, status == 2) ~ log(bili), pbc, id = pbc$id, max_T = 3600,
Q_0 = diag(1, 4), Q = diag(1e-4, 2), by = 50,
control = list(method = "GMA"),
order = 2)
plot(fit)
# }
Run the code above in your browser using DataLab