Function to fit dynamic discrete 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", "exp_clip_time_w_jump", "exp_clip_time", "exp_bin" or "exp_combined" for the discrete time function using the logistic link function in the first case or for the continuous time model with different estimation method in the four latter cases (see the ddhazard for details on the methods)
Interval length of the bins in which parameters are fixed
End of the last interval. The last stop time with an event is selected if the parameter is omitted
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 details below)
TRUE if you want status messages during execution
A list with class fahrmeier_94. The list contains:
formulaThe passed formula
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
idids used to match rows in data to individuals
orderOrder of the random walk
F_Matrix with that map transition 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
hazard_funcHazard function
hazard_first_derivFirst derivative of the hazard function with respect to the linear predictor
The control argument allows you to pass a list to select additional parameters. See the vignette 'ddhazard' for more information on hyper parameters. 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 or "UKF"for the Unscented Kalman Filter. "EKF" is the default
LRLearning rate for the Extended Kalman filter
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 call to residuals, plot and logLike. Can be set to FALSE to save memory
save_dataTRUE if you want to save the list data argument. It may be needed for later call to residuals, plot and logLike. Can be set to FALSE to save memory
ridge_epsPenalty term added to the diagonal of the covariance matrix of the observational equation in either the EKF or UKF
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
This function can be used to estimate a binary regression 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' for more details
The Extended Kalman filter or Unscented Kalman filter needs an initial co-variance matrix Q_0 and state vector a_0. An estimate from a time-invariant model is provided for a_0 if it is not supplied (the same model you would get from static_glm function). A diagonal matrix with large entries is recommended for Q_0. What is large dependents on the data set and model. Further, a variance matrix for the first iteration Q is needed. It is recommended to select diagonal matrix with low values for the latter. The Q, a_0 and optionally Q_0 is estimated with an EM-algorithm
The model is specified through the model argument. Currently, 'logit' and 'exponential' is available. The former uses an logistic model 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 latter model uses 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