Description Usage Arguments Value Examples
Function to extract the log-likelihood from a mssm
or
mssmLaplace
object.
1 2 3 4 5 |
object |
an object of class |
... |
un-used. |
A logLik
object. The log_lik_terms
attribute contains
the log-likelihood contributions from each time point.
The degrees of freedom assumes that all parameters are free. The number of observations may be invalid for some models (e.g., discrete survival analysis).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | if(require(Ecdat)){
# load data and fit glm to get starting values
data("Gasoline", package = "Ecdat")
glm_fit <- glm(lgaspcar ~ factor(country) + lincomep + lrpmg + lcarpcap,
Gamma("log"), Gasoline)
# get object to perform estimation
library(mssm)
ll_func <- mssm(
fixed = formula(glm_fit), random = ~ 1, family = Gamma("log"),
data = Gasoline, ti = year, control = mssm_control(
N_part = 1000L, n_threads = 1L))
# fit model with time-varying intercept with Laplace approximation
disp <- summary(glm_fit)$dispersion
laplace <- ll_func$Laplace(
cfix = coef(glm_fit), disp = disp, F. = diag(.5, 1), Q = diag(1))
# run particle filter
pf <- ll_func$pf_filter(
cfix = laplace$cfix, disp = laplace$disp, F. = laplace$F., Q = laplace$Q)
# compare approximate log-likelihoods
print(logLik(pf))
print(logLik(laplace))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.