logLik.mssm: Approximate Log-likelihood for a mssm Object

Description Usage Arguments Value Examples

Description

Function to extract the log-likelihood from a mssm or mssmLaplace object.

Usage

1
2
3
4
5
## S3 method for class 'mssm'
logLik(object, ...)

## S3 method for class 'mssmLaplace'
logLik(object, ...)

Arguments

object

an object of class mssm or mssmLaplace.

...

un-used.

Value

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).

Examples

 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))
}

mssm documentation built on Jan. 31, 2022, 9:08 a.m.