Log-likelihood of the two-level VAR(1) at given parameters (MAR)
Source:R/fit_fiml.R
loglik_fiml.RdEvaluates, without fitting, the likelihood that fit_fiml
maximizes: the Gaussian likelihood of the answered states under the
two-level VAR(1) with random person means, skipped prompts integrated out
as missing at random. Useful for comparing fits, for profile likelihoods,
and for checking a fit against the trace of the EM iterations.
Usage
loglik_fiml(
data,
vars,
Phi,
Psi,
mu,
Sigma_mu,
Sigma0 = stationary_cov(Phi, Psi),
id = "id",
time = "time",
R = "R"
)Arguments
- data
Long data frame with one row per scheduled prompt.
- vars
Names of the state columns.
- Phi, Psi, mu, Sigma_mu, Sigma0
Parameter values: the \(p \times p\) lagged-coefficient matrix, the \(p \times p\) innovation covariance, the length-\(p\) population mean, the \(p \times p\) between-person covariance of the person means, and the \(p \times p\) covariance of the within-person deviation at the first prompt (by default the stationary covariance implied by
PhiandPsi).- id, time
Names of the person and prompt-index columns.
- R
Name of the response-indicator column (0/1, no
NA). If the default name is not among the columns ofdata, a prompt counts as answered when allvarsare non-missing; any other name must exist.
Value
A single number, the log-likelihood of the observed states under the two-level VAR(1) with the given parameters, skipped prompts treated as missing at random.
Examples
sim <- simulate_ema(N = 20, n_prompts = 15, seed = 1)
f <- fit_fiml(sim$data, sim$vars)
loglik_fiml(sim$data, sim$vars, f$Phi, f$Psi, f$mu, f$Sigma_mu)
#> [1] -1168.637
# the likelihood at the population parameters is lower than at the ML estimates
p <- default_params()
loglik_fiml(sim$data, sim$vars, p$Phi, p$Psi, p$mu, p$Sigma_mu)
#> [1] -1191.993