Title: | Estimate Univariate Gaussian and Student's t Mixture Autoregressive Models |
---|---|
Description: | Maximum likelihood estimation of univariate Gaussian Mixture Autoregressive (GMAR), Student's t Mixture Autoregressive (StMAR), and Gaussian and Student's t Mixture Autoregressive (G-StMAR) models, quantile residual tests, graphical diagnostics, forecast and simulate from GMAR, StMAR and G-StMAR processes. Leena Kalliovirta, Mika Meitz, Pentti Saikkonen (2015) <doi:10.1111/jtsa.12108>, Mika Meitz, Daniel Preve, Pentti Saikkonen (2023) <doi:10.1080/03610926.2021.1916531>, Savi Virolainen (2022) <doi:10.1515/snde-2020-0060>. |
Authors: | Savi Virolainen [aut, cre] |
Maintainer: | Savi Virolainen <[email protected]> |
License: | GPL-3 |
Version: | 3.5.0 |
Built: | 2024-11-01 04:39:33 UTC |
Source: | https://github.com/saviviro/ugmar |
uGMAR
is a package for estimating univariate Gaussian mixture autoregressive (GMAR),
Student's t mixture autoregressive (StMAR), and Gaussian and Student's t mixture autoregressive (G-StMAR) models.
In addition to unconstrained and constrained estimation, uGMAR
provides tools for quantile residual based model
diagnostics, forecasting, simulation, and more.
The readme file or the vignette is a good place to start.
Maintainer: Savi Virolainen [email protected]
Useful links:
Report bugs at https://github.com/saviviro/uGMAR/issues
add_data
adds or updates data to object of class 'gsmar
' that defines a GMAR, StMAR,
or G-StMAR model. Also calculates empirical mixing weights, conditional moments, and quantile residuals accordingly.
add_data( data, gsmar, calc_qresiduals = TRUE, calc_cond_moments = TRUE, calc_std_errors = FALSE, custom_h = NULL )
add_data( data, gsmar, calc_qresiduals = TRUE, calc_cond_moments = TRUE, calc_std_errors = FALSE, custom_h = NULL )
data |
a numeric vector or class |
gsmar |
a class 'gsmar' object, typically generated by |
calc_qresiduals |
should quantile residuals be calculated? Default is |
calc_cond_moments |
should conditional means and variances be calculated? Default is |
calc_std_errors |
should approximate standard errors be calculated? |
custom_h |
A numeric vector with same the length as the parameter vector: i:th element of custom_h is the difference
used in central difference approximation for partial differentials of the log-likelihood function for the i:th parameter.
If |
Returns an object of class 'gsmar' defining the GMAR, StMAR, or G-StMAR model with the data added to the model. If the object already contained data, the data will be updated. Does not modify the 'gsmar' object given as argument!
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
fitGSMAR
, GSMAR
, iterate_more
, get_gradient
,
get_regime_means
, swap_parametrization
, stmar_to_gstmar
# G-StMAR model without data params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) gstmar42 <- GSMAR(p=4, M=c(1, 1), params=params42gs, model="G-StMAR") gstmar42 # Add data to the model gstmar42 <- add_data(data=M10Y1Y, gsmar=gstmar42) gstmar42
# G-StMAR model without data params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) gstmar42 <- GSMAR(p=4, M=c(1, 1), params=params42gs, model="G-StMAR") gstmar42 # Add data to the model gstmar42 <- add_data(data=M10Y1Y, gsmar=gstmar42) gstmar42
fitGSMAR
alt_gsmar
constructs a GSMAR model based on results from an arbitrary estimation round of fitGSMAR
.
alt_gsmar( gsmar, which_round = 1, which_largest, calc_qresiduals = TRUE, calc_cond_moments = TRUE, calc_std_errors = TRUE, custom_h = NULL )
alt_gsmar( gsmar, which_round = 1, which_largest, calc_qresiduals = TRUE, calc_cond_moments = TRUE, calc_std_errors = TRUE, custom_h = NULL )
gsmar |
a class 'gsmar' object, typically generated by |
which_round |
based on which estimation round should the model be constructed? An integer value in 1,..., |
which_largest |
based on estimation round with which largest log-likelihood should the model be constructed?
An integer value in 1,..., |
calc_qresiduals |
should quantile residuals be calculated? Default is |
calc_cond_moments |
should conditional means and variances be calculated? Default is |
calc_std_errors |
should approximate standard errors be calculated? |
custom_h |
A numeric vector with same the length as the parameter vector: i:th element of custom_h is the difference
used in central difference approximation for partial differentials of the log-likelihood function for the i:th parameter.
If |
It's sometimes useful to examine other estimates than the one with the highest log-likelihood value. This function
is just a simple wrapper to GSMAR
that picks the correct estimates from an object returned by fitGSMAR
.
In addition to the S3 methods listed under the topic "Methods (by generic)", the predict
and simulate
methods
are also available for the class 'gsmar' objects (see ?predict.gsmar
and ?simulate.gsmar
).
Returns an object of class 'gsmar'
defining the specified GMAR, StMAR, or G-StMAR model. If data is supplied,
the returned object contains (by default) empirical mixing weights, some conditional and unconditional moments, and quantile
residuals. Note that the first p observations are taken as the initial values so the mixing weights, conditional moments, and
quantile residuals start from the p+1:th observation (interpreted as t=1).
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
fitGSMAR
, GSMAR
, iterate_more
, get_gradient
,
get_regime_means
, swap_parametrization
, stmar_to_gstmar
# These are long running examples that take approximately ... fit42t <- fitGSMAR(data=M10Y1Y, p=4, M=2, model="StMAR", ncalls=2, seeds=c(1, 6)) fit42t # Bad estimate in the boundary of the stationarity region! # So we build a model based on the next-best local maximum point: fit42t_alt <- alt_gsmar(fit42t, which_largest=2) fit42t_alt # Overly large degrees of freedom paramter estimate # Switch to the appropriate G-StMAR model: fit42gs <- stmar_to_gstmar(fit42t_alt) fit42gs
# These are long running examples that take approximately ... fit42t <- fitGSMAR(data=M10Y1Y, p=4, M=2, model="StMAR", ncalls=2, seeds=c(1, 6)) fit42t # Bad estimate in the boundary of the stationarity region! # So we build a model based on the next-best local maximum point: fit42t_alt <- alt_gsmar(fit42t, which_largest=2) fit42t_alt # Overly large degrees of freedom paramter estimate # Switch to the appropriate G-StMAR model: fit42gs <- stmar_to_gstmar(fit42t_alt) fit42gs
calc_gradient
or calc_hessian
calculates the gradient or Hessian matrix
of the given function at the given point using central difference numerical approximation.
get_gradient
(and get_foc
) or get_hessian
calculates the gradient or Hessian matrix of the
log-likelihood function at the parameter values of a class 'gsmar'
object.
get_soc
returns eigenvalues of the Hessian matrix.
calc_gradient(x, fn, h = 6e-06, varying_h = NULL, ...) calc_hessian(x, fn, h = 6e-06, varying_h = NULL, ...) get_gradient(gsmar, custom_h = NULL) get_foc(gsmar, custom_h = NULL) get_hessian(gsmar, custom_h = NULL) get_soc(gsmar, custom_h = NULL)
calc_gradient(x, fn, h = 6e-06, varying_h = NULL, ...) calc_hessian(x, fn, h = 6e-06, varying_h = NULL, ...) get_gradient(gsmar, custom_h = NULL) get_foc(gsmar, custom_h = NULL) get_hessian(gsmar, custom_h = NULL) get_soc(gsmar, custom_h = NULL)
x |
a numeric vector specifying the point at which the gradient or Hessian should be evaluated. |
fn |
a function that takes in the argument |
h |
the difference used to approximate the derivatives. |
varying_h |
a numeric vector with the same length as |
... |
other arguments passed to |
gsmar |
a class 'gsmar' object, typically generated by |
custom_h |
same as |
In particular, the functions get_foc
and get_soc
can be used to check whether
the found estimates denote a (local) maximum point, a saddle point, or something else.
The gradient functions return numerical approximation of the gradient, and the Hessian functions return
numerical approximation of the Hessian. get_soc
returns eigenvalues of the Hessian matrix, get_foc
is the same as get_gradient
but named conveniently.
No argument checks!
# Simple function foo <- function(x) x^2 + x calc_gradient(x=1, fn=foo) calc_gradient(x=-0.5, fn=foo) calc_hessian(x=2, fn=foo) # More complicated function foo <- function(x, a, b) a*x[1]^2 - b*x[2]^2 calc_gradient(x=c(1, 2), fn=foo, a=0.3, b=0.1) calc_hessian(x=c(1, 2), fn=foo, a=0.3, b=0.1) # GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR") get_gradient(gmar12) get_foc(gmar12) get_hessian(gmar12) get_soc(gmar12)
# Simple function foo <- function(x) x^2 + x calc_gradient(x=1, fn=foo) calc_gradient(x=-0.5, fn=foo) calc_hessian(x=2, fn=foo) # More complicated function foo <- function(x, a, b) a*x[1]^2 - b*x[2]^2 calc_gradient(x=c(1, 2), fn=foo, a=0.3, b=0.1) calc_hessian(x=c(1, 2), fn=foo, a=0.3, b=0.1) # GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR") get_gradient(gmar12) get_foc(gmar12) get_hessian(gmar12) get_soc(gmar12)
cond_moment_plot
plots the one-step in-sample conditional means/variances of the model along with
the time series contained in the model (e.g. the time series the model was fitted to). Also plots
the regimewise conditional means/variances multiplied with the mixing weights.
cond_moment_plot(gsmar, which_moment = c("mean", "variance"))
cond_moment_plot(gsmar, which_moment = c("mean", "variance"))
gsmar |
a class 'gsmar' object, typically generated by |
which_moment |
should conditional means or variances be plotted? |
The conditional mean plot works best if the data contains positive values only.
cond_moment_plot
only plots to a graphical device and does not return anything. Numerical values
of the conditional means/variances can be extracted from the model with the dollar sign.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
profile_logliks
, diagnostic_plot
, fitGSMAR
, GSMAR
, quantile_residual_tests
,
quantile_residual_plot
# GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR") cond_moment_plot(gmar12, which_moment="mean") cond_moment_plot(gmar12, which_moment="variance") # G-StMAR model params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) gstmar42 <- GSMAR(data=M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR") cond_moment_plot(gstmar42, which_moment="mean") cond_moment_plot(gstmar42, which_moment="variance")
# GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR") cond_moment_plot(gmar12, which_moment="mean") cond_moment_plot(gmar12, which_moment="variance") # G-StMAR model params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) gstmar42 <- GSMAR(data=M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR") cond_moment_plot(gstmar42, which_moment="mean") cond_moment_plot(gstmar42, which_moment="variance")
cond_moments
calculates the regime specific conditional means and variances and total
conditional means and variances of the specified GMAR, StMAR or G-StMAR model.
cond_moments( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean"), to_return = c("regime_cmeans", "regime_cvars", "total_cmeans", "total_cvars") )
cond_moments( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean"), to_return = c("regime_cmeans", "regime_cvars", "total_cmeans", "total_cvars") )
data |
a numeric vector or class |
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
parametrization |
is the model parametrized with the "intercepts" |
to_return |
calculate regimewise conditional means ( |
Note that the first p observations are taken as the initial values so the conditional moments start form the p+1:th observation (interpreted as t=1).
to_return=="regime_cmeans"
:a size ((n_obs-p)xM) matrix containing the regime specific conditional means.
to_return=="regime_cvars"
:a size ((n_obs-p)xM) matrix containing the regime specific conditional variances.
to_return=="total_cmeans"
:a size ((n_obs-p)x1) vector containing the total conditional means.
to_return=="total_cvars"
:a size ((n_obs-p)x1) vector containing the total conditional variances.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
Other moment functions:
get_regime_autocovs()
,
get_regime_means()
,
get_regime_vars()
,
uncond_moments()
# GMAR model, regimewise conditional means and variances params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) cond_moments(simudata, p=1, M=2, params=params12, model="GMAR", to_return="regime_cmeans") cond_moments(simudata, p=1, M=2, params=params12, model="GMAR", to_return="regime_cvars") # G-StMAR-model, total conditional means and variances params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) cond_moments(M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR", to_return="total_cmeans") cond_moments(M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR", to_return="total_cvars")
# GMAR model, regimewise conditional means and variances params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) cond_moments(simudata, p=1, M=2, params=params12, model="GMAR", to_return="regime_cmeans") cond_moments(simudata, p=1, M=2, params=params12, model="GMAR", to_return="regime_cvars") # G-StMAR-model, total conditional means and variances params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) cond_moments(M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR", to_return="total_cmeans") cond_moments(M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR", to_return="total_cvars")
cond_moment_plot
INSTEAD! Conditional mean or variance plot for GMAR, StMAR, and G-StMAR modelscondmomentPlot
plots the one-step in-sample conditional means/variances of the model along with
the time series contained in the model (e.g. the time series the model was fitted to). Also plots
the regimewise conditional means/variances multiplied with the mixing weights.
DEPRECATED, USE cond_moment_plot
INSTEAD!
condmomentPlot(gsmar, which_moment = c("mean", "variance"))
condmomentPlot(gsmar, which_moment = c("mean", "variance"))
gsmar |
a class 'gsmar' object, typically generated by |
which_moment |
should conditional means or variances be plotted? |
DEPRECATED, USE cond_moment_plot
INSTEAD!
cond_moment_plot
only plots to a graphical device and does not return anything. Numerical values
of the conditional means/variances can be extracted from the model with the dollar sign.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
profile_logliks
, diagnostic_plot
, fitGSMAR
, GSMAR
, quantile_residual_tests
,
quantileResidualPlot
cond_moments
INSTEAD! Calculate conditional moments of GMAR, StMAR, or G-StMAR modelcondMoments
calculates the regime specific conditional means and variances and total
conditional means and variances of the specified GMAR, StMAR or G-StMAR model.
DEPRECATED, USE cond_moments
INSTEAD!
condMoments( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean"), to_return = c("regime_cmeans", "regime_cvars", "total_cmeans", "total_cvars") )
condMoments( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean"), to_return = c("regime_cmeans", "regime_cvars", "total_cmeans", "total_cvars") )
data |
a numeric vector or class |
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
parametrization |
is the model parametrized with the "intercepts" |
to_return |
calculate regimewise conditional means ( |
Note that the first p observations are taken as the initial values so the conditional moments start form the p+1:th observation (interpreted as t=1).
to_return=="regime_cmeans"
:a size ((n_obs-p)xM) matrix containing the regime specific conditional means.
to_return=="regime_cvars"
:a size ((n_obs-p)xM) matrix containing the regime specific conditional variances.
to_return=="total_cmeans"
:a size ((n_obs-p)x1) vector containing the total conditional means.
to_return=="total_cvars"
:a size ((n_obs-p)x1) vector containing the total conditional variances.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
diagnostic_plot
plots quantile residual time series, normal QQ-plot, autocorrelation function,
and squared quantile residual autocorrelation function. There is an option to also plot the individual statistics
associated with the quantile residual tests (for autocorrelation and conditional heteroskedasticity) divided by
their approximate standard errors with their approximate 95% critical bounds (see Kalliovirta 2012, Section 3).
diagnostic_plot(gsmar, nlags = 20, nsimu = 1, plot_indstats = FALSE)
diagnostic_plot(gsmar, nlags = 20, nsimu = 1, plot_indstats = FALSE)
gsmar |
a class 'gsmar' object, typically generated by |
nlags |
a positive integer specifying how many lags should be calculated for the autocorrelation and conditional heteroscedasticity statistics. |
nsimu |
a positive integer specifying to how many simulated values from the process the covariance
matrix "Omega" (used to compute the tests) should be based on. Larger number of simulations may result
more reliable tests but takes longer to compute. If smaller than data size, then "Omega" will be based
on the given data. Ignored if |
plot_indstats |
set |
Sometimes the individual statistics are not plotted because it was not (numerically) possible to calculate all the required statistics. This may suggest that the model is misspecified.
The dashed lines plotted with autocorrelation functions (for quantile residuals and their squares) are
plus-minus where
is the sample size (minus the
initial values for
conditional models).
diagnostic_plot
only plots to a graphical device and does not return anything. Use the
function quantile_residual_tests
in order to obtain the individual statistics.
Install the suggested package "gsl" for faster evaluations in the cases of StMAR and G-StMAR models. For large StMAR and G-StMAR models with large data the calculations to obtain the individual statistics may take a significantly long time without the package "gsl".
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
profile_logliks
, get_foc
, fitGSMAR
, cond_moment_plot
, quantile_residual_tests
,
quantile_residual_plot
, simulate.gsmar
, LR_test
, Wald_test
## The below examples the approximately 30 seconds to run. # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) diagnostic_plot(fit42gs) # Restricted StMAR model: plot also the individual statistics with # their approximate critical bounds using the given data (and not # simulation procedure) fit42tr <- fitGSMAR(M10Y1Y, p=4, M=2, model="StMAR", restricted=TRUE, ncalls=1, seeds=1) diagnostic_plot(fit42tr, nlags=10, nsimu=1, plot_indstats=TRUE) # GMAR model, plot 30 lags. fit12 <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) diagnostic_plot(fit12, nlags=30)
## The below examples the approximately 30 seconds to run. # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) diagnostic_plot(fit42gs) # Restricted StMAR model: plot also the individual statistics with # their approximate critical bounds using the given data (and not # simulation procedure) fit42tr <- fitGSMAR(M10Y1Y, p=4, M=2, model="StMAR", restricted=TRUE, ncalls=1, seeds=1) diagnostic_plot(fit42tr, nlags=10, nsimu=1, plot_indstats=TRUE) # GMAR model, plot 30 lags. fit12 <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) diagnostic_plot(fit12, nlags=30)
diagnostic_plot
INSTEAD! Quantile residual based diagnostic plots for GMAR, StMAR, and G-StMAR modelsdiagnosticPlot
plots quantile residual time series, normal QQ-plot, autocorrelation function,
and squared quantile residual autocorrelation function. There is an option to also plot the individual statistics
associated with the quantile residual tests (for autocorrelation and conditional heteroskedasticity) divided by
their approximate standard errors with their approximate 95% critical bounds (see Kalliovirta 2012, Section 3).
DEPRECATED, USE diagnostic_plot
INSTEAD!
diagnosticPlot(gsmar, nlags = 20, nsimu = 1, plot_indstats = FALSE)
diagnosticPlot(gsmar, nlags = 20, nsimu = 1, plot_indstats = FALSE)
gsmar |
a class 'gsmar' object, typically generated by |
nlags |
a positive integer specifying how many lags should be calculated for the autocorrelation and conditional heteroscedasticity statistics. |
nsimu |
a positive integer specifying to how many simulated values from the process the covariance
matrix "Omega" (used to compute the tests) should be based on. Larger number of simulations may result
more reliable tests but takes longer to compute. If smaller than data size, then "Omega" will be based
on the given data. Ignored if |
plot_indstats |
set |
DEPRECATED, USE diagnostic_plot
INSTEAD!
Sometimes the individual statistics are not plotted because it was not (numerically) possible to calculate all the required statistics. This may suggest that the model is misspecified.
The dashed lines plotted with autocorrelation functions (for quantile residuals and their squares) are
plus-minus where
is the sample size (minus the
initial values for
conditional models).
diagnostic_plot
only plots to a graphical device and does not return anything. Use the
function quantile_residual_tests
in order to obtain the individual statistics.
Install the suggested package "gsl" for faster evaluations in the cases of StMAR and G-StMAR models. For large StMAR and G-StMAR models with large data the calculations to obtain the individual statistics may take a significantly long time without the package "gsl".
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
profile_logliks
, get_foc
, fitGSMAR
, cond_moment_plot
, quantile_residual_tests
,
quantile_residual_plot
, simulate.gsmar
, LR_test
, Wald_test
fitGSMAR
estimates GMAR, StMAR, or G-StMAR model in two phases. In the first phase, a genetic algorithm is employed
to find starting values for a gradient based method. In the second phase, the gradient based variable metric algorithm is utilized to
accurately converge to a local maximum or a saddle point near each starting value. Parallel computing is used to conduct multiple
rounds of estimations in parallel.
fitGSMAR( data, p, M, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, conditional = TRUE, parametrization = c("intercept", "mean"), ncalls = round(10 + 9 * log(sum(M))), ncores = 2, maxit = 500, seeds = NULL, print_res = TRUE, filter_estimates = TRUE, ... )
fitGSMAR( data, p, M, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, conditional = TRUE, parametrization = c("intercept", "mean"), ncalls = round(10 + 9 * log(sum(M))), ncores = 2, maxit = 500, seeds = NULL, print_res = TRUE, filter_estimates = TRUE, ... )
data |
a numeric vector or class |
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
conditional |
a logical argument specifying whether the conditional or exact log-likelihood function should be used. |
parametrization |
is the model parametrized with the "intercepts" |
ncalls |
a positive integer specifying how many rounds of estimation should be conducted. The estimation results may vary from round to round because of multimodality of the log-likelihood function and the randomness associated with the genetic algorithm. |
ncores |
the number of CPU cores to be used in the estimation process. |
maxit |
the maximum number of iterations for the variable metric algorithm. |
seeds |
a length |
print_res |
should the estimation results be printed? |
filter_estimates |
should likely inappropriate estimates be filtered? See details. |
... |
additional settings passed to the function |
Because of complexity and multimodality of the log-likelihood function, it's not guaranteed that the estimation algorithm will end up in the global maximum point. It's often expected that most of the estimation rounds will end up in some local maximum point instead, and therefore a number of estimation rounds is required for reliable results. Because of the nature of the models, the estimation may fail particularly in the cases where the number of mixture components is chosen too large. Note that the genetic algorithm is designed to avoid solutions with mixing weights of some regimes too close to zero at almost all times ("redundant regimes") but the settings can, however, be adjusted (see ?GAfit).
If the iteration limit for the variable metric algorithm (maxit
) is reached, one can continue the estimation by
iterating more with the function iterate_more
.
The core of the genetic algorithm is mostly based on the description by Dorsey and Mayer (1995). It utilizes a slightly modified version the individually adaptive crossover and mutation rates described by Patnaik and Srinivas (1994) and employs (50%) fitness inheritance discussed by Smith, Dike and Stegmann (1995). Large (in absolute value) but stationary AR parameter values are generated with the algorithm proposed by Monahan (1984).
The variable metric algorithm (or quasi-Newton method, Nash (1990, algorithm 21)) used in the second phase is implemented
with function the optim
from the package stats
.
Additional Notes about the estimates:
Sometimes the found MLE is very close to the boundary of the stationarity region some regime, the related variance parameter
is very small, and the associated mixing weights are "spiky". This kind of estimates often maximize the log-likelihood function
for a technical reason that induces by the endogenously determined mixing weights. In such cases, it might be more appropriate
to consider the next-best local maximum point of the log-likelihood function that is well inside the parameter space. Models based
local-only maximum points can be built with the function alt_gsmar
by adjusting the argument which_largest
accordingly.
Some mixture components of the StMAR model may sometimes get very large estimates for the degrees of freedom parameters.
Such parameters are weakly identified and induce various numerical problems. However, mixture components with large degree
of freedom parameter estimates are similar to the mixture components of the GMAR model. It's hence advisable to further
estimate a G-StMAR model by allowing the mixture components with large degrees of freedom parameter estimates to be GMAR
type with the function stmar_to_gstmar
.
Filtering inappropriate estimates: If filter_estimates == TRUE
, the function will automatically filter
out estimates that it deems "inappropriate". That is, estimates that are not likely solutions of interest.
Specifically, it filters out solutions that incorporate regimes with any modulus of the roots of the AR polynomial less
than ; a variance parameter estimat near zero (less than
);
mixing weights such that they are close to zero for almost all
for at least one regime; or mixing weight parameter
estimate close to zero (or one). You can also set
filter_estimates=FALSE
and find the solutions of interest yourself
by using the function alt_gsmar
.
Returns an object of class 'gsmar'
defining the estimated GMAR, StMAR or G-StMAR model. The returned object contains
estimated mixing weights, some conditional and unconditional moments, and quantile residuals. Note that the first p
observations are taken as the initial values, so the mixing weights, conditional moments, and quantile residuals start from
the p+1
:th observation (interpreted as t=1). In addition, the returned object contains the estimates and log-likelihoods
from all of the estimation rounds. See ?GSMAR
for the form of the parameter vector, if needed.
The following S3 methods are supported for class 'gsmar'
objects: print
, summary
, plot
,
predict
, simulate
, logLik
, residuals
.
Dorsey R. E. and Mayer W. J. 1995. Genetic algorithms for estimation problems with multiple optima, nondifferentiability, and other irregular features. Journal of Business & Economic Statistics, 13, 53-66.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Monahan J.F. 1984. A Note on Enforcing Stationarity in Autoregressive-Moving Average Models. Biometrica 71, 403-404.
Nash J. 1990. Compact Numerical Methods for Computers. Linear algebra and Function Minimization. Adam Hilger.
Patnaik L.M. and Srinivas M. 1994. Adaptive Probabilities of Crossover and Mutation in Genetic Algorithms. Transactions on Systems, Man and Cybernetics 24, 656-667.
Smith R.E., Dike B.A., Stegmann S.A. 1995. Fitness inheritance in genetic algorithms. Proceedings of the 1995 ACM Symposium on Applied Computing, 345-350.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
GSMAR
, iterate_more
, , stmar_to_gstmar
, add_data
,
profile_logliks
, swap_parametrization
, get_gradient
, simulate.gsmar
,
predict.gsmar
, diagnostic_plot
, quantile_residual_tests
, cond_moments
,
uncond_moments
, LR_test
, Wald_test
## These are long running examples that use parallel computing. ## The below examples take approximately 90 seconds to run. ## Note that the number of estimation rounds (ncalls) is relatively small ## in the below examples to reduce the time required for running the examples. ## For reliable results, a large number of estimation rounds is recommended! # GMAR model fit12 <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", ncalls=4, seeds=1:4) summary(fit12) plot(fit12) profile_logliks(fit12) diagnostic_plot(fit12) # StMAR model (large estimate of the degrees of freedom) fit42t <- fitGSMAR(data=M10Y1Y, p=4, M=2, model="StMAR", ncalls=2, seeds=c(1, 6)) summary(fit42t) # Overly large 2nd regime degrees of freedom estimate! fit42gs <- stmar_to_gstmar(fit42t) # Switch to G-StMAR model summary(fit42gs) # An appropriate G-StMVAR model with one G and one t regime plot(fit42gs) # Restricted StMAR model fit42r <- fitGSMAR(M10Y1Y, p=4, M=2, model="StMAR", restricted=TRUE, ncalls=2, seeds=1:2) fit42r # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) fit42gs # The following three examples demonstrate how to apply linear constraints # to the autoregressive (AR) parameters. # Two-regime GMAR p=2 model with the second AR coeffiecient of # of the second regime contrained to zero. C22 <- list(diag(1, ncol=2, nrow=2), as.matrix(c(1, 0))) fit22c <- fitGSMAR(M10Y1Y, p=2, M=2, constraints=C22, ncalls=1, seeds=6) fit22c # StMAR(3, 1) model with the second order AR coefficient constrained to zero. C31 <- list(matrix(c(1, 0, 0, 0, 0, 1), ncol=2)) fit31tc <- fitGSMAR(M10Y1Y, p=3, M=1, model="StMAR", constraints=C31, ncalls=1, seeds=1) fit31tc # Such StMAR(3, 2) model that the AR coefficients are restricted to be # the same for both regimes and the second AR coefficients are # constrained to zero. fit32rc <- fitGSMAR(M10Y1Y, p=3, M=2, model="StMAR", restricted=TRUE, constraints=matrix(c(1, 0, 0, 0, 0, 1), ncol=2), ncalls=1, seeds=1) fit32rc
## These are long running examples that use parallel computing. ## The below examples take approximately 90 seconds to run. ## Note that the number of estimation rounds (ncalls) is relatively small ## in the below examples to reduce the time required for running the examples. ## For reliable results, a large number of estimation rounds is recommended! # GMAR model fit12 <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", ncalls=4, seeds=1:4) summary(fit12) plot(fit12) profile_logliks(fit12) diagnostic_plot(fit12) # StMAR model (large estimate of the degrees of freedom) fit42t <- fitGSMAR(data=M10Y1Y, p=4, M=2, model="StMAR", ncalls=2, seeds=c(1, 6)) summary(fit42t) # Overly large 2nd regime degrees of freedom estimate! fit42gs <- stmar_to_gstmar(fit42t) # Switch to G-StMAR model summary(fit42gs) # An appropriate G-StMVAR model with one G and one t regime plot(fit42gs) # Restricted StMAR model fit42r <- fitGSMAR(M10Y1Y, p=4, M=2, model="StMAR", restricted=TRUE, ncalls=2, seeds=1:2) fit42r # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) fit42gs # The following three examples demonstrate how to apply linear constraints # to the autoregressive (AR) parameters. # Two-regime GMAR p=2 model with the second AR coeffiecient of # of the second regime contrained to zero. C22 <- list(diag(1, ncol=2, nrow=2), as.matrix(c(1, 0))) fit22c <- fitGSMAR(M10Y1Y, p=2, M=2, constraints=C22, ncalls=1, seeds=6) fit22c # StMAR(3, 1) model with the second order AR coefficient constrained to zero. C31 <- list(matrix(c(1, 0, 0, 0, 0, 1), ncol=2)) fit31tc <- fitGSMAR(M10Y1Y, p=3, M=1, model="StMAR", constraints=C31, ncalls=1, seeds=1) fit31tc # Such StMAR(3, 2) model that the AR coefficients are restricted to be # the same for both regimes and the second AR coefficients are # constrained to zero. fit32rc <- fitGSMAR(M10Y1Y, p=3, M=2, model="StMAR", restricted=TRUE, constraints=matrix(c(1, 0, 0, 0, 0, 1), ncol=2), ncalls=1, seeds=1) fit32rc
GAfit
estimates specified GMAR, StMAR, or G-StMAR model using a genetic algorithm.
The employed genetic algorithm is designed to find starting values for gradient based methods.
GAfit( data, p, M, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean"), conditional = TRUE, ngen = 200, popsize, smart_mu = min(100, ceiling(0.5 * ngen)), mu_scale, sigma_scale, initpop = NULL, regime_force_scale = 1, red_criteria = c(0.05, 0.01), to_return = c("alt_ind", "best_ind"), minval, seed = NULL, ... )
GAfit( data, p, M, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean"), conditional = TRUE, ngen = 200, popsize, smart_mu = min(100, ceiling(0.5 * ngen)), mu_scale, sigma_scale, initpop = NULL, regime_force_scale = 1, red_criteria = c(0.05, 0.01), to_return = c("alt_ind", "best_ind"), minval, seed = NULL, ... )
data |
a numeric vector or class |
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
parametrization |
is the model parametrized with the "intercepts" |
conditional |
a logical argument specifying whether the conditional or exact log-likelihood function should be used. |
ngen |
a positive integer specifying the number of generations to be ran through in the genetic algorithm. |
popsize |
a positive even integer specifying the population size in the genetic algorithm.
Default is |
smart_mu |
a positive integer specifying the generation after which the random mutations in the genetic algorithm are "smart". This means that mutating individuals will mostly mutate fairly close (or partially close) to the best fitting individual so far. |
mu_scale |
a real valued vector of length two specifying the mean (the first element) and standard deviation (the second element)
of the normal distribution from which the |
sigma_scale |
a positive real number specifying the standard deviation of the (zero mean, positive only by taking absolute value)
normal distribution from which the component variance parameters are generated in the random mutations in the genetic algorithm.
Default is |
initpop |
a list of parameter vectors from which the initial population of the genetic algorithm will be generated from. The parameter vectors should be of form...
Symbol |
regime_force_scale |
a non-negative real number specifying how much should natural selection favor individuals
with less regimes that have almost all mixing weights (practically) at zero (see |
red_criteria |
a length 2 numeric vector specifying the criteria that is used to determine whether a regime is redundant or not.
Any regime |
to_return |
should the genetic algorithm return the best fitting individual which has the least "redundant" regimes ( |
minval |
a real number defining the minimum value of the log-likelihood function that will be considered.
Values smaller than this will be treated as they were |
seed |
a single value, interpreted as an integer, or NULL, that sets seed for the random number generator in the beginning of
the function call. If calling |
... |
We currently use this to catch deprecated arguments. |
The core of the genetic algorithm is mostly based on the description by Dorsey and Mayer (1995). It utilizes a slightly modified version of the individually adaptive crossover and mutation rates described by Patnaik and Srinivas (1994) and employs (50%) fitness inheritance discussed by Smith, Dike and Stegmann (1995). Large (in absolute value) but stationary AR parameter values are generated with the algorithm proposed by Monahan (1984).
By "redundant" or "wasted" regimes we mean regimes that have the time varying mixing weights basically at zero for all t. The model with redundant regimes would have approximately the same log-likelihood value without the redundant regimes and there is no purpose to have redundant regimes in the model.
Returns estimated parameter vector with the form described in initpop
.
Dorsey R. E. and Mayer W. J. 1995. Genetic algorithms for estimation problems with multiple optima, nondifferentiability, and other irregular features. Journal of Business & Economic Statistics, 13, 53-66.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Monahan J.F. 1984. A Note on Enforcing Stationarity in Autoregressive-Moving Average Models. Biometrica 71, 403-404.
Patnaik L.M. and Srinivas M. 1994. Adaptive Probabilities of Crossover and Mutation in Genetic Algorithms. Transactions on Systems, Man and Cybernetics 24, 656-667.
Smith R.E., Dike B.A., Stegmann S.A. 1995. Fitness inheritance in genetic algorithms. Proceedings of the 1995 ACM Symposium on Applied Computing, 345-350.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
## These are long running examples # Preliminary estimation of GMAR p=1, M=2, model with the genetic algorithm # using only 100 generations (200 is recommended): pars12_ga <- GAfit(data=simudata, p=1, M=2, model="GMAR", ngen=100, seed=1) pars12_ga # Returns a parameter vector, not a class 'gsmar' object.
## These are long running examples # Preliminary estimation of GMAR p=1, M=2, model with the genetic algorithm # using only 100 generations (200 is recommended): pars12_ga <- GAfit(data=simudata, p=1, M=2, model="GMAR", ngen=100, seed=1) pars12_ga # Returns a parameter vector, not a class 'gsmar' object.
get_ar_roots
calculates the absolute values of the roots of the AR
characteristic polynomials for each mixture component.
get_ar_roots(gsmar)
get_ar_roots(gsmar)
gsmar |
a class 'gsmar' object, typically generated by |
Returns a list with M
elements each containing the absolute values of the roots
of the AR characteristic polynomial corresponding to each mixture component.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR") get_ar_roots(gmar12)
params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR") get_ar_roots(gmar12)
get_regime_autocovs
calculates the first p regime specific autocovariances
for the given GMAR, StMAR, or G-StMAR model.
get_regime_autocovs(gsmar)
get_regime_autocovs(gsmar)
gsmar |
a class 'gsmar' object, typically generated by |
Returns a size matrix containing the first p autocovariances of the components processes:
i:th autocovariance in the i:th row and m:th component process in the m:th column.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis. Springer.
Other moment functions:
cond_moments()
,
get_regime_means()
,
get_regime_vars()
,
uncond_moments()
# GMAR model params13 <- c(1.4, 0.88, 0.26, 2.46, 0.82, 0.74, 5.0, 0.68, 5.2, 0.72, 0.2) gmar13 <- GSMAR(p=1, M=3, params=params13, model="GMAR") get_regime_autocovs(gmar13) # StMAR model params12t <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 100, 3.6) stmar12t <- GSMAR(p=1, M=2, params=params12t, model="StMAR") get_regime_autocovs(stmar12t) # G-StMAR model (similar to the StMAR model above) params12gs <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 3.6) gstmar12 <- GSMAR(p=1, M=c(1, 1), params=params12gs, model="G-StMAR") get_regime_autocovs(gstmar12)
# GMAR model params13 <- c(1.4, 0.88, 0.26, 2.46, 0.82, 0.74, 5.0, 0.68, 5.2, 0.72, 0.2) gmar13 <- GSMAR(p=1, M=3, params=params13, model="GMAR") get_regime_autocovs(gmar13) # StMAR model params12t <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 100, 3.6) stmar12t <- GSMAR(p=1, M=2, params=params12t, model="StMAR") get_regime_autocovs(stmar12t) # G-StMAR model (similar to the StMAR model above) params12gs <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 3.6) gstmar12 <- GSMAR(p=1, M=c(1, 1), params=params12gs, model="G-StMAR") get_regime_autocovs(gstmar12)
get_regime_means
calculates the regime means
for the given GMAR, StMAR, or G-StMAR model
get_regime_means(gsmar)
get_regime_means(gsmar)
gsmar |
a class 'gsmar' object, typically generated by |
Returns a length M
vector containing the regime mean in the m:th element.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
cond_moments
, uncond_moments
, get_regime_vars
,
get_regime_autocovs
Other moment functions:
cond_moments()
,
get_regime_autocovs()
,
get_regime_vars()
,
uncond_moments()
# GMAR model params13 <- c(1.4, 0.88, 0.26, 2.46, 0.82, 0.74, 5.0, 0.68, 5.2, 0.72, 0.2) gmar13 <- GSMAR(p=1, M=3, params=params13, model="GMAR") get_regime_means(gmar13) # StMAR model params12t <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 100, 3.6) stmar12t <- GSMAR(p=1, M=2, params=params12t, model="StMAR") get_regime_means(stmar12t) # G-StMAR model (similar to the StMAR model above) params12gs <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 3.6) gstmar12 <- GSMAR(p=1, M=c(1, 1), params=params12gs, model="G-StMAR") get_regime_means(gstmar12)
# GMAR model params13 <- c(1.4, 0.88, 0.26, 2.46, 0.82, 0.74, 5.0, 0.68, 5.2, 0.72, 0.2) gmar13 <- GSMAR(p=1, M=3, params=params13, model="GMAR") get_regime_means(gmar13) # StMAR model params12t <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 100, 3.6) stmar12t <- GSMAR(p=1, M=2, params=params12t, model="StMAR") get_regime_means(stmar12t) # G-StMAR model (similar to the StMAR model above) params12gs <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 3.6) gstmar12 <- GSMAR(p=1, M=c(1, 1), params=params12gs, model="G-StMAR") get_regime_means(gstmar12)
get_regime_vars
calculates the unconditional regime specific variances
for the given GMAR, StMAR, or G-StMAR model.
get_regime_vars(gsmar)
get_regime_vars(gsmar)
gsmar |
a class 'gsmar' object, typically generated by |
Returns a length M vector containing the unconditional variances of the components processes: m:th element for the m:th regime.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis. Springer.
Other moment functions:
cond_moments()
,
get_regime_autocovs()
,
get_regime_means()
,
uncond_moments()
# GMAR model params13 <- c(1.4, 0.88, 0.26, 2.46, 0.82, 0.74, 5.0, 0.68, 5.2, 0.72, 0.2) gmar13 <- GSMAR(p=1, M=3, params=params13, model="GMAR") get_regime_vars(gmar13) # StMAR model params12t <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 100, 3.6) stmar12t <- GSMAR(p=1, M=2, params=params12t, model="StMAR") get_regime_vars(stmar12t) # G-StMAR model (similar to the StMAR model above) params12gs <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 3.6) gstmar12 <- GSMAR(p=1, M=c(1, 1), params=params12gs, model="G-StMAR") get_regime_vars(gstmar12)
# GMAR model params13 <- c(1.4, 0.88, 0.26, 2.46, 0.82, 0.74, 5.0, 0.68, 5.2, 0.72, 0.2) gmar13 <- GSMAR(p=1, M=3, params=params13, model="GMAR") get_regime_vars(gmar13) # StMAR model params12t <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 100, 3.6) stmar12t <- GSMAR(p=1, M=2, params=params12t, model="StMAR") get_regime_vars(stmar12t) # G-StMAR model (similar to the StMAR model above) params12gs <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 3.6) gstmar12 <- GSMAR(p=1, M=c(1, 1), params=params12gs, model="G-StMAR") get_regime_vars(gstmar12)
GSMAR
creates an S3 object of class 'gsmar'
that defines a GMAR, StMAR, or G-StMAR model.
GSMAR( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, conditional = TRUE, parametrization = c("intercept", "mean"), calc_qresiduals, calc_cond_moments, calc_std_errors = FALSE, custom_h = NULL ) ## S3 method for class 'gsmar' logLik(object, ...) ## S3 method for class 'gsmar' residuals(object, ...) ## S3 method for class 'gsmar' summary(object, ..., digits = 2) ## S3 method for class 'gsmar' plot(x, ..., include_dens = TRUE) ## S3 method for class 'gsmar' print(x, ..., digits = 2, summary_print = FALSE)
GSMAR( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, conditional = TRUE, parametrization = c("intercept", "mean"), calc_qresiduals, calc_cond_moments, calc_std_errors = FALSE, custom_h = NULL ) ## S3 method for class 'gsmar' logLik(object, ...) ## S3 method for class 'gsmar' residuals(object, ...) ## S3 method for class 'gsmar' summary(object, ..., digits = 2) ## S3 method for class 'gsmar' plot(x, ..., include_dens = TRUE) ## S3 method for class 'gsmar' print(x, ..., digits = 2, summary_print = FALSE)
data |
a numeric vector or class |
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
conditional |
a logical argument specifying whether the conditional or exact log-likelihood function should be used. |
parametrization |
is the model parametrized with the "intercepts" |
calc_qresiduals |
should quantile residuals be calculated? Default is |
calc_cond_moments |
should conditional means and variances be calculated? Default is |
calc_std_errors |
should approximate standard errors be calculated? |
custom_h |
A numeric vector with same the length as the parameter vector: i:th element of custom_h is the difference
used in central difference approximation for partial differentials of the log-likelihood function for the i:th parameter.
If |
object |
object of class |
... |
in the plot method: arguments passed to the function |
digits |
number of digits to be printed (max 20) |
x |
object of class |
include_dens |
Plot also kernel density estimate of the data and model implied stationary density with regimewise densities? See the details. |
summary_print |
if set to |
Models can be built without data, e.q., in order to simulate from the process, but some things such as quantile residuals and conditional moments can't be calculated without data.
If include_dens == TRUE
, the kernel density estimate of the data is calculated
with the function density
from the package stats
. By default, the default
settings of that function are used, including the usage of Gaussian kernel. Use the dot
parameters to adjust the settings if desired.
By the model implied stationary density we mean the stationary one-dimensional mixture density of M regimes (see KMS 2015, Theorem 1 and the discussion following it for the Gaussian case and Theorem 2 in PMS 2018 for the Student's t case). The regimewise densities (i.e. each density 1,...,M in the stationary mixture density) are multiplied with the mixing weight parameters accordingly.
In the density plot black represents the kernel density estimate of the data, grey dashed line the model implied density, and the colored dotted lines the regime wise densities.
Returns an object of class 'gsmar'
defining the specified GMAR, StMAR, or G-StMAR model. If data is supplied,
the returned object contains (by default) empirical mixing weights, some conditional and unconditional moments, and quantile
residuals. Note that the first p observations are taken as the initial values so the mixing weights, conditional moments, and
quantile residuals start from the p+1:th observation (interpreted as t=1).
logLik(gsmar)
: Log-likelihood method
residuals(gsmar)
: residuals method to extract quantile residuals
summary(gsmar)
: summary method, standard errors in brackets
plot(gsmar)
: Plot method for class 'gsmar'
print(gsmar)
: print method
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
fitGSMAR
, iterate_more
, add_data
, stmar_to_gstmar
,
swap_parametrization
, get_gradient
, simulate.gsmar
,
predict.gsmar
, cond_moments
, uncond_moments
, LR_test
, Wald_test
# GMAR model without data params22 <- c(0.9, 0.4, 0.2, 0.5, 0.7, 0.5, -0.2, 0.7, 0.7) gmar22 <- GSMAR(p=2, M=2, params=params22, model="GMAR") gmar22 # StMAR model, without data params12t <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 300, 3.6) stmar12t <- GSMAR(p=1, M=2, params=params12t, model="StMAR") stmar12t # G-StMAR model with data params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) gstmar42 <- GSMAR(data=M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR") gstmar42 # Restricted G-StMAR model with data params42gsr <- c(0.13, 0.03, 1.29, -0.4, 0.25, -0.2, 0.03, 0.05, 0.51, 2.76) gstmar42r <- GSMAR(data=M10Y1Y, p=4, M=c(1, 1), params=params42gsr, model="G-StMAR", restricted=TRUE) gstmar42r
# GMAR model without data params22 <- c(0.9, 0.4, 0.2, 0.5, 0.7, 0.5, -0.2, 0.7, 0.7) gmar22 <- GSMAR(p=2, M=2, params=params22, model="GMAR") gmar22 # StMAR model, without data params12t <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 300, 3.6) stmar12t <- GSMAR(p=1, M=2, params=params12t, model="StMAR") stmar12t # G-StMAR model with data params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) gstmar42 <- GSMAR(data=M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR") gstmar42 # Restricted G-StMAR model with data params42gsr <- c(0.13, 0.03, 1.29, -0.4, 0.25, -0.2, 0.03, 0.05, 0.51, 2.76) gstmar42r <- GSMAR(data=M10Y1Y, p=4, M=c(1, 1), params=params42gsr, model="G-StMAR", restricted=TRUE) gstmar42r
is_stationary
checks the stationarity condition of the specified GMAR, StMAR, or G-StMAR model.
is_stationary( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL )
is_stationary( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL )
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
This function falsely returns FALSE
for stationary models when the parameter is extremely close
to the boundary of the stationarity region.
Returns TRUE
or FALSE
accordingly.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
# GMAR model params22 <- c(0.4, 0.39, 0.6, 0.3, 0.4, 0.1, 0.6, 0.3, 0.8) is_stationary(p=2, M=2, params=params22) # StMAR model params12t <- c(-0.3, 1, 0.9, 0.1, 0.8, 0.6, 0.7, 10, 12) is_stationary(p=1, M=2, params=params12t, model="StMAR") # G-StMAR model params12gs <- c(1, 0.1, 1, 2, 0.2, 2, 0.8, 20) is_stationary(p=1, M=c(1, 1), params=params12gs, model="G-StMAR") # Restricted GMAR model params13r <- c(0.1, 0.2, 0.3, -0.99, 0.1, 0.2, 0.3, 0.5, 0.3) is_stationary(p=1, M=3, params=params13r, restricted=TRUE) # Such StMAR(3, 2) that the AR coefficients are restricted to be the # same for both regimes and that the second AR coefficients are # constrained to zero. params32trc <- c(1, 2, 0.8, -0.3, 1, 2, 0.7, 11, 12) is_stationary(p=3, M=2, params=params32trc, model="StMAR", restricted=TRUE, constraints=matrix(c(1, 0, 0, 0, 0, 1), ncol=2))
# GMAR model params22 <- c(0.4, 0.39, 0.6, 0.3, 0.4, 0.1, 0.6, 0.3, 0.8) is_stationary(p=2, M=2, params=params22) # StMAR model params12t <- c(-0.3, 1, 0.9, 0.1, 0.8, 0.6, 0.7, 10, 12) is_stationary(p=1, M=2, params=params12t, model="StMAR") # G-StMAR model params12gs <- c(1, 0.1, 1, 2, 0.2, 2, 0.8, 20) is_stationary(p=1, M=c(1, 1), params=params12gs, model="G-StMAR") # Restricted GMAR model params13r <- c(0.1, 0.2, 0.3, -0.99, 0.1, 0.2, 0.3, 0.5, 0.3) is_stationary(p=1, M=3, params=params13r, restricted=TRUE) # Such StMAR(3, 2) that the AR coefficients are restricted to be the # same for both regimes and that the second AR coefficients are # constrained to zero. params32trc <- c(1, 2, 0.8, -0.3, 1, 2, 0.7, 11, 12) is_stationary(p=3, M=2, params=params32trc, model="StMAR", restricted=TRUE, constraints=matrix(c(1, 0, 0, 0, 0, 1), ncol=2))
is_stationary
INSTEAD! Check the stationary condition of specified GMAR, StMAR, or G-StMAR model.isStationary
checks the stationarity condition of the specified GMAR, StMAR, or G-StMAR model.
DEPRECATED, USE is_stationary
INSTEAD!
isStationary( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL )
isStationary( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL )
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
DEPRECATED, USE is_stationary
INSTEAD!
This function falsely returns FALSE
for stationary models when the parameter is extremely close
to the boundary of the stationarity region.
Returns TRUE
or FALSE
accordingly.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
iterate_more
uses a variable metric algorithm to finalize maximum likelihood
estimation of a GMAR, StMAR or G-StMAR model (object of class 'gsmar'
) which already has
preliminary estimates.
iterate_more(gsmar, maxit = 100, custom_h = NULL, calc_std_errors = TRUE)
iterate_more(gsmar, maxit = 100, custom_h = NULL, calc_std_errors = TRUE)
gsmar |
a class 'gsmar' object, typically generated by |
maxit |
the maximum number of iterations for the variable metric algorithm. |
custom_h |
A numeric vector with same the length as the parameter vector: i:th element of custom_h is the difference
used in central difference approximation for partial differentials of the log-likelihood function for the i:th parameter.
If |
calc_std_errors |
should approximate standard errors be calculated? |
The main purpose of iterate_more
is to provide a simple and convenient tool to finalize
the estimation when the maximum number of iterations is reached when estimating a model with the
main estimation function fitGSMAR
. iterate_more
is essentially a wrapper for the functions
optim
from the package stats
and GSMAR
from the package uGMAR
.
Returns an object of class 'gsmar'
defining the estimated model.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
fitGSMAR
, GSMAR
, stmar_to_gstmar
,
profile_logliks
, optim
# Estimate GMAR model with on only 1 iteration in variable metric algorithm fit12 <- fitGSMAR(simudata, p=1, M=2, maxit=1, ncalls=1, seeds=1) fit12 # Iterate more since iteration limit was reached fit12 <- iterate_more(fit12) fit12
# Estimate GMAR model with on only 1 iteration in variable metric algorithm fit12 <- fitGSMAR(simudata, p=1, M=2, maxit=1, ncalls=1, seeds=1) fit12 # Iterate more since iteration limit was reached fit12 <- iterate_more(fit12) fit12
loglikelihood
computes the log-likelihood of the specified GMAR, StMAR, or G-StMAR model.
Exists for convenience if one wants to for example plot profile log-likelihoods or employ other estimation algorithms.
Use minval
to control what happens when the parameter vector is outside the parameter space.
loglikelihood( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, conditional = TRUE, parametrization = c("intercept", "mean"), return_terms = FALSE, minval = NA )
loglikelihood( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, conditional = TRUE, parametrization = c("intercept", "mean"), return_terms = FALSE, minval = NA )
data |
a numeric vector or class |
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
conditional |
a logical argument specifying whether the conditional or exact log-likelihood function should be used. |
parametrization |
is the model parametrized with the "intercepts" |
return_terms |
should the terms |
minval |
this will be returned when the parameter vector is outside the parameter space and |
Returns the log-likelihood value or the terms described in return_terms
.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
fitGSMAR
, GSMAR
, quantile_residuals
,
mixing_weights
, calc_gradient
# GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) loglikelihood(simudata, p=1, M=2, params=params12, model="GMAR") # G-StMAR-model params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) loglikelihood(M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR")
# GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) loglikelihood(simudata, p=1, M=2, params=params12, model="GMAR") # G-StMAR-model params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) loglikelihood(M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR")
LR_test
performs a likelihood ratio test for a GMAR, StMAR, or G-StMAR model.
LR_test(gsmar1, gsmar2)
LR_test(gsmar1, gsmar2)
gsmar1 |
an object of class |
gsmar2 |
an object of class |
Performs a likelihood ratio test, testing the null hypothesis that the true parameter value lies
in the constrained parameter space specified by constraints imposed to the model gsmar2
.
Under the null, the test statistic is asymptotically -distributed with
degrees of freedom,
being the difference in the dimensions of the unconstrained and constrained parameter spaces.
Note that this function does not verify that the two models are actually nested. Notably, GSMAR models with different autoregressive orders are not nested, whereas testing models with different numbers of regimes induce an identification problem and thereby unreliable test results (see the discussion related to Theorem 2 in Virolainen, 2021).
A list with class "htest" containing the following components:
statistic |
the value of the likelihood ratio statistics. |
parameter |
the degrees of freedom of the likelihood ratio statistic. |
p.value |
the p-value of the test. |
alternative |
a character string describing the alternative hypothesis. |
method |
a character string indicating the type of the test (likelihood ratio test). |
data.name |
a character string giving the names of the supplied models, gsmar1 and gsmar2. |
gsmar1 |
the supplied argument gsmar1 |
gsmar2 |
the supplied argument gsmar2 |
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
Wald_test
, fitGSMAR
, GSMAR
, diagnostic_plot
,
profile_logliks
, quantile_residual_tests
, cond_moment_plot
# GMAR p=1, M=2 model: fit12 <- fitGSMAR(simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) # GMAR p=1, M=2 model with AR parameters restricted to be the same in both # regimes: fit12r <- fitGSMAR(simudata, p=1, M=2, model="GMAR", restricted=TRUE, ncalls=1, seeds=1) # Test with likelihood ratio test whether the AR parameters are the same in # both regimes: LR_test(fit12, fit12r)
# GMAR p=1, M=2 model: fit12 <- fitGSMAR(simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) # GMAR p=1, M=2 model with AR parameters restricted to be the same in both # regimes: fit12r <- fitGSMAR(simudata, p=1, M=2, model="GMAR", restricted=TRUE, ncalls=1, seeds=1) # Test with likelihood ratio test whether the AR parameters are the same in # both regimes: LR_test(fit12, fit12r)
A dataset containing monthly U.S. interest rate spread between the 10-Year Treasury constant maturity rate and 1-Year Treasury constant maturity rate from 1982 January to 2020 December.
M10Y1Y
M10Y1Y
A class 'ts' time series object containing 468 observations.
https://fred.stlouisfed.org/series/GS10 https://fred.stlouisfed.org/series/GS1
mixing_weights
calculates the mixing weights of the specified GMAR, StMAR or G-StMAR model and returns them as a matrix.
mixing_weights( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean") )
mixing_weights( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean") )
data |
a numeric vector or class |
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
parametrization |
is the model parametrized with the "intercepts" |
The first p observations are taken to be the initial values.
to_return=="mw"
:a size ((n_obs-p)xM) matrix containing the mixing weights: for m:th component in m:th column.
to_return=="mw_tplus1"
:a size ((n_obs-p+1)xM) matrix containing the mixing weights: for m:th component in m:th column.
The last row is for
.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
# GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) mixing_weights(simudata, p=1, M=2, params=params12, model="GMAR") # G-StMAR-model params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) mixing_weights(M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR")
# GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) mixing_weights(simudata, p=1, M=2, params=params12, model="GMAR") # G-StMAR-model params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) mixing_weights(M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR")
mixing_weights
INSTEAD! Calculate mixing weights of GMAR, StMAR or G-StMAR modelmixingWeights
calculates the mixing weights of the specified GMAR, StMAR or G-StMAR model
and returns them as a matrix. DEPRECATED, USE mixing_weights
INSTEAD!
mixingWeights( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean") )
mixingWeights( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean") )
data |
a numeric vector or class |
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
parametrization |
is the model parametrized with the "intercepts" |
DEPRECATED, USE mixing_weights
INSTEAD!
to_return=="mw"
:a size ((n_obs-p)xM) matrix containing the mixing weights: for m:th component in m:th column.
to_return=="mw_tplus1"
:a size ((n_obs-p+1)xM) matrix containing the mixing weights: for m:th component in m:th column.
The last row is for
.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
(or
), AR-coefficients, and variance parameters from a parameter vectorpick_pars
picks /
, AR-coefficients, and variance parameters from
the given parameter vector.
pick_pars( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL )
pick_pars( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL )
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
Returns a matrix containing the parameters, column for each component.
The first row for
or
depending on the parametrization, the second row
for
, ..., the second to last row for
, and the last row for
.
@keywords internal
plot.gsmarpred
is plot method for class 'gsmarpred' objects
## S3 method for class 'gsmarpred' plot(x, ..., nt, mix_weights = TRUE, add_grid = TRUE)
## S3 method for class 'gsmarpred' plot(x, ..., nt, mix_weights = TRUE, add_grid = TRUE)
x |
object of class |
... |
arguments passed to function |
nt |
a positive integer specifying the number of observations to be plotted
along with the prediction. Default is |
mix_weights |
|
add_grid |
should grid a be added to the plots? |
This method is intended for plotting forecasts of GSMAR processes.
quantile_residual_tests
performs quantile residual tests for GMAR, StMAR,
and G-StMAR models, testing normality, autocorrelation, and conditional heteroscedasticity
of the quantile residuals.
## S3 method for class 'qrtest' plot(x, ...) ## S3 method for class 'qrtest' print(x, ..., digits = 3) quantile_residual_tests( gsmar, lags_ac = c(1, 3, 6, 12), lags_ch = lags_ac, nsimu = 1, print_res = TRUE )
## S3 method for class 'qrtest' plot(x, ...) ## S3 method for class 'qrtest' print(x, ..., digits = 3) quantile_residual_tests( gsmar, lags_ac = c(1, 3, 6, 12), lags_ch = lags_ac, nsimu = 1, print_res = TRUE )
x |
object of class |
... |
graphical parameters passed to |
digits |
the number of digits to be print |
gsmar |
a class 'gsmar' object, typically generated by |
lags_ac |
a numeric vector of positive integers specifying the lags for which autocorrelation is tested. |
lags_ch |
a numeric vector of positive integers specifying the lags for which conditional heteroscedasticity is tested. |
nsimu |
a positive integer specifying to how many simulated observations the covariance matrix Omega (see Kalliovirta (2012)) should be based on. If smaller than data size, then omega will be based on the given data and not on simulated data. Having the covariance matrix omega based on a large simulated sample might improve the tests size properties. |
print_res |
a logical argument defining whether the results should be printed or not. |
For a correctly specified GSMAR model employing the maximum likelihood estimator, the quantile residuals are asymptotically independent with standard normal distribution. They can hence be used in a similar manner to conventional Pearson's residuals. For more details about quantile residual based diagnostics, and in particular, about the quantile residual tests, see the cited article by Kalliovirta (2012).
Returns an object of class 'qrtest'
containing the test results in data frames. In the cases
of autocorrelation and conditional heteroscedasticity tests, the returned object also contains the
associated individual statistics and their standard errors, discussed in Kalliovirta (2012) at
the pages 369-370.
plot(qrtest)
: Plot p-values of the autocorrelation and conditional
heteroskedasticity tests.
print(qrtest)
: Print method for class 'qrtest' objects
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
profile_logliks
, fitGSMAR
, GSMAR
, diagnostic_plot
,
predict.gsmar
, get_test_Omega
,
## The below examples take approximately 30 seconds to run. # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(data=M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) # Tests based on the observed data (without simulation procedure) with the # default lags: qrt1 <- quantile_residual_tests(fit42gs) # Tests based on the simulation procedure using sample size 10000 and with # the lags specified by hand: set.seed(1) qrt2 <- quantile_residual_tests(fit42gs, lags_ac=c(1, 6), nsimu=10000) # GMAR model fit12 <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) qrt3 <- quantile_residual_tests(fit12, lags_ac=c(1, 5, 10, 15))
## The below examples take approximately 30 seconds to run. # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(data=M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) # Tests based on the observed data (without simulation procedure) with the # default lags: qrt1 <- quantile_residual_tests(fit42gs) # Tests based on the simulation procedure using sample size 10000 and with # the lags specified by hand: set.seed(1) qrt2 <- quantile_residual_tests(fit42gs, lags_ac=c(1, 6), nsimu=10000) # GMAR model fit12 <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) qrt3 <- quantile_residual_tests(fit12, lags_ac=c(1, 5, 10, 15))
predict.gsmar
forecasts the specified GMAR, StMAR, or G-StMAR process by using the given
data to simulate its possible future values. For one-step forecasts using the exact formula for conditional
mean is supported.
## S3 method for class 'gsmar' predict( object, ..., n_ahead, nsimu = 10000, pi = c(0.95, 0.8), pred_type = c("median", "mean", "cond_mean"), pi_type = c("two-sided", "upper", "lower", "none"), plot_res = TRUE, mix_weights = TRUE, nt )
## S3 method for class 'gsmar' predict( object, ..., n_ahead, nsimu = 10000, pi = c(0.95, 0.8), pred_type = c("median", "mean", "cond_mean"), pi_type = c("two-sided", "upper", "lower", "none"), plot_res = TRUE, mix_weights = TRUE, nt )
object |
object of class |
... |
additional arguments passed to |
n_ahead |
a positive integer specifying how many steps in the future should be forecasted. |
nsimu |
a positive integer specifying to how many simulations the forecast should be based on. |
pi |
a numeric vector specifying confidence levels for the prediction intervals. |
pred_type |
should the prediction be based on sample "median" or "mean"? Or should it
be one-step-ahead forecast based on the exact conditional mean ( |
pi_type |
should the prediction intervals be "two-sided", "upper", or "lower"? |
plot_res |
a logical argument defining whether the forecast should be plotted or not. |
mix_weights |
|
nt |
a positive integer specifying the number of observations to be plotted
along with the prediction. Default is |
predict.gsmar
uses the last p
values of the data to simulate nsimu
possible future values for each step-ahead. The point prediction is then obtained by calculating
the sample median or mean for each step and the prediction intervals are obtained from the
empirical fractiles.
The function simulate.gsmar
can also be used directly for quantile based forecasting.
Returns a class 'gsmarpred'
object containing, among the specifications,...
$pred |
Point forecasts |
$pred_ints |
Prediction intervals |
$mix_pred |
Point forecasts for mixing weights |
mix_pred_ints |
Individual prediction intervals for mixing weights, as |
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
simulate.gsmar
, cond_moments
, fitGSMAR
, GSMAR
,
quantile_residual_tests
, diagnostic_plot
## These examples take approximately 30 seconds to run. # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) # Forecast 12 steps ahead based on 10000 simulated sample paths, prediction # interval confidence levels 0.95 and 0.8, prediction based on sample median, # and two-sided prediction intevals: mypred <- predict(fit42gs, n_ahead=12, nsimu=10000, pi=c(0.95, 0.8), pred_type="median", pi_type="two-sided") mypred plot(mypred) # Forecast 24 steps ahead based on 1000 simulated sample paths, prediction # interval confidence level 0.99 and 0.9, prediction based on sample mean, # and upper prediction intevals: mypred2 <- predict(fit42gs, n_ahead=24, nsimu=1000, pi=c(0.99, 0.9), pred_type="mean", pi_type="upper") # Forecast 24 steps ahead based on 1000 simulated sample paths, prediction # interval confidence level 0.99, 0.95, 0.9 and 0.8, prediction based on # sample median, and lower prediction intevals: mypred3 <- predict(fit42gs, n_ahead=24, nsimu=1000, pi=c(0.99, 0.95, 0.9, 0.8), pred_type="median", pi_type="lower") # GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR") pred12 <- predict(gmar12, n_ahead=10, nsimu=1000, pi=c(0.95, 0.9, 0.8), pred_type="median", pi_type="two-sided") pred12 plot(pred12) # One-step prediction based on the exact conditional mean: predict(gmar12, n_ahead=1, pred_type="cond_mean", plot_res=FALSE)
## These examples take approximately 30 seconds to run. # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) # Forecast 12 steps ahead based on 10000 simulated sample paths, prediction # interval confidence levels 0.95 and 0.8, prediction based on sample median, # and two-sided prediction intevals: mypred <- predict(fit42gs, n_ahead=12, nsimu=10000, pi=c(0.95, 0.8), pred_type="median", pi_type="two-sided") mypred plot(mypred) # Forecast 24 steps ahead based on 1000 simulated sample paths, prediction # interval confidence level 0.99 and 0.9, prediction based on sample mean, # and upper prediction intevals: mypred2 <- predict(fit42gs, n_ahead=24, nsimu=1000, pi=c(0.99, 0.9), pred_type="mean", pi_type="upper") # Forecast 24 steps ahead based on 1000 simulated sample paths, prediction # interval confidence level 0.99, 0.95, 0.9 and 0.8, prediction based on # sample median, and lower prediction intevals: mypred3 <- predict(fit42gs, n_ahead=24, nsimu=1000, pi=c(0.99, 0.95, 0.9, 0.8), pred_type="median", pi_type="lower") # GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR") pred12 <- predict(gmar12, n_ahead=10, nsimu=1000, pi=c(0.95, 0.9, 0.8), pred_type="median", pi_type="two-sided") pred12 plot(pred12) # One-step prediction based on the exact conditional mean: predict(gmar12, n_ahead=1, pred_type="cond_mean", plot_res=FALSE)
print.gsmarpred
is a print method for call 'gsmarpred'
objects created with predict.gsmar
.
## S3 method for class 'gsmarpred' print(x, ..., digits = 2)
## S3 method for class 'gsmarpred' print(x, ..., digits = 2)
x |
object of class |
... |
currently not in use. |
digits |
the number of digits to be printed |
print.gsmarsum
is a print method for objects of class 'gsmarsum'
created with the summary method summary.gsmar
. Approximate standard errors
are printed in brackets.
## S3 method for class 'gsmarsum' print(x, ..., digits)
## S3 method for class 'gsmarsum' print(x, ..., digits)
x |
object of class 'gsmarsum' generated by |
... |
currently not in use. |
digits |
the number of digits to be printed |
profile_logliks
plots profile log-likelihoods around the estimates.
profile_logliks(gsmar, scale = 0.02, nrows, ncols, precision = 200)
profile_logliks(gsmar, scale = 0.02, nrows, ncols, precision = 200)
gsmar |
a class 'gsmar' object, typically generated by |
scale |
a numeric scalar specifying the interval plotted for each estimate: the estimate plus-minus |
nrows |
how many rows should be in the plot-matrix? The default is |
ncols |
how many columns should be in the plot-matrix? The default is |
precision |
at how many points should each profile log-likelihood be evaluated at? |
The red vertical line points the estimate.
Be aware that the profile log-likelihood function is subject to a numerical error due to limited float-point precision when considering extremely large parameter values, say, overly large degrees freedom estimates.
Only plots to a graphical device and doesn't return anything.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
quantile_residual_plot
, diagnostic_plot
, cond_moment_plot
, GSMAR
,
quantile_residual_tests
, simulate.gsmar
## The below examples the approximately 15 seconds to run. # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) profile_logliks(fit42gs) # GMAR model, graphs zoomed in closer. fit12 <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) profile_logliks(fit12, scale=0.001)
## The below examples the approximately 15 seconds to run. # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) profile_logliks(fit42gs) # GMAR model, graphs zoomed in closer. fit12 <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) profile_logliks(fit12, scale=0.001)
quantile_residualsPlot
plots quantile residual time series and histogram.
quantile_residual_plot(gsmar)
quantile_residual_plot(gsmar)
gsmar |
a class 'gsmar' object, typically generated by |
Only plots to a graphical device and doesn't return anything.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
profile_logliks
, diagnostic_plot
, fitGSMAR
, GSMAR
,
quantile_residual_tests
, simulate.gsmar
## The below examples the approximately 15 seconds to run. # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) quantile_residual_plot(fit42gs) # GMAR model fit12 <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) quantile_residual_plot(fit12)
## The below examples the approximately 15 seconds to run. # G-StMAR model with one GMAR type and one StMAR type regime fit42gs <- fitGSMAR(M10Y1Y, p=4, M=c(1, 1), model="G-StMAR", ncalls=1, seeds=4) quantile_residual_plot(fit42gs) # GMAR model fit12 <- fitGSMAR(data=simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) quantile_residual_plot(fit12)
quantile_residuals
computes the quantile residuals of the specified GMAR, StMAR, or G-StMAR model.
quantile_residuals( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean") )
quantile_residuals( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean") )
data |
a numeric vector or class |
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
parametrization |
is the model parametrized with the "intercepts" |
Numerical integration is employed if the quantile residuals cannot be obtained analytically with the hypergeometric function using the package 'gsl'.
Returns a numeric vector containing the quantile residuals of the specified GMAR, StMAR or G-StMAR model.
Note that there are no quantile residuals for the first
p
observations as they are the initial values.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
# GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) quantile_residuals(simudata, p=1, M=2, params=params12, model="GMAR") # G-StMAR-model params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) quantile_residuals(M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR")
# GMAR model params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) quantile_residuals(simudata, p=1, M=2, params=params12, model="GMAR") # G-StMAR-model params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) quantile_residuals(M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR")
quantile_residual_plot
INSTEAD! Plot quantile residual time series and histogramquantileResidualsPlot
plots quantile residual time series and histogram.
DEPRECATED, USE quantile_residual_plot
INSTEAD!
quantileResidualPlot(gsmar)
quantileResidualPlot(gsmar)
gsmar |
a class 'gsmar' object, typically generated by |
DEPRECATED, USE quantile_residual_plot
INSTEAD!
Only plots to a graphical device and doesn't return anything.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
profile_logliks
, diagnostic_plot
, fitGSMAR
, GSMAR
,
quantile_residual_tests
, simulate.gsmar
quantile_residuals
INSTEAD! Compute quantile residuals of GMAR, StMAR, or G-StMAR modelquantileResiduals
computes the quantile residuals of the specified GMAR, StMAR, or G-StMAR model.
DEPRECATED, USE quantile_residuals
INSTEAD!
quantileResiduals( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean") )
quantileResiduals( data, p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, parametrization = c("intercept", "mean") )
data |
a numeric vector or class |
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
parametrization |
is the model parametrized with the "intercepts" |
DEPRECATED, USE quantile_residuals
INSTEAD!
Returns a numeric vector containing the quantile residuals of the specified GMAR, StMAR or G-StMAR model.
Note that there are no quantile residuals for the first
p
observations as they are the initial values.
Install the suggested package "gsl" for faster evaluation of the quantile residuals of StMAR and G-StMAR models.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
quantile_residual_tests
INSTEAD! Quantile residual tests for GMAR, StMAR , and G-StMAR modelsquantileResidualTests
performs quantile residual tests for GMAR, StMAR,
and G-StMAR models, testing normality, autocorrelation, and conditional heteroscedasticity
of the quantile residuals. DEPRECATED, USE quantile_residual_tests
INSTEAD!
quantileResidualTests( gsmar, lags_ac = c(1, 3, 6, 12), lags_ch = lags_ac, nsimu = 1, print_res = TRUE, lagsAC = NULL, lagsCH = NULL, printRes = NULL )
quantileResidualTests( gsmar, lags_ac = c(1, 3, 6, 12), lags_ch = lags_ac, nsimu = 1, print_res = TRUE, lagsAC = NULL, lagsCH = NULL, printRes = NULL )
gsmar |
a class 'gsmar' object, typically generated by |
lags_ac |
a numeric vector of positive integers specifying the lags for which autocorrelation is tested. |
lags_ch |
a numeric vector of positive integers specifying the lags for which conditional heteroscedasticity is tested. |
nsimu |
a positive integer specifying to how many simulated observations the covariance matrix Omega (see Kalliovirta (2012)) should be based on. If smaller than data size, then omega will be based on the given data and not on simulated data. Having the covariance matrix omega based on a large simulated sample might improve the tests size properties. |
print_res |
a logical argument defining whether the results should be printed or not. |
lagsAC |
deprecated! Use |
lagsCH |
deprecated! Use |
printRes |
deprecated! Use |
DEPRECATED! USE quantile_residual_tests
INSTEAD!
For a correctly specified GSMAR model employing the maximum likelihood estimator, the quantile residuals are asymptotically independent with standard normal distribution. They can hence be used in a similar manner to conventional Pearson's residuals. For more details about quantile residual based diagnostics, and in particular, about the quantile residual tests, see the cited article by Kalliovirta (2012).
Returns an object of class 'qrtest'
containing the test results in data frames. In the cases
of autocorrelation and conditional heteroscedasticity tests, the returned object also contains the
associated individual statistics and their standard errors, discussed in Kalliovirta (2012) at
the pages 369-370.
Install the suggested package "gsl" for faster evaluations in the cases of StMAR and G-StMAR models. For large StMAR and G-StMAR models with large data, the evaluations may take significantly long time without the package "gsl".
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
profile_logliks
, fitGSMAR
, GSMAR
, diagnostic_plot
,
predict.gsmar
, get_test_Omega
,
random_ind
creates a random GMAR, StMAR, or G-StMAR model compatible mean-parametrized parameter vector.
smart_ind
creates a random GMAR, StMAR, or G-StMAR model compatible parameter vector close to argument params
.
Sometimes returns exactly the given parameter vector.
random_ind( p, M, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, mu_scale, sigma_scale, forcestat = FALSE ) smart_ind( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, mu_scale, sigma_scale, accuracy, which_random = numeric(0), forcestat = FALSE )
random_ind( p, M, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, mu_scale, sigma_scale, forcestat = FALSE ) smart_ind( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, mu_scale, sigma_scale, accuracy, which_random = numeric(0), forcestat = FALSE )
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
mu_scale |
a real valued vector of length two specifying the mean (the first element) and standard deviation (the second element)
of the normal distribution from which the |
sigma_scale |
a positive real number specifying the standard deviation of the (zero mean, positive only by taking absolute value) normal distribution from which the component variance parameters (for random regimes) should be generated. |
forcestat |
use the algorithm by Monahan (1984) to force stationarity on the AR parameters (slower) for random regimes? Not supported for constrained models. |
params |
a real valued parameter vector specifying the model.
Symbol |
accuracy |
a real number larger than zero specifying how close to |
which_random |
a numeric vector of maximum length |
These functions can be used, for example, to create initial populations for the genetic algorithm. Mean-parametrization
(instead of intercept terms ) is assumed.
Returns estimated parameter vector with the form described in initpop
.
Monahan J.F. 1984. A Note on Enforcing Stationarity in Autoregressive-Moving Average Models. Biometrica 71, 403-404.
set.seed(1) # GMAR model parameter vector params22 <- random_ind(p=2, M=2, mu_scale=c(0, 1), sigma_scale=1) smart22 <- smart_ind(p=2, M=2, params22, accuracy=10) cbind(params22, smart22) # Restricted GMAR parameter vector params12r <- random_ind(p=1, M=2, restricted=TRUE, mu_scale=c(-2, 2), sigma_scale=2) smart12r <- smart_ind(p=1, M=2, params12r, restricted=TRUE, accuracy=20) cbind(params12r, smart12r) # StMAR parameter vector: first regime is random in the "smart individual" params13t <- random_ind(p=1, M=3, model="StMAR", mu_scale=c(3, 1), sigma_scale=3) smart13t <- smart_ind(p=1, M=3, params13t, model="StMAR", accuracy=15, mu_scale=c(3, 3), sigma_scale=3, which_random=1) cbind(params13t, smart13t) # Restricted StMAR parameter vector params22tr <- random_ind(p=2, M=2, model="StMAR", restricted=TRUE, mu_scale=c(3, 2), sigma_scale=0.5) smart22tr <- smart_ind(p=2, M=2, params22tr, model="StMAR", restricted=TRUE, accuracy=30) cbind(params22tr, smart22tr) # G-StMAR parameter vector params12gs <- random_ind(p=1, M=c(1, 1), model="G-StMAR", mu_scale=c(0, 1), sigma_scale=1) smart12gs <- smart_ind(p=1, M=c(1, 1), params12gs, model="G-StMAR", accuracy=20) cbind(params12gs, smart12gs) # Such StMAR(3,2) that the AR coefficients are restricted to be # the same for both regimes and that the second AR coefficients are # constrained to zero. Second regime is random in the "smart individual". params32trc <- random_ind(p=3, M=2, model="StMAR", restricted=TRUE, constraints=matrix(c(1, 0, 0, 0, 0, 1), ncol=2), mu_scale=c(-2, 0.5), sigma_scale=4) smart32trc <- smart_ind(p=3, M=2, params32trc, model="StMAR", restricted=TRUE, constraints=matrix(c(1, 0, 0, 0, 0, 1), ncol=2), mu_scale=c(0, 0.1), sigma_scale=0.1, which_random=2, accuracy=20) cbind(params32trc, smart32trc)
set.seed(1) # GMAR model parameter vector params22 <- random_ind(p=2, M=2, mu_scale=c(0, 1), sigma_scale=1) smart22 <- smart_ind(p=2, M=2, params22, accuracy=10) cbind(params22, smart22) # Restricted GMAR parameter vector params12r <- random_ind(p=1, M=2, restricted=TRUE, mu_scale=c(-2, 2), sigma_scale=2) smart12r <- smart_ind(p=1, M=2, params12r, restricted=TRUE, accuracy=20) cbind(params12r, smart12r) # StMAR parameter vector: first regime is random in the "smart individual" params13t <- random_ind(p=1, M=3, model="StMAR", mu_scale=c(3, 1), sigma_scale=3) smart13t <- smart_ind(p=1, M=3, params13t, model="StMAR", accuracy=15, mu_scale=c(3, 3), sigma_scale=3, which_random=1) cbind(params13t, smart13t) # Restricted StMAR parameter vector params22tr <- random_ind(p=2, M=2, model="StMAR", restricted=TRUE, mu_scale=c(3, 2), sigma_scale=0.5) smart22tr <- smart_ind(p=2, M=2, params22tr, model="StMAR", restricted=TRUE, accuracy=30) cbind(params22tr, smart22tr) # G-StMAR parameter vector params12gs <- random_ind(p=1, M=c(1, 1), model="G-StMAR", mu_scale=c(0, 1), sigma_scale=1) smart12gs <- smart_ind(p=1, M=c(1, 1), params12gs, model="G-StMAR", accuracy=20) cbind(params12gs, smart12gs) # Such StMAR(3,2) that the AR coefficients are restricted to be # the same for both regimes and that the second AR coefficients are # constrained to zero. Second regime is random in the "smart individual". params32trc <- random_ind(p=3, M=2, model="StMAR", restricted=TRUE, constraints=matrix(c(1, 0, 0, 0, 0, 1), ncol=2), mu_scale=c(-2, 0.5), sigma_scale=4) smart32trc <- smart_ind(p=3, M=2, params32trc, model="StMAR", restricted=TRUE, constraints=matrix(c(1, 0, 0, 0, 0, 1), ncol=2), mu_scale=c(0, 0.1), sigma_scale=0.1, which_random=2, accuracy=20) cbind(params32trc, smart32trc)
random_ind
OR smart_ind
INSTEAD!
Create random GMAR, StMAR, or G-StMAR model compatible parameter vectorrandomIndividual
creates a random GMAR, StMAR, or G-StMAR model compatible mean-parametrized parameter vector.
DEPRECATED, USE random_ind
INSTEAD!
smartIndividual
creates a random GMAR, StMAR, or G-StMAR model compatible parameter vector close to argument params
.
Sometimes returns exactly the given parameter vector. DEPRECATED, USE smart_ind
INSTEAD!
randomIndividual( p, M, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, mu_scale, sigma_scale, forcestat = FALSE, meanscale = NULL, sigmascale = NULL ) smartIndividual( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, mu_scale, sigma_scale, accuracy, which_random = numeric(0), forcestat = FALSE, whichRandom = NULL, meanscale = NULL, sigmascale = NULL )
randomIndividual( p, M, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, mu_scale, sigma_scale, forcestat = FALSE, meanscale = NULL, sigmascale = NULL ) smartIndividual( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, mu_scale, sigma_scale, accuracy, which_random = numeric(0), forcestat = FALSE, whichRandom = NULL, meanscale = NULL, sigmascale = NULL )
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
mu_scale |
a real valued vector of length two specifying the mean (the first element) and standard deviation (the second element)
of the normal distribution from which the |
sigma_scale |
a positive real number specifying the standard deviation of the (zero mean, positive only by taking absolute value) normal distribution from which the component variance parameters (for random regimes) should be generated. |
forcestat |
use the algorithm by Monahan (1984) to force stationarity on the AR parameters (slower) for random regimes? Not supported for constrained models. |
meanscale |
deprecated! Use |
sigmascale |
deprecated! Use |
params |
a real valued parameter vector specifying the model.
Symbol |
accuracy |
a real number larger than zero specifying how close to |
which_random |
a numeric vector of maximum length |
whichRandom |
deprecated! Use |
DEPRECATED, USE random_ind
OR smart_ind
INSTEAD!
These functions can be used, for example, to create initial populations for the genetic algorithm. Mean-parametrization
(instead of intercept terms ) is assumed.
Returns estimated parameter vector with the form described in initpop
.
Monahan J.F. 1984. A Note on Enforcing Stationarity in Autoregressive-Moving Average Models. Biometrica 71, 403-404.
reform_parameters
takes a parameter vector of any (non-constrained) GMAR, StMAR, or G-StMAR model
and returns a list with the parameter vector in the standard form, parameter matrix containing AR coefficients and
component variances, mixing weights alphas, and in case of StMAR or G-StMAR model also degrees of freedom parameters.
reform_parameters( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE )
reform_parameters( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE )
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
This function does not support models imposing linear constraints. No argument checks in this function.
Returns a list with...
$params
parameter vector in the standard form.
$pars
corresponding parameter matrix containing AR coefficients and component variances. First row for phi0 or means depending on the parametrization. Column for each component.
$alphas
numeric vector containing mixing weight parameters for all of the components (also for the last one).
$dfs
numeric vector containing degrees of freedom parameters for all of components.
Returned only if model == "StMAR"
or model == "G-StMAR"
.
@keywords internal
A dataset containing 200 observations simulated from a GMAR p=1, M=2 process.
simudata
simudata
A numeric vector of length 200.
Simulated
simulate.gsmar
simulates observations from the specified GMAR, StMAR, or G-StMAR process.
Can be utilized for forecasting future values of the process.
## S3 method for class 'gsmar' simulate( object, nsim = 1, seed = NULL, ..., init_values = NULL, ntimes = 1, drop = TRUE )
## S3 method for class 'gsmar' simulate( object, nsim = 1, seed = NULL, ..., init_values = NULL, ntimes = 1, drop = TRUE )
object |
object of class |
nsim |
a positive integer specifying how many values (ahead from |
seed |
an integer that specifies the seed for the random number generator. Ignored if |
... |
currently not in use. |
init_values |
a numeric vector with length |
ntimes |
a positive integer specifying how many sets of simulations should be performed. |
drop |
if |
The argument ntimes
is intended for forecasting: a GSMAR process can be forecasted by simulating its
possible future values. One can perform a large number of sets of simulations and calculate the sample quantiles from
the simulated values to obtain prediction intervals. See the forecasting example below for a hand-on demonstration.
If drop==TRUE
and ntimes==1
(default): $sample
and $component
are vectors
and $mixing_weights
is a (nsim
) matrix. Otherwise, returns a list with...
$sample
a size (nsim
ntimes
) matrix containing the simulated values.
$component
a size (nsim
ntimes
) matrix containing the information from which
mixture component each value was generated from.
$mixing_weights
a size (nsim
ntimes
) array containing the mixing weights corresponding to the
sample: the dimension [i, , ]
is the time index, the dimension [, i, ]
indicates the regime, and the dimension
[, , i]
indicates the i:th set of simulations.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
fitGSMAR
, GSMAR
, predict.gsmar
,
add_data
, cond_moments
, mixing_weights
set.seed(1) # GMAR model: params22 <- c(0.9, 0.4, 0.2, 0.5, 0.7, 0.5, -0.2, 0.7, 0.7) mod22 <- GSMAR(p=2, M=2, params=params22, model="GMAR") mysim <- simulate(mod22, nsim=500) ts.plot(mysim$sample) ts.plot(mysim$component) ts.plot(mysim$mixing_weights, col=rainbow(2), lty=2) # G-StMAR model, with initial values: params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) gstmar42 <- GSMAR(data=M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR") sim42gs <- simulate(gstmar42, nsim=500, init_values=1:4) ts.plot(sim42gs$sample) ts.plot(sim42gs$component) ts.plot(sim42gs$mixing_weights, col=rainbow(2), lty=2) # FORECASTING EXAMPLE: # GMAR model, 1000 sets of simulations with initial values from the data: params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR") sim12 <- simulate(gmar12, nsim=5, init_val=gmar12$data, ntimes=1000) apply(sim12$sample, MARGIN=1, FUN=median) # Point prediction apply(sim12$sample, MARGIN=1, FUN=quantile, probs=c(0.025, 0.975)) # 95% pi apply(sim12$mixing_weights, MARGIN=1:2, FUN=median) # mix.weight point pred apply(sim12$mixing_weights, MARGIN=1:2, FUN=quantile, probs=c(0.025, 0.975)) # mix.weight 95% prediction intervals
set.seed(1) # GMAR model: params22 <- c(0.9, 0.4, 0.2, 0.5, 0.7, 0.5, -0.2, 0.7, 0.7) mod22 <- GSMAR(p=2, M=2, params=params22, model="GMAR") mysim <- simulate(mod22, nsim=500) ts.plot(mysim$sample) ts.plot(mysim$component) ts.plot(mysim$mixing_weights, col=rainbow(2), lty=2) # G-StMAR model, with initial values: params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) gstmar42 <- GSMAR(data=M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR") sim42gs <- simulate(gstmar42, nsim=500, init_values=1:4) ts.plot(sim42gs$sample) ts.plot(sim42gs$component) ts.plot(sim42gs$mixing_weights, col=rainbow(2), lty=2) # FORECASTING EXAMPLE: # GMAR model, 1000 sets of simulations with initial values from the data: params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63) gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR") sim12 <- simulate(gmar12, nsim=5, init_val=gmar12$data, ntimes=1000) apply(sim12$sample, MARGIN=1, FUN=median) # Point prediction apply(sim12$sample, MARGIN=1, FUN=quantile, probs=c(0.025, 0.975)) # 95% pi apply(sim12$mixing_weights, MARGIN=1:2, FUN=median) # mix.weight point pred apply(sim12$mixing_weights, MARGIN=1:2, FUN=quantile, probs=c(0.025, 0.975)) # mix.weight 95% prediction intervals
simulate.gsmar
INSTEAD! Simulate observations from GMAR, StMAR, and G-StMAR processessimulateGSMAR
simulates observations from the specified GMAR, StMAR, or G-StMAR process.
Can be utilized for forecasting future values of the process. DEPRECATED, USE simulate.gsmar
INSTEAD!
simulateGSMAR( object, nsim, init_values = NULL, ntimes = 1, drop = TRUE, gsmar = NULL, nsimu = NULL )
simulateGSMAR( object, nsim, init_values = NULL, ntimes = 1, drop = TRUE, gsmar = NULL, nsimu = NULL )
object |
object of class |
nsim |
a positive integer specifying how many values (ahead from |
init_values |
a numeric vector with length |
ntimes |
a positive integer specifying how many sets of simulations should be performed. |
drop |
if |
gsmar |
a class 'gsmar' object, typically generated by |
nsimu |
a positive integer specifying how many values (ahead from |
DEPRECATED, USE simulate.gsmar
INSTEAD!
The argument ntimes
is intended for forecasting: a GSMAR process can be forecasted by simulating its
possible future values. One can perform a large number of sets of simulations and calculate the sample quantiles from
the simulated values to obtain prediction intervals. See the forecasting example below for a hand-on demonstration.
If drop==TRUE
and ntimes==1
(default): $sample
and $component
are vectors
and $mixing_weights
is a (nsim
) matrix. Otherwise, returns a list with...
$sample
a size (nsim
ntimes
) matrix containing the simulated values.
$component
a size (nsim
ntimes
) matrix containing the information from which
mixture component each value was generated from.
$mixing_weights
a size (nsim
ntimes
) array containing the mixing weights corresponding to the
sample: the dimension [i, , ]
is the time index, the dimension [, i, ]
indicates the regime, and the dimension
[, , i]
indicates the i:th set of simulations.
Galbraith, R., Galbraith, J. 1974. On the inverses of some patterned matrices arising in the theory of stationary time series. Journal of Applied Probability 11, 63-71.
Kalliovirta L. (2012) Misspecification tests based on quantile residuals. The Econometrics Journal, 15, 358-393.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
fitGSMAR
, GSMAR
, predict.gsmar
,
add_data
, cond_moments
, mixing_weights
stmar_to_gstmar
estimates a G-StMAR model based on a StMAR model with large degree
of freedom parameters.
stmar_to_gstmar( gsmar, maxdf = 100, estimate, calc_std_errors, maxit = 100, custom_h = NULL )
stmar_to_gstmar( gsmar, maxdf = 100, estimate, calc_std_errors, maxit = 100, custom_h = NULL )
gsmar |
a class 'gsmar' object, typically generated by |
maxdf |
regimes with degrees of freedom parameter value larger than this will be turned into GMAR type. |
estimate |
set |
calc_std_errors |
set |
maxit |
the maximum number of iterations for the variable metric algorithm. Ignored if |
custom_h |
A numeric vector with same the length as the parameter vector: i:th element of custom_h is the difference
used in central difference approximation for partial differentials of the log-likelihood function for the i:th parameter.
If |
If a StMAR model contains large estimates for the degrees of freedom parameters,
one should consider switching to the corresponding G-StMAR model that lets the corresponding
regimes to be GMAR type. stmar_to_gstmar
does this switch conveniently.
Returns an object of class 'gsmar'
defining the specified GMAR, StMAR, or G-StMAR model. If data is supplied,
the returned object contains (by default) empirical mixing weights, some conditional and unconditional moments, and quantile
residuals. Note that the first p observations are taken as the initial values so the mixing weights, conditional moments, and
quantile residuals start from the p+1:th observation (interpreted as t=1).
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
fitGSMAR
, GSMAR
, iterate_more
, get_gradient
,
get_regime_means
, swap_parametrization
, stmar_to_gstmar
# These are long running example that take approximately 15 seconds to run. fit42t <- fitGSMAR(data=M10Y1Y, p=4, M=2, model="StMAR", ncalls=1, seeds=6) fit42t # Overly large degrees of freedom estimate! # Switch to the appropriate G-StMAR model: fit42gs <- stmar_to_gstmar(fit42t) fit42gs
# These are long running example that take approximately 15 seconds to run. fit42t <- fitGSMAR(data=M10Y1Y, p=4, M=2, model="StMAR", ncalls=1, seeds=6) fit42t # Overly large degrees of freedom estimate! # Switch to the appropriate G-StMAR model: fit42gs <- stmar_to_gstmar(fit42t) fit42gs
stmarpars_to_gstmar
transforms a StMAR model parameter vector to a corresponding
G-StMAR model parameter vector with large dfs parameters reduced by switching the related regimes
to be GMAR type.
stmarpars_to_gstmar( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, maxdf = 100 )
stmarpars_to_gstmar( p, M, params, model = c("GMAR", "StMAR", "G-StMAR"), restricted = FALSE, constraints = NULL, maxdf = 100 )
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
maxdf |
regimes with degrees of freedom parameter value larger than this will be turned into GMAR type. |
Returns a list with three elements: $params
contains the corresponding G-StMAR model
parameter vector, $reg_order
contains the permutation that was applied to the regimes
(GMAR type components first, and decreasing ordering by mixing weight parameters), and
$M
a vector of length two containing the number of GMAR type regimes in the first element
and the number of StMAR type regimes in the second.
params12 <- c(2, 0.9, 0.1, 0.8, 0.5, 0.5, 0.4, 12, 300) stmarpars_to_gstmar(p=1, M=2, params=params12, model="StMAR", maxdf=100)
params12 <- c(2, 0.9, 0.1, 0.8, 0.5, 0.5, 0.4, 12, 300) stmarpars_to_gstmar(p=1, M=2, params=params12, model="StMAR", maxdf=100)
swap_parametrization
swaps the parametrization of object of class 'gsmar
'
to "mean"
if the current parametrization is "intercept"
, and vice versa.
swap_parametrization(gsmar, calc_std_errors = TRUE, custom_h = NULL)
swap_parametrization(gsmar, calc_std_errors = TRUE, custom_h = NULL)
gsmar |
a class 'gsmar' object, typically generated by |
calc_std_errors |
should approximate standard errors be calculated? |
custom_h |
A numeric vector with same the length as the parameter vector: i:th element of custom_h is the difference
used in central difference approximation for partial differentials of the log-likelihood function for the i:th parameter.
If |
swap_parametrization
is a convenient tool if you have estimated the model in
"intercept"-parametrization but wish to work with "mean"-parametrization in the future,
or vice versa. For example, approximate standard errors are readily available for
parametrized parameters only.
Returns an object of class 'gsmar'
defining the specified GMAR, StMAR, or G-StMAR model. If data is supplied,
the returned object contains (by default) empirical mixing weights, some conditional and unconditional moments, and quantile
residuals. Note that the first p observations are taken as the initial values so the mixing weights, conditional moments, and
quantile residuals start from the p+1:th observation (interpreted as t=1).
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
fitGSMAR
, GSMAR
, iterate_more
, get_gradient
,
get_regime_means
, swap_parametrization
, stmar_to_gstmar
# G-StMAR model with intercept parametrization params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) gstmar42 <- GSMAR(data=M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR") summary(gstmar42) # Swap to mean parametrization gstmar42 <- swap_parametrization(gstmar42) summary(gstmar42)
# G-StMAR model with intercept parametrization params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36, 0.2, -0.15, 0.04, 0.19, 9.75) gstmar42 <- GSMAR(data=M10Y1Y, p=4, M=c(1, 1), params=params42gs, model="G-StMAR") summary(gstmar42) # Swap to mean parametrization gstmar42 <- swap_parametrization(gstmar42) summary(gstmar42)
A dataset containing monthly U.S. interest rate spread between the 10-Year Treasury constant maturity rate and 1-Year Treasury constant maturity rate from 1953IV to 2020II.
T10Y1Y
T10Y1Y
A class 'ts' time series object containing 803 observations.
https://fred.stlouisfed.org/series/GS10 https://fred.stlouisfed.org/series/GS1
A dataset containing the monthly U.S. interest rate spread between the 3-month Treasury bill secondary market rate and the effective federal funds rate from 1954 July to 2019 July (781 observations). This series was studied in the empirical application of Virolainen (2021) introducing the G-StMAR model.
TBFF
TBFF
A class 'ts' time series object containing 781 observations.
https://fred.stlouisfed.org/series/TB3SMFFM
Virolainen S. 2021. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, doi: 10.1515/snde-2020-0060
uncond_moments
calculates the unconditional mean, variance, and the first p autocovariances
and autocorrelations of the GSMAR process.
uncond_moments(gsmar)
uncond_moments(gsmar)
gsmar |
a class 'gsmar' object, typically generated by |
Returns a list containing the unconditional mean, variance, and the first p autocovariances and
autocorrelations. Note that the lag-zero autocovariance/correlation is not included in the "first p"
but is given in the uncond_variance
component separately.
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
Lütkepohl H. 2005. New Introduction to Multiple Time Series Analysis. Springer.
Other moment functions:
cond_moments()
,
get_regime_autocovs()
,
get_regime_means()
,
get_regime_vars()
# GMAR model params13 <- c(1.4, 0.88, 0.26, 2.46, 0.82, 0.74, 5.0, 0.68, 5.2, 0.72, 0.2) gmar13 <- GSMAR(p=1, M=3, params=params13, model="GMAR") uncond_moments(gmar13) # StMAR model params12t <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 100, 3.6) stmar12t <- GSMAR(p=1, M=2, params=params12t, model="StMAR") uncond_moments(stmar12t) # G-StMAR model (similar to the StMAR model above) params12gs <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 3.6) gstmar12 <- GSMAR(p=1, M=c(1, 1), params=params12gs, model="G-StMAR") uncond_moments(gstmar12)
# GMAR model params13 <- c(1.4, 0.88, 0.26, 2.46, 0.82, 0.74, 5.0, 0.68, 5.2, 0.72, 0.2) gmar13 <- GSMAR(p=1, M=3, params=params13, model="GMAR") uncond_moments(gmar13) # StMAR model params12t <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 100, 3.6) stmar12t <- GSMAR(p=1, M=2, params=params12t, model="StMAR") uncond_moments(stmar12t) # G-StMAR model (similar to the StMAR model above) params12gs <- c(1.38, 0.88, 0.27, 3.8, 0.74, 3.15, 0.8, 3.6) gstmar12 <- GSMAR(p=1, M=c(1, 1), params=params12gs, model="G-StMAR") uncond_moments(gstmar12)
Wald_test
performs a Wald test for a GMAR, StMAR, or G-StMAR model.
Wald_test(gsmar, A, c, h = 6e-06)
Wald_test(gsmar, A, c, h = 6e-06)
gsmar |
a class 'gsmar' object, typically generated by |
A |
a size |
c |
a length |
h |
the difference used to approximate the derivatives. |
Denoting the true parameter value by , we test the null hypothesis
.
Under the null, the test statistic is asymptotically
-distributed with
(
=nrow(A)
) degrees of freedom. The parameter is assumed to have the same form as in
the model supplied in the argument
gsmar
and it is presented in the documentation of the argument
params
in the function GSMAR
(see ?GSMAR
).
Note that this function does not check whether the specified constraints are feasible (e.g., whether the implied constrained model would be stationary or have positive definite error term covariance matrices).
A list with class "htest" containing the following components:
statistic |
the value of the Wald statistics. |
parameter |
the degrees of freedom of the Wald statistic. |
p.value |
the p-value of the test. |
alternative |
a character string describing the alternative hypothesis. |
method |
a character string indicating the type of the test (Wald test). |
data.name |
a character string giving the names of the supplied model, constraint matrix A, and vector c. |
gsmar |
the supplied argument gsmar. |
A |
the supplied argument A. |
c |
the supplied argument c. |
h |
the supplied argument h. |
Kalliovirta L., Meitz M. and Saikkonen P. 2015. Gaussian Mixture Autoregressive model for univariate time series. Journal of Time Series Analysis, 36(2), 247-266.
Meitz M., Preve D., Saikkonen P. 2023. A mixture autoregressive model based on Student's t-distribution. Communications in Statistics - Theory and Methods, 52(2), 499-515.
Virolainen S. 2022. A mixture autoregressive model based on Gaussian and Student's t-distributions. Studies in Nonlinear Dynamics & Econometrics, 26(4) 559-580.
LR_test
, fitGSMAR
, GSMAR
, diagnostic_plot
,
profile_logliks
, quantile_residual_tests
, cond_moment_plot
# GMAR p=1, M=2 model: fit12 <- fitGSMAR(simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) # Test with Wald test whether the AR coefficients are the same in both # regimes: # There are 7 parameters in the model and the AR coefficient of the # first regime is the 2nd element, whereas the AR coefficient of the second # regime is in the 5th element. A <- matrix(c(0, 1, 0, 0, -1, 0, 0), nrow=1, ncol=7) c <- 0 Wald_test(fit12, A=A, c=c)
# GMAR p=1, M=2 model: fit12 <- fitGSMAR(simudata, p=1, M=2, model="GMAR", ncalls=1, seeds=1) # Test with Wald test whether the AR coefficients are the same in both # regimes: # There are 7 parameters in the model and the AR coefficient of the # first regime is the 2nd element, whereas the AR coefficient of the second # regime is in the 5th element. A <- matrix(c(0, 1, 0, 0, -1, 0, 0), nrow=1, ncol=7) c <- 0 Wald_test(fit12, A=A, c=c)