PF_forward_filter | R Documentation |
Functions to only use the forward particle filter. Useful for log-likelihood
evaluation though there is an O(d^2) variance of the estimate where d is the number of time
periods. The number of particles specified in the control
argument
has no effect.
The function does not alter the .Random.seed
to make sure the
same rng.kind
is kept after the call. See PF_EM
for
model details.
PF_forward_filter(x, N_fw, N_first, ...) ## S3 method for class 'PF_EM' PF_forward_filter(x, N_fw, N_first, seed, ...) ## S3 method for class 'formula' PF_forward_filter( x, N_fw, N_first, data, model = "logit", by, max_T, id, a_0, Q_0, Q, fixed_effects, control = PF_control(...), seed = NULL, trace = 0, G, theta, J, K, psi, phi, type = "RW", Fmat, ... ) ## S3 method for class 'data.frame' PF_forward_filter( x, N_fw, N_first, formula, model = "logit", by, max_T, id, a_0, Q_0, Q, fixed_effects, control = PF_control(...), seed = NULL, trace = 0, fixed = NULL, random = NULL, G, theta, J, K, psi, phi, type = "RW", Fmat, order = 1, ... )
x |
an |
N_fw |
number of particles. |
N_first |
number of time zero particles to draw. |
... |
optional way to pass arguments to |
seed |
|
data |
|
model |
either |
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 |
Q_0 |
covariance matrix for the prior distribution. |
Q |
initial covariance matrix for the state equation. |
fixed_effects |
values for the fixed parameters. |
control |
see |
trace |
argument to get progress information. Zero will yield no info and larger integer values will yield incrementally more information. |
G, theta, J, K, psi, phi |
parameters for a restricted |
type |
type of state model. Either |
Fmat |
starting value for F when |
formula |
|
fixed |
two-sided |
random |
one-sided |
order |
order of the random walk. |
An object of class PF_clouds
.
PF_EM
: Forward particle filter using the
estimates of an PF_EM
call.
formula
: Forward particle filter with formula input.
data.frame
: Forward particle filter with data.frame
data input as x
instead of data
. Can be used with fixed
and random
argument.
The function is still under development so the output and API may change.
# head-and-neck cancer study data. See Efron, B. (1988) doi:10.2307/2288857 is_censored <- c( 6, 27, 34, 36, 42, 46, 48:51, 51 + c(15, 30:28, 33, 35:37, 39, 40, 42:45)) head_neck_cancer <- data.frame( id = 1:96, stop = c( 1, 2, 2, rep(3, 6), 4, 4, rep(5, 8), rep(6, 7), 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 14, 14, 14, 15, 18, 18, 20, 20, 37, 37, 38, 41, 45, 47, 47, 2, 2, 3, rep(4, 4), rep(5, 5), rep(6, 5), 7, 7, 7, 9, 10, 11, 12, 15, 16, 18, 18, 18, 21, 21, 24, 25, 27, 36, 41, 44, 52, 54, 59, 59, 63, 67, 71, 76), event = !(1:96 %in% is_censored), group = factor(c(rep(1, 45 + 6), rep(2, 45)))) # fit model set.seed(61364778) ctrl <- PF_control( N_fw_n_bw = 500, N_smooth = 2500, N_first = 2000, n_max = 1, # set to one as an example n_threads = 2, eps = .001, Q_tilde = as.matrix(.3^2), est_a_0 = FALSE) pf_fit <- suppressWarnings( PF_EM( survival::Surv(stop, event) ~ ddFixed(group), data = head_neck_cancer, by = 1, Q_0 = 1, Q = 0.1^2, control = ctrl, max_T = 30)) # the log-likelihood in the final iteration (end_log_like <- logLik(pf_fit)) # gives the same fw_ps <- PF_forward_filter( survival::Surv(stop, event) ~ ddFixed(group), N_fw = 500, N_first = 2000, data = head_neck_cancer, by = 1, Q_0 = 1, Q = 0.1^2, a_0 = pf_fit$a_0, fixed_effects = -0.5370051, control = ctrl, max_T = 30, seed = pf_fit$seed) all.equal(c(end_log_like), c(logLik(fw_ps))) # will differ since we use different number of particles fw_ps <- PF_forward_filter( survival::Surv(stop, event) ~ ddFixed(group), N_fw = 1000, N_first = 3000, data = head_neck_cancer, by = 1, Q_0 = 1, Q = 0.1^2, a_0 = pf_fit$a_0, fixed_effects = -0.5370051, control = ctrl, max_T = 30, seed = pf_fit$seed) all.equal(c(end_log_like), c(logLik(fw_ps))) # will differ since we use the final estimates fw_ps <- PF_forward_filter(pf_fit, N_fw = 500, N_first = 2000) all.equal(c(end_log_like), c(logLik(fw_ps)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.