This function can be used as part of a dynamiteformula() to define
a common latent factor component. The latent factor is modeled as a spline
similarly as a time-varying intercept, but instead of having equal effect on
each group, there is an additional loading variable for each group so that
in the linear predictor we have a term \(\lambda_i \psi_t\) for each
group \(i\).
Usage
lfactor(
responses = NULL,
nonzero_lambda = TRUE,
correlated = TRUE,
noncentered_psi = FALSE,
flip_sign = TRUE
)Arguments
- responses
[
character()]
Names of the responses that the factor should affect. Default is all responses defined withobsexcept categorical responses, which do not (yet) support the factor component.- nonzero_lambda
[
logical()]
IfTRUE(the default), assumes that the mean of factor loadings is nonzero or not. Should be a logical vector matching the length ofresponsesor a single logical value in caseresponsesisNULL. See details.[
logical()]
IfTRUE(the default), the latent factors are assumed to be correlated between channels.- noncentered_psi
[
logical(1)]
IfTRUE, uses a noncentered parametrization for spline coefficients of all the factors. The number of knots is basedsplines()call. Default isFALSE.- flip_sign
[
logical(1)]
IfTRUE(default), try to avoid multimodality due to sign-switching by defining the sign of \(\lambda\) and \(\psi\) based on the mean of \(\omega_1,\ldots, \omega_D\) coefficients. This only affects channels withnonzero_lambda = FALSE. If the true mean of \(\omega\)s is close to zero, this might not help, in which case it is better to setflip_sign = FALSEand post-process the samples in other ways (or use only one chain and/or suitable initial values). This argument is common to all factors.
See also
Model formula construction
dynamite(),
dynamiteformula(),
lags(),
random_spec(),
splines()
Examples
data.table::setDTthreads(1) # For CRAN
# three channel model with common factor affecting for responses x and y
obs(y ~ 1, family = "gaussian") +
obs(x ~ 1, family = "poisson") +
obs(z ~ 1, family = "gaussian") +
lfactor(
responses = c("y", "x"), nonzero_lambda = c(TRUE, FALSE),
correlated = TRUE, noncentered_psi = FALSE
)
#> Family Formula
#> y gaussian y ~ 1
#> x poisson x ~ 1
#> z gaussian z ~ 1
