dynamichazard (version 0.4.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. The last stop time with an event is selected if the parameter is omitted

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 an 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 the vignette 'ddhazard' for more information on hyper parameters. Unspecified elements of the list will yield default values

method

Method for forward, backward and smoothing filter. See the particle_filter vignette for details.

smoother

Smoother to use. See the particle_filter vignette for details.

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 threhshold 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 the particle_filter vignette 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 DataCamp Workspace