Description Usage Arguments Value See Also Examples
Returns an object with a function that can be used to run a particle filter, a function to perform parameter estimation using a Laplace approximation, and a function to perform smoothing of particle weights.
1 2 | mssm(fixed, family, data, random, weights, offsets, ti,
control = mssm_control())
|
fixed |
|
family |
family for the observed outcome given the state variables and covariates. |
data |
|
random |
|
weights |
optional prior weights. |
offsets |
optional a priori known component in the linear predictor. |
ti |
integer vector with time indices matching with each observation of
|
control |
list with arguments passed to |
An object of class mssmFunc
with the following elements
pf_filter |
function to perform particle filtering. See mssm-pf. |
Laplace |
function to perform parameter estimation with a Laplace approximation. See mssm-Laplace. |
smoother |
function to compute smoothing weights for an |
terms_fixed |
|
terms_random |
|
y |
vector with outcomes. |
X |
covariates with fixed effects. |
Z |
covariates with random effects. |
ti |
time indices for each observation. |
weights |
prior weights for each observation. |
offsets |
a priori known component in the linear predictor for each observation. |
call |
the matched call. |
family |
character describing the conditional distribution of the outcomes. |
The README of the package contains examples of how to use this function. See https://github.com/boennecd/mssm.
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | if(require(Ecdat)){
# load data and fit glm to get starting values
. <- print
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))
.(ll_func)
# 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))
.(laplace)
# compare w/ glm
.(logLik(laplace))
.(logLik(glm_fit))
.(rbind(laplace = laplace$cfix, glm = coef(glm_fit)))
# run particle filter
pf <- ll_func$pf_filter(
cfix = laplace$cfix, disp = laplace$disp, F. = laplace$F., Q = laplace$Q)
.(pf)
# compare approximate log-likelihoods
.(logLik(pf))
.(logLik(laplace))
# predicted values from filtering (does not appear random...)
plot(pf)
# plot predicted values from smoothing distribution
pf <- ll_func$smoother(pf)
plot(pf, which_weights = "smooth")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.