dynamichazard (version 0.5.0)

PF_EM: EM estimation with particle filters

Description

Method to estimate the hyper parameters with an EM algorithm.

Usage

PF_EM(formula, data, model = "logit", by, max_T, id, a_0, Q_0, Q, order = 1,
  control = list(), trace = 0)

Arguments

formula

coxph like formula with Surv(tstart, tstop, event) on the left hand site of ~.

data

data.frame or environment containing the outcome and co-variates.

model

either 'logit' for binary outcomes or 'exponential' for piecewise constant exponential distributed arrival times.

by

interval length of the bins in which parameters are fixed.

max_T

end of the last interval interval.

id

vector of ids for each row of the in the design matrix.

a_0

vector \(a_0\) for the initial coefficient vector for the first iteration (optional). Default is estimates from static model (see static_glm).

Q_0

covariance matrix for the prior distribution.

Q

initial covariance matrix for the state equation.

order

order of the random walk.

control

list of control variables (see the control section below).

trace

argument to get progress information. Zero will yield no info and larger integer values will yield incrementally more information.

Value

An object of class PF_EM.

Control

The control argument allows you to pass a list to select additional parameters. See vignette("Particle_filtering", "dynamichazard") for details. Unspecified elements of the list will yield default values.

method

method for forward, backward and smoothing filter.

smoother

smoother to use.

N_fw_n_bw

number of particles to use in forward and backward filter.

N_first

number of particles to use at time \(0\) and time \(d + 1\).

N_smooth

number of particles to use in particle smoother.

eps

convergence threshold in EM method.

n_max

maximum number of iterations of the EM algorithm.

n_threads

maximum number threads to use in the computations.

forward_backward_ESS_threshold

required effective sample size to not re-sample in the particle filters.

seed

seed to set at the start of every EM iteration.

Details

See vignette("Particle_filtering", "dynamichazard") for details.

Examples

Run this code
# 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 DataLab