# cond_moments: Compute conditional moments of a GMVAR, StMVAR, or G-StMVAR... In saviviro/gmvarkit: Estimate Gaussian or Student's t Mixture Vector Autoregressive Model

## Description

`loglikelihood` compute conditional regimewise means, conditional means, and conditional covariance matrices of a GMVAR, StMVAR, or G-StMVAR model.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17``` ```cond_moments( data, p, M, params, model = c("GMVAR", "StMVAR", "G-StMVAR"), parametrization = c("intercept", "mean"), constraints = NULL, same_means = NULL, structural_pars = NULL, to_return = c("regime_cmeans", "regime_ccovs", "total_cmeans", "total_ccovs", "arch_scalars"), minval = NA, stat_tol = 0.001, posdef_tol = 1e-08, df_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. `NA` values are not supported. `p` a positive integer specifying the autoregressive order of the model. `M` For GMVAR and StMVAR models:a positive integer specifying the number of mixture components. For G-StMVAR models:a size (2x1) integer vector specifying the number of GMVAR type components `M1` in the first element and StMVAR type components `M2` in the second element. The total number of mixture components is `M=M1+M2`. `params` a real valued vector specifying the parameter values. For unconstrained models: Should be size ((M(pd^2+d+d(d+1)/2+2)-M1-1)x1) and have the form θ = (υ_{1}, ...,υ_{M}, α_{1},...,α_{M-1},ν), where υ_{m} = (φ_{m,0},φ_{m},σ_{m}) φ_{m} = (vec(A_{m,1}),...,vec(A_{m,p}) and σ_{m} = vech(Ω_{m}), m=1,...,M, ν=(ν_{M1+1},...,ν_{M}) M1 is the number of GMVAR type regimes. For constrained models: Should be size ((M(d+d(d+1)/2+2)+q-M1-1)x1) and have the form θ = (φ_{1,0},...,φ_{M,0},ψ, σ_{1},...,σ_{M},α_{1},...,α_{M-1},ν), where ψ (qx1) satisfies (φ_{1},..., φ_{M}) = C ψ where C is a (Mpd^2xq) constraint matrix. For same_means models: Should have the form θ = (μ,ψ, σ_{1},...,σ_{M},α_{1},...,α_{M-1},ν), where μ= (μ_{1},...,μ_{g}) where μ_{i} is the mean parameter for group i and g is the number of groups. If AR constraints are employed, ψ is as for constrained models, and if AR constraints are not employed, ψ = (φ_{1},...,φ_{M}). For structural models: Should have the form θ = (φ_{1,0},...,φ_{M,0},φ_{1},...,φ_{M}, vec(W),λ_{2},...,λ_{M},α_{1},...,α_{M-1},ν), where λ_{m}=(λ_{m1},...,λ_{md}) contains the eigenvalues of the mth mixture component. If AR parameters are constrained: Replace φ_{1},..., φ_{M} with ψ (qx1) that satisfies (φ_{1},..., φ_{M}) = C ψ, as above. If same_means: Replace (φ_{1,0},...,φ_{M,0}) with (μ_{1},...,μ_{g}), as above. If W is constrained:Remove the zeros from vec(W) and make sure the other entries satisfy the sign constraints. If λ_{mi} are constrained:Replace λ_{2},...,λ_{M} with γ (rx1) that satisfies (λ_{2},..., λ_{M}) = C_{λ} γ where C_{λ} is a (d(M-1) x r) constraint matrix. Above, φ_{m,0} is the intercept parameter, A_{m,i} denotes the ith coefficient matrix of the mth mixture component, Ω_{m} denotes the error term covariance matrix of the m:th mixture component, and α_{m} is the mixing weight parameter. The W and λ_{mi} are structural parameters replacing the error term covariance matrices (see Virolainen, 2020). If M=1, α_{m} and λ_{mi} are dropped. If `parametrization=="mean"`, just replace each φ_{m,0} with regimewise mean μ_{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. In the GMVAR model, M1=M and ν is dropped from the parameter vector. In the StMVAR model, M1=0. In the G-StMVAR model, the first `M1` regimes are GMVAR type and the rest `M2` regimes are StMVAR type. In StMVAR and G-StMVAR models, the degrees of freedom parameters in ν should be strictly larger than two. The notation is similar to the cited literature. `model` is "GMVAR", "StMVAR", or "G-StMVAR" model considered? In the G-StMVAR model, the first `M1` components are GMVAR type and the rest `M2` components are StMVAR type. `parametrization` `"intercept"` or `"mean"` determining whether the model is parametrized with intercept parameters φ_{m,0} or regime means μ_{m}, m=1,...,M. `constraints` a size (Mpd^2 x q) constraint matrix C specifying general linear constraints to the autoregressive parameters. We consider constraints of form (φ_{1},...,φ_{M}) = C ψ, where φ_{m} = (vec(A_{m,1}),...,vec(A_{m,p}) (pd^2 x 1), m=1,...,M, contains the coefficient matrices and ψ (q x 1) contains the related parameters. For example, to restrict the AR-parameters to be the same for all regimes, set C= [`I:...:I`]' (Mpd^2 x pd^2) where `I = diag(p*d^2)`. Ignore (or set to `NULL`) if linear constraints should not be employed. `same_means` Restrict the mean parameters of some regimes to be the same? 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 the same 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"`. `structural_pars` If `NULL` a reduced form model is considered. For structural model, should be a list containing the following elements: `W` - a (dxd) matrix with its entries imposing constraints on W: `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. `C_lambda` - a (d(M-1) x r) constraint matrix that satisfies (λ_{2},..., λ_{M}) = C_{λ} γ where γ is the new (r x 1) parameter subject to which the model is estimated (similarly to AR parameter constraints). The entries of `C_lambda` must be either positive or zero. Ignore (or set to `NULL`) if the eigenvalues λ_{mi} should not be constrained. See Virolainen (2020) for the conditions required to identify the shocks and for the B-matrix as well (it is W times a time-varying diagonal matrix with positive diagonal entries). `to_return` should the regimewise conditional means, total conditional means, or total conditional covariance matrices be returned? `minval` the value that will be returned if the parameter vector does not lie in the parameter space (excluding the identification condition). `stat_tol` numerical tolerance for stationarity of the AR parameters: if the "bold A" matrix of any regime has eigenvalues larger that `1 - stat_tol` the model is classified as non-stationary. Note that if the 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 model is classified as not satisfying positive definiteness assumption. Note that if the tolerance is too small, numerical evaluation of the log-likelihood might fail and cause error. `df_tol` the parameter vector is considered to be outside the parameter space if all degrees of freedom parameters are not larger than `2 + df_tol`.

## Details

The first p values are used as the initial values, and by conditional we mean conditioning on the past. Formulas for the conditional means and covariance matrices are given in equations (3) and (4) of KMS (2016).

## Value

 `If to_return=="regime_cmeans":` an `[T-p, d, M]` array containing the regimewise conditional means (the first p values are used as the initial values). `If to_return=="regime_ccovs":` an `[d, d, T-p, M]` array containing the regimewise conditional covariance matrices (the first p values are used as the initial values). The index `[ , , t, m]` gives the time `t` conditional covariance matrix for the regime `m`. `If to_return=="total_cmeans":` a `[T-p, d]` matrix containing the conditional means of the process (the first p values are used as the initial values). `If to_return=="total_ccov":` an `[d, d, T-p]` array containing the conditional covariance matrices of the process (the first p values are used as the initial values). `If to_return=="arch_scalars":` a `[T-p, M]` matrix containing the regimewise arch scalars multiplying error term covariance matrix in the conditional covariance matrix of the regime. For GMVAR type regimes, these are all ones (the first p values are used as the initial values).

## References

• Kalliovirta L., Meitz M. and Saikkonen P. 2016. Gaussian mixture vector autoregression. Journal of Econometrics, 192, 485-498.

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

• Virolainen S. 2020. Structural Gaussian mixture vector autoregressive model. Unpublished working paper, available as arXiv:2007.04713.

• Virolainen S. 2021. Gaussian and Student's t mixture vector autoregressive model. Unpublished working paper, available as arXiv:2109.13648.

Other moment functions: `get_regime_autocovs()`, `get_regime_means()`, `uncond_moments()`
 ```1 2 3 4 5 6 7``` ```# GMVAR(2, 2), d=2 model; params22 <- c(0.36, 0.121, 0.223, 0.059, -0.151, 0.395, 0.406, -0.005, 0.083, 0.299, 0.215, 0.002, 0.03, 0.484, 0.072, 0.218, 0.02, -0.119, 0.722, 0.093, 0.032, 0.044, 0.191, 1.101, -0.004, 0.105, 0.58) cond_moments(data=gdpdef, p=2, M=2, params=params22, to_return="regime_cmeans") cond_moments(data=gdpdef, p=2, M=2, params=params22, to_return="total_cmeans") cond_moments(data=gdpdef, p=2, M=2, params=params22, to_return="total_ccovs") ```