loglikelihood: Log-likelihood function

View source: R/loglikelihood.R

loglikelihoodR Documentation

Log-likelihood function

Description

loglikelihood log-likelihood function of a smooth transition VAR model

Usage

loglikelihood(
  data,
  p,
  M,
  params,
  weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
    "exogenous"),
  weightfun_pars = NULL,
  cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
  parametrization = c("intercept", "mean"),
  identification = c("reduced_form", "recursive", "heteroskedasticity",
    "non-Gaussianity"),
  AR_constraints = NULL,
  mean_constraints = NULL,
  weight_constraints = NULL,
  B_constraints = NULL,
  other_constraints = NULL,
  to_return = c("loglik", "tw", "loglik_and_tw", "terms", "regime_cmeans",
    "total_cmeans", "total_ccovs", "B_t"),
  check_params = TRUE,
  penalized = FALSE,
  penalty_params = c(0.05, 0.2),
  allow_unstab = FALSE,
  bound_by_weights = FALSE,
  indt_R = FALSE,
  alt_par = FALSE,
  minval = NULL,
  stab_tol = 0.001,
  posdef_tol = 1e-08,
  distpar_tol = 1e-08,
  weightpar_tol = 1e-08
)

Arguments

data

a matrix or class 'ts' object with d>1 columns. Each column is taken to represent a univariate time series. Missing values are not supported.

p

a positive integer specifying the autoregressive order

M

a positive integer specifying the number of regimes

params

a real valued vector specifying the parameter values. Should have the form \theta = (\phi_{1},...,\phi_{M},\varphi_1,...,\varphi_M,\sigma,\alpha,\nu), where (see exceptions below):

  • \phi_{m} = the (d \times 1) intercept (or mean) vector of the mth regime.

  • \varphi_m = (vec(A_{m,1}),...,vec(A_{m,p})) (pd^2 \times 1).

  • if cond_dist="Gaussian" or "Student":

    \sigma = (vech(\Omega_1),...,vech(\Omega_M)) (Md(d + 1)/2 \times 1).

    if cond_dist="ind_Student" or "ind_skewed_t":

    \sigma = (vec(B_1),...,vec(B_M) (Md^2 \times 1).

  • \alpha = the (a\times 1) vector containing the transition weight parameters (see below).

  • if cond_dist = "Gaussian"):

    Omit \nu from the parameter vector.

    if cond_dist="Student":

    \nu > 2 is the single degrees of freedom parameter.

    if cond_dist="ind_Student":

    \nu = (\nu_1,...,\nu_d) (d \times 1), \nu_i > 2.

    if cond_dist="ind_skewed_t":

    \nu = (\nu_1,...,\nu_d,\lambda_1,...,\lambda_d) (2d \times 1), \nu_i > 2 and \lambda_i \in (0, 1).

For models with...

weight_function="relative_dens":

\alpha = (\alpha_1,...,\alpha_{M-1}) (M - 1 \times 1), where \alpha_m (1\times 1), m=1,...,M-1 are the transition weight parameters.

weight_function="logistic":

\alpha = (c,\gamma) (2 \times 1), where c\in\mathbb{R} is the location parameter and \gamma >0 is the scale parameter.

weight_function="mlogit":

\alpha = (\gamma_1,...,\gamma_M) ((M-1)k\times 1), where \gamma_m (k\times 1), m=1,...,M-1 contains the multinomial logit-regression coefficients of the mth regime. Specifically, for switching variables with indices in I\subset\lbrace 1,...,d\rbrace, and with \tilde{p}\in\lbrace 1,...,p\rbrace lags included, \gamma_m contains the coefficients for the vector z_{t-1} = (1,\tilde{z}_{\min\lbrace I\rbrace},...,\tilde{z}_{\max\lbrace I\rbrace}), where \tilde{z}_{i} =(y_{it-1},...,y_{it-\tilde{p}}), i\in I. So k=1+|I|\tilde{p} where |I| denotes the number of elements in I.

weight_function="exponential":

\alpha = (c,\gamma) (2 \times 1), where c\in\mathbb{R} is the location parameter and \gamma >0 is the scale parameter.

weight_function="threshold":

\alpha = (r_1,...,r_{M-1}) (M-1 \times 1), where r_1,...,r_{M-1} are the thresholds.

weight_function="exogenous":

Omit \alpha from the parameter vector.

AR_constraints:

Replace \varphi_1,...,\varphi_M with \psi as described in the argument AR_constraints.

mean_constraints:

Replace \phi_{1},...,\phi_{M} with (\mu_{1},...,\mu_{g}) where \mu_i, \ (d\times 1) is the mean parameter for group i and g is the number of groups.

weight_constraints:

If linear constraints are imposed, replace \alpha with \xi as described in the argument weigh_constraints. If weight functions parameters are imposed to be fixed values, simply drop \alpha from the parameter vector.

identification="heteroskedasticity":

\sigma = (vec(W),\lambda_2,...,\lambda_M), where W (d\times d) and \lambda_m (d\times 1), m=2,...,M, satisfy \Omega_1=WW' and \Omega_m=W\Lambda_mW', \Lambda_m=diag(\lambda_{m1},...,\lambda_{md}), \lambda_{mi}>0, m=2,...,M, i=1,...,d.

B_constraints:

For models identified by heteroskedasticity, replace vec(W) with \tilde{vec}(W) that stacks the columns of the matrix W in to vector so that the elements that are constrained to zero are not included. For models identified by non-Gaussianity, replace vec(B_1),...,vec(B_M) with similarly with vectorized versions B_m so that the elements that are constrained to zero are not included.

Above, \phi_{m} is the intercept parameter, A_{m,i} denotes the ith coefficient matrix of the mth regime, \Omega_{m} denotes the positive definite error term covariance matrix of the mth regime, and B_m is the invertible (d\times d) impact matrix of the mth regime. \nu_m is the degrees of freedom parameter of the mth regime. If parametrization=="mean", just replace each \phi_{m} with regimewise mean \mu_{m}. vec() is vectorization operator that stacks columns of a given matrix into a vector. vech() stacks columns of a given matrix from the principal diagonal downwards (including elements on the diagonal) into a vector. Bvec() is a vectorization operator that stacks the columns of a given impact matrix B_m into a vector so that the elements that are constrained to zero by the argument B_constraints are excluded.

weight_function

What type of transition weights \alpha_{m,t} should be used?

"relative_dens":

\alpha_{m,t}= \frac{\alpha_mf_{m,dp}(y_{t-1},...,y_{t-p+1})}{\sum_{n=1}^M\alpha_nf_{n,dp}(y_{t-1},...,y_{t-p+1})}, where \alpha_m\in (0,1) are weight parameters that satisfy \sum_{m=1}^M\alpha_m=1 and f_{m,dp}(\cdot) is the dp-dimensional stationary density of the mth regime corresponding to p consecutive observations. Available for Gaussian conditional distribution only.

"logistic":

M=2, \alpha_{1,t}=1-\alpha_{2,t}, and \alpha_{2,t}=[1+\exp\lbrace -\gamma(y_{it-j}-c) \rbrace]^{-1}, where y_{it-j} is the lag j observation of the ith variable, c is a location parameter, and \gamma > 0 is a scale parameter.

"mlogit":

\alpha_{m,t}=\frac{\exp\lbrace \gamma_m'z_{t-1} \rbrace} {\sum_{n=1}^M\exp\lbrace \gamma_n'z_{t-1} \rbrace}, where \gamma_m are coefficient vectors, \gamma_M=0, and z_{t-1} (k\times 1) is the vector containing a constant and the (lagged) switching variables.

"exponential":

M=2, \alpha_{1,t}=1-\alpha_{2,t}, and \alpha_{2,t}=1-\exp\lbrace -\gamma(y_{it-j}-c) \rbrace, where y_{it-j} is the lag j observation of the ith variable, c is a location parameter, and \gamma > 0 is a scale parameter.

"threshold":

\alpha_{m,t} = 1 if r_{m-1}<y_{it-j}\leq r_{m} and 0 otherwise, where -\infty\equiv r_0<r_1<\cdots <r_{M-1}<r_M\equiv\infty are thresholds y_{it-j} is the lag j observation of the ith variable.

"exogenous":

Exogenous nonrandom transition weights, specify the weight series in weightfun_pars.

See the vignette for more details about the weight functions.

weightfun_pars
If weight_function == "relative_dens":

Not used.

If weight_function %in% c("logistic", "exponential", "threshold"):

a numeric vector with the switching variable i\in\lbrace 1,...,d \rbrace in the first and the lag j\in\lbrace 1,...,p \rbrace in the second element.

If weight_function == "mlogit":

a list of two elements:

The first element $vars:

a numeric vector containing the variables that should used as switching variables in the weight function in an increasing order, i.e., a vector with unique elements in \lbrace 1,...,d \rbrace.

The second element $lags:

an integer in \lbrace 1,...,p \rbrace specifying the number of lags to be used in the weight function.

If weight_function == "exogenous":

a size (nrow(data) - p x M) matrix containing the exogenous transition weights as [t, m] for time t and regime m. Each row needs to sum to one and only weakly positive values are allowed.

cond_dist

specifies the conditional distribution of the model as "Gaussian", "Student", "ind_Student", or "ind_skewed_t", where "ind_Student" the Student's t distribution with independent components, and "ind_skewed_t" is the skewed t distribution with independent components (see Hansen, 1994).

parametrization

"intercept" or "mean" determining whether the model is parametrized with intercept parameters \phi_{m} or regime means \mu_{m}, m=1,...,M.

identification

is it reduced form model or an identified structural model; if the latter, how is it identified (see the vignette or the references for details)?

"reduced_form":

Reduced form model.

"recursive":

The usual lower-triangular recursive identification of the shocks via their impact responses.

"heteroskedasticity":

Identification by conditional heteroskedasticity, which imposes constant relative impact responses for each shock.

"non-Gaussianity":

Identification by non-Gaussianity; requires mutually independent non-Gaussian shocks, thus, currently available only with the conditional distribution "ind_Student".

AR_constraints

a size (Mpd^2 \times q) constraint matrix C specifying linear constraints to the autoregressive parameters. The constraints are of the form (\varphi_{1},...,\varphi_{M}) = C\psi, where \varphi_{m} = (vec(A_{m,1}),...,vec(A_{m,p})) \ (pd^2 \times 1),\ m=1,...,M, contains the coefficient matrices and \psi (q \times 1) contains the related parameters. For example, to restrict the AR-parameters to be the identical across the regimes, set C = [I:...:I]' (Mpd^2 \times pd^2) where I = diag(p*d^2).

mean_constraints

Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if M=3, the argument list(1, 2:3) restricts the mean parameters of the second and third regime to be identical but the first regime has freely estimated (unconditional) mean. Ignore or set to NULL if mean parameters should not be restricted to be the same among any regimes. This constraint is available only for mean parametrized models; that is, when parametrization="mean".

weight_constraints

a list of two elements, R in the first element and r in the second element, specifying linear constraints on the transition weight parameters \alpha. The constraints are of the form \alpha = R\xi + r, where R is a known (a\times l) constraint matrix of full column rank (a is the dimension of \alpha), r is a known (a\times 1) constant, and \xi is an unknown (l\times 1) parameter. Alternatively, set R=0 to constrain the weight parameters to the constant r (in this case, \alpha is dropped from the constrained parameter vector).

B_constraints

a (d \times d) matrix with its entries imposing constraints on the impact matrix B_t: NA indicating that the element is unconstrained, a positive value indicating strict positive sign constraint, a negative value indicating strict negative sign constraint, and zero indicating that the element is constrained to zero. Currently only available for models with identification="heteroskedasticity" or "non-Gaussianity" due to the (in)availability of appropriate parametrizations that allow such constraints to be imposed.

other_constraints

A list containing internally used additional type of constraints (see the options below).

$fixed_lambdas (only if identification="heteroskedasticity"):

a length d(M-1) numeric vector (\lambda_{2},..., \lambda_{M}) with elements strictly larger than zero specifying the fixed parameter values for the parameters \lambda_{mi} should be constrained to.

$B1_constraints (only if identification="non-Gaussianity"):

set to the string "fixed_sign_and_order" to impose the constraints that the elements of the first impact matrix B_1 are strictly positive and that they are in a decreasing order.

to_return

should the returned object be the log-likelihood, which is the default, or something else? See the section "Value" for all the options.

check_params

should it be checked that the parameter vector satisfies the model assumptions? Can be skipped to save computation time if it does for sure.

penalized

Perform penalized LS estimation that minimizes penalized RSS in which estimates close to breaking or not satisfying the usual stability condition are penalized? If TRUE, the tuning parameter is set by the argument penalty_params[2], and the penalization starts when the eigenvalues of the companion form AR matrix are larger than 1 - penalty_params[1].

penalty_params

a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more).

allow_unstab

If TRUE, estimates not satisfying the stability condition are allowed. Always FALSE if weight_function="relative_dens".

bound_by_weights

should minval be returned if the transition weights do not allocate enough weights to a regime compared to the number of observations in the regime? See the source code for details.

indt_R

If TRUE calculates the independent Student's t density in R instead of C++ without any approximations employed for speed-up.

alt_par

If TRUE assumes that models identified by non-Gaussianiaty (or cond_dist="Student") are parametrized as B_{y,t}=B_1 + \sum_{m=2}^M\alpha_{m,t}B_m^*, where B_m^* = B_m - B_1.

minval

the value that will be returned if the parameter vector does not lie in the parameter space (excluding the identification condition).

stab_tol

numerical tolerance for stability of condition of the regimes: if the "bold A" matrix of any regime has eigenvalues larger that 1 - stat_tol the parameter is considered to be outside the parameter space. Note that if tolerance is too small, numerical evaluation of the log-likelihood might fail and cause error.

posdef_tol

numerical tolerance for positive definiteness of the error term covariance matrices: if the error term covariance matrix of any regime has eigenvalues smaller than this, the parameter is considered to be outside the parameter space. Note that if the tolerance is too small, numerical evaluation of the log-likelihood might fail and cause error.

distpar_tol

the parameter vector is considered to be outside the parameter space if the degrees of freedom parameters is not larger than 2 + distpar_tol (applies only if cond_dist="Student").

weightpar_tol

numerical tolerance for weight parameters being in the parameter space. Values closer to to the border of the parameter space than this are considered to be "outside" the parameter space.

Details

Calculates the log-likelihood of the specified model.

Value

If to_return="loglik":

the log-likelihood of the specified model.

If to_return=="tw":

a size [n_obs-p, M] matrix containing the transition weights: for m:th component in m:th column.

If to_return=="loglik_and_tw":

a list of two elements. The first element ($loglik) contains the log-likelihood and the second element ($tw) contains the transition weights.

If to_return=="terms":

a length n_obs-p numeric vector containing the terms l_{t}.

If to_return=="regime_cmeans":

an [n_obs-p, d, M] array containing the regimewise conditional means.

If to_return=="total_cmeans":

a [n_obs-p, d] matrix containing the conditional means of the process.

If to_return=="total_ccovs":

an [d, d, n_obs-p] array containing the conditional covariance matrices of the process.

If to_return=="B_t":

an [d, d, n_obs-p] array containing the impact matrices B_t of the process. Available only for models with cond_dist="ind_Student".

References

  • Anderson H., Vahid F. 1998. Testing multiple equation systems for common nonlinear components. Journal of Econometrics, 84:1, 1-36.

  • Hansen B.E. 1994. Autoregressive Conditional Density estimation. Journal of Econometrics, 35:3, 705-730.

  • Kheifets I.L., Saikkonen P.J. 2020. Stationarity and ergodicity of Vector STAR models. International Economic Review, 35:3, 407-414.

  • Lanne M., Virolainen S. 2025. A Gaussian smooth transition vector autoregressive model: An application to the macroeconomic effects of severe weather shocks. Unpublished working paper, available as arXiv:2403.14216.

  • Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis, Springer.

  • McElroy T. 2017. Computation of vector ARMA autocovariances. Statistics and Probability Letters, 124, 92-96.

  • Kilian L., Lütkepohl H. 20017. Structural Vector Autoregressive Analysis. 1st edition. Cambridge University Press, Cambridge.

  • Tsay R. 1998. Testing and Modeling Multivariate Threshold Models. Journal of the American Statistical Association, 93:443, 1188-1202.

  • Virolainen S. 2025. Identification by non-Gaussianity in structural threshold and smooth transition vector autoregressive models. Unpublished working paper, available as arXiv:2404.19707.


sstvars documentation built on April 11, 2025, 5:47 p.m.