Title: | Estimate Univariate Gaussian and Student's t Mixture Autoregressive Models |
Version: | 3.6.0 |
Author: | Savi Virolainen |
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>. |
Depends: | R (≥ 3.4.0) |
BugReports: | https://github.com/saviviro/uGMAR/issues |
License: | GPL-3 |
Encoding: | UTF-8 |
LazyData: | true |
Imports: | Brobdingnag (≥ 1.2-4), parallel, pbapply (≥ 1.3-2), stats (≥ 3.3.2), gsl (≥ 1.9-10.3) |
Suggests: | testthat, knitr, rmarkdown |
RoxygenNote: | 7.3.2 |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2025-06-19 15:28:42 UTC; savi |
Repository: | CRAN |
Date/Publication: | 2025-06-19 16:20:02 UTC |
Maintainer: | Savi Virolainen <savi.virolainen@helsinki.fi> |
uGMAR: Estimate Univariate Gaussian and Student's t Mixture Autoregressive Models
Description
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.
Author(s)
Maintainer: Savi Virolainen savi.virolainen@helsinki.fi (ORCID)
See Also
Useful links:
Report bugs at https://github.com/saviviro/uGMAR/issues
Genetic algorithm for preliminary estimation of GMAR, StMAR, or G-StMAR model
Description
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.
Usage
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,
...
)
Arguments
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. |
Details
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.
Value
Returns estimated parameter vector with the form described in initpop
.
References
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.
Examples
## 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.
Create object of class 'gsmar' defining a GMAR, StMAR, or G-StMAR model
Description
GSMAR
creates an S3 object of class 'gsmar'
that defines a GMAR, StMAR, or G-StMAR model.
Usage
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)
Arguments
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 |
Details
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.
Value
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).
Functions
-
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
References
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.
See Also
fitGSMAR
, iterate_more
, add_data
, stmar_to_gstmar
,
swap_parametrization
, get_gradient
, simulate.gsmar
,
predict.gsmar
, cond_moments
, uncond_moments
, LR_test
, Wald_test
Examples
# 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
Perform likelihood ratio test
Description
LR_test
performs a likelihood ratio test for a GMAR, StMAR, or G-StMAR model.
Usage
LR_test(gsmar1, gsmar2)
Arguments
gsmar1 |
an object of class |
gsmar2 |
an object of class |
Details
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 \chi^2
-distributed with k
degrees of freedom,
k
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).
Value
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 |
References
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.
See Also
Wald_test
, fitGSMAR
, GSMAR
, diagnostic_plot
,
profile_logliks
, quantile_residual_tests
, cond_moment_plot
Examples
# 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)
Spread between 10-Year and 1-Year Treasury rates: M10Y1Y
Description
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.
Usage
M10Y1Y
Format
A class 'ts' time series object containing 468 observations.
Source
https://fred.stlouisfed.org/series/GS10 https://fred.stlouisfed.org/series/GS1
Spread between 10-Year and 1-Year Treasury rates: T10Y1Y
Description
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.
Usage
T10Y1Y
Format
A class 'ts' time series object containing 803 observations.
Source
https://fred.stlouisfed.org/series/GS10 https://fred.stlouisfed.org/series/GS1
Spread between the 3-month Treasury bill rate and the effective federal funds rate: TBFF
Description
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.
Usage
TBFF
Format
A class 'ts' time series object containing 781 observations.
Source
https://fred.stlouisfed.org/series/TB3SMFFM
References
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
Perform Wald test
Description
Wald_test
performs a Wald test for a GMAR, StMAR, or G-StMAR model.
Usage
Wald_test(gsmar, A, c, h = 6e-06)
Arguments
gsmar |
a class 'gsmar' object, typically generated by |
A |
a size |
c |
a length |
h |
the difference used to approximate the derivatives. |
Details
Denoting the true parameter value by \theta_{0}
, we test the null hypothesis A\theta_{0}=c
.
Under the null, the test statistic is asymptotically \chi^2
-distributed with k
(=nrow(A)
) degrees of freedom. The parameter \theta_{0}
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).
Value
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. |
References
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.
See Also
LR_test
, fitGSMAR
, GSMAR
, diagnostic_plot
,
profile_logliks
, quantile_residual_tests
, cond_moment_plot
Examples
# 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)
Add data to object of class 'gsmar' defining a GMAR, StMAR, or G-StMAR model
Description
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.
Usage
add_data(
data,
gsmar,
calc_qresiduals = TRUE,
calc_cond_moments = TRUE,
calc_std_errors = FALSE,
custom_h = NULL
)
Arguments
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 |
Value
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!
References
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.
See Also
fitGSMAR
, GSMAR
, iterate_more
, get_gradient
,
get_regime_means
, swap_parametrization
, stmar_to_gstmar
Examples
# 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
Add random dfs to a vector
Description
add_dfs
adds random degrees of freedom parameters to a vector.
Usage
add_dfs(x, how_many)
Arguments
x |
a vector to add the dfs to |
how_many |
how many dfs? |
Details
Read the source code for details.
Value
Returns c(x, dfs)
with how_many
dfs-elements.
Check whether all arguments are strictly positive natural numbers
Description
all_pos_ints
tells whether all the elements in a vector
are strictly positive natural numbers.
Usage
all_pos_ints(x)
Arguments
x |
a vector containing the elements to be tested. |
Value
Returns TRUE
or FALSE
accordingly.
Construct a GSMAR model based on results from an arbitrary estimation round of fitGSMAR
Description
alt_gsmar
constructs a GSMAR model based on results from an arbitrary estimation round of fitGSMAR
.
Usage
alt_gsmar(
gsmar,
which_round = 1,
which_largest,
calc_qresiduals = TRUE,
calc_cond_moments = TRUE,
calc_std_errors = TRUE,
custom_h = NULL
)
Arguments
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 |
Details
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
).
Value
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).
References
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.
See Also
fitGSMAR
, GSMAR
, iterate_more
, get_gradient
,
get_regime_means
, swap_parametrization
, stmar_to_gstmar
Examples
# 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
Calculate gradient or Hessian matrix
Description
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.
Usage
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)
Arguments
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 |
Details
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.
Value
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.
Warning
No argument checks!
See Also
Examples
# 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)
Change parametrization of a parameter vector
Description
change_parametrization
changes the parametrization of the given parameter
vector to change_to
.
Usage
change_parametrization(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
change_to = c("intercept", "mean")
)
Arguments
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 |
change_to |
either "intercept" or "mean" specifying to which parametrization it should be switched to.
If set to |
Value
Returns parameter vector described in params
but with parametrization changed from intercept to mean
(when change_to==mean
) or from mean to intercept (when change_to==intercept
).
Warning
No argument checks!
References
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.
Change the specified regime of parameter vector to the given regime-parameter vector
Description
change_regime
changes the specified regime of the parameter vector to correspond the given
regime-parameter vector and returns the modified parameter vector. Does not affect mixing weight parameters.
Usage
change_regime(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
regime_params,
regime
)
Arguments
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 |
regime_params |
a numeric vector specifying the parameter values that should be inserted to the specified regime.
|
regime |
a positive integer in the interval [1, M] defining which regime should be changed. |
Value
Returns modified parameter vector of the form described in params
.
Check that the data is set correctly and correct if not
Description
check_and_correct_data
checks that the data is set correctly and
throws an error if there is something wrong with the data.
Usage
check_and_correct_data(data, p)
Arguments
data |
a numeric vector or class |
p |
a positive integer specifying the autoregressive order of the model. |
Value
Returns the data as a class 'ts' object.
Check the constraint matrices
Description
check_constraint_mat
checks for some parts that the constraint matrices are correctly set.
Usage
check_constraint_mat(p, M, restricted = FALSE, constraints = NULL)
Arguments
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
Value
Doesn't return anything but throws an informative error if finds out that something is wrong.
Check that given object contains data
Description
check_data
checks that a given object contains data.
Usage
check_data(object)
Arguments
object |
an object to be tested |
Value
Doesn't return anything but throws and error if something is wrong.
Check that given object has class attribute 'gsmar'
Description
check_gsmar
checks that the given object has class attribute 'gsmar'.
Usage
check_gsmar(object, object_name = "gsmar")
Arguments
object |
an object to be tested |
object_name |
the name of the tested object |
Value
Doesn't return anything but throws and error if something is wrong.
Check that the argument 'model' is correctly specified.
Description
check_model
checks that the argument 'model' is correctly specified.
Usage
check_model(model)
Arguments
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
Value
Doesn't return anything but throws and error if something is wrong.
Check that p and M are correctly set
Description
check_pM
checks that the arguments p and M are correctly set.
Usage
check_pM(p, M, model = c("GMAR", "StMAR", "G-StMAR"))
Arguments
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 |
Value
Doesn't return anything but throws an informative error if something is wrong.
Check that the parameter vector has the correct dimension
Description
check_model
checks that the parameter vector has the correct dimension.
Usage
check_params_length(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL
)
Arguments
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 |
Value
Doesn't return anything but throws and error if something is wrong.
Conditional mean or variance plot for GMAR, StMAR, and G-StMAR models
Description
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.
Usage
cond_moment_plot(gsmar, which_moment = c("mean", "variance"))
Arguments
gsmar |
a class 'gsmar' object, typically generated by |
which_moment |
should conditional means or variances be plotted? |
Details
The conditional mean plot works best if the data contains positive values only.
Value
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.
References
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.
See Also
profile_logliks
, diagnostic_plot
, fitGSMAR
, GSMAR
, quantile_residual_tests
,
quantile_residual_plot
Examples
# 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")
Calculate conditional moments of GMAR, StMAR, or G-StMAR model
Description
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.
Usage
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")
)
Arguments
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 ( |
Value
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).
- if
to_return=="regime_cmeans"
: a size
((n_obs-p)\times M)
matrix containing the regime specific conditional means.- if
to_return=="regime_cvars"
: a size
((n_obs-p)\times M)
matrix containing the regime specific conditional variances.- if
to_return=="total_cmeans"
: a size
((n_obs-p)\times 1)
vector containing the total conditional means.- if
to_return=="total_cvars"
: a size
((n_obs-p)\times 1)
vector containing the total conditional variances.
References
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.
See Also
Other moment functions:
get_regime_autocovs()
,
get_regime_means()
,
get_regime_vars()
,
uncond_moments()
Examples
# 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")
Quantile residual based diagnostic plots for GMAR, StMAR, and G-StMAR models
Description
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).
Usage
diagnostic_plot(gsmar, nlags = 20, nsimu = 1, plot_indstats = FALSE)
Arguments
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 |
Details
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 1.96*T^{-1/2}
where T
is the sample size (minus the p
initial values for
conditional models).
Value
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.
Suggested packages
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".
References
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.
See Also
profile_logliks
, get_foc
, fitGSMAR
, cond_moment_plot
, quantile_residual_tests
,
quantile_residual_plot
, simulate.gsmar
, LR_test
, Wald_test
Examples
## 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)
Extract regime from a parameter vector
Description
extract_regime
extracts the specified regime from the GMAR, StMAR, or G-StMAR model parameter vector.
Doesn't extract mixing weight parameter \alpha
.
Usage
extract_regime(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
regime,
with_dfs = TRUE
)
Arguments
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 |
regime |
a positive integer in the interval [1, M] defining which regime should be extracted. |
with_dfs |
Should the degrees of freedom parameter (if any) be included? |
Value
Returns a numeric vector corresponding to the regime with...
- For non-restricted models:
-
- For GMAR model:
Size
(p+2\times 1)
vector(\phi_{m,0},\phi_{m,1},...,\phi_{m,p}, \sigma_{m}^2)
.- For StMAR model:
Size
(p+3\times 1)
vector(\phi_{m,0},\phi_{m,1},...,\phi_{m,p}, \sigma_{m}^2, \nu_{m})
.- For G-StMAR model:
Same as GMAR for GMAR type regimes and same as StMAR for StMAR type regimes.
- With linear constraints:
Parameter vector as described above, but vector
\phi_{m}
replaced with vector\psi_{m}
that satisfies\phi_{m}
=
R_{m}\psi_{m}
.
- For restricted models:
-
- For GMAR model:
Size
(2\times 1)
vector(\phi_{m,0}, \sigma_{m}^2)
.- For StMAR model:
Size
(3\times 1)
vector(\phi_{m,0}, \sigma_{m}^2, \nu_{m})
.- For G-StMAR model:
Same as GMAR for GMAR type regimes and same as StMAR for StMAR type regimes.
- With linear constraints:
Parameter vector as described above.
Estimate Gaussian or Student's t Mixture Autoregressive model
Description
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.
Usage
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,
...
)
Arguments
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 |
Details
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 1.0015
; a variance parameter estimat near zero (less than 0.0015
);
mixing weights such that they are close to zero for almost all t
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
.
Value
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.
S3 methods
The following S3 methods are supported for class 'gsmar'
objects: print
, summary
, plot
,
predict
, simulate
, logLik
, residuals
.
References
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.
See Also
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
Examples
## 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
Function factory for formatting values
Description
format_valuef
generates functions that format
values so that they print out with the desired number of digits.
Usage
format_valuef(digits)
Arguments
digits |
number of digits to use |
Value
Returns a function that takes an atomic vector as its argument
and returns it formatted to character with digits
decimals.
Calculate AIC, HQIC and BIC
Description
get_IC
calculates AIC, HQIC and BIC
Usage
get_IC(loglik, npars, obs)
Arguments
loglik |
log-likelihood value |
npars |
the number of (freely estimated) parameters in the model. |
obs |
the number of observations with initial values excluded for conditional models. |
Value
Returns a data frame containing the information criteria values.
Get mixing weights alpha_mt (this function is for internal use)
Description
get_alpha_mt
computes the mixing weights based on
the logarithm of the multivariate normal densities in the definition of
the mixing weights.
Usage
get_alpha_mt(
M,
log_mvnvalues,
alphas,
epsilon,
conditional,
to_return,
also_l_0 = FALSE
)
Arguments
M |
|
log_mvnvalues |
|
alphas |
|
epsilon |
the smallest number such that its exponent is wont classified as numerically zero
(around |
conditional |
a logical argument specifying whether the conditional or exact log-likelihood function should be used. |
to_return |
should the returned object be the log-likelihood value, mixing weights, mixing weights including
value for |
also_l_0 |
return also l_0 (the first term in the exact log-likelihood function)? |
Details
Note that we index the time series as -p+1,...,0,1,...,T
as in Kalliovirta et al. (2015).
Value
Returns the mixing weights a matrix of the same dimension as log_mvnvalues
so
that the t:th row is for the time point t and m:th column is for the regime m.
References
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.
See Also
Calculate absolute values of the roots of the AR characteristic polynomials
Description
get_ar_roots
calculates the absolute values of the roots of the AR
characteristic polynomials for each mixture component.
Usage
get_ar_roots(gsmar)
Arguments
gsmar |
a class 'gsmar' object, typically generated by |
Value
Returns a list with M
elements each containing the absolute values of the roots
of the AR characteristic polynomial corresponding to each mixture component.
References
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.
Examples
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)
Returns the default smallest allowed log-likelihood for given data.
Description
get_minval
returns the default smallest allowed log-likelihood for given data.
Usage
get_minval(data)
Arguments
data |
a numeric vector or class |
Details
This function exists simply to avoid duplication inside the package.
Value
Returns -(10^(ceiling(log10(length(data))) + 1) - 1)
See Also
Calculate regime specific autocovariances \gamma
_{m,p}
Description
get_regime_autocovs
calculates the first p regime specific autocovariances \gamma
_{m,p}
for the given GMAR, StMAR, or G-StMAR model.
Usage
get_regime_autocovs(gsmar)
Arguments
gsmar |
a class 'gsmar' object, typically generated by |
Value
Returns a size (pxM)
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.
References
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.
See Also
Other moment functions:
cond_moments()
,
get_regime_means()
,
get_regime_vars()
,
uncond_moments()
Examples
# 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)
Calculate regime specific means \mu_{m}
Description
get_regime_means
calculates the regime means \mu_{m} = \phi_{m,0}/(1-\sum\phi_{i,m})
for the given GMAR, StMAR, or G-StMAR model
Usage
get_regime_means(gsmar)
Arguments
gsmar |
a class 'gsmar' object, typically generated by |
Value
Returns a length M
vector containing the regime mean \mu_{m}
in the m:th element.
References
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.
See Also
cond_moments
, uncond_moments
, get_regime_vars
,
get_regime_autocovs
Other moment functions:
cond_moments()
,
get_regime_autocovs()
,
get_regime_vars()
,
uncond_moments()
Examples
# 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)
Calculate regime specific variances \gamma_{m,0}
Description
get_regime_vars
calculates the unconditional regime specific variances \gamma_{m,0}
for the given GMAR, StMAR, or G-StMAR model.
Usage
get_regime_vars(gsmar)
Arguments
gsmar |
a class 'gsmar' object, typically generated by |
Value
Returns a length M vector containing the unconditional variances of the components processes: m:th element for the m:th regime.
References
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.
See Also
Other moment functions:
cond_moments()
,
get_regime_autocovs()
,
get_regime_means()
,
uncond_moments()
Examples
# 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)
Generate the covariance matrix Omega for quantile residual tests
Description
get_test_Omega
generates the covariance matrix Omega used in the quantile residual tests.
Usage
get_test_Omega(
data,
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
parametrization = c("intercept", "mean"),
g,
dim_g
)
Arguments
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" |
g |
a function specifying the transformation. |
dim_g |
output dimension of the transformation |
Details
This function is used for quantile residuals tests in quantile_residual_tests
.
Value
Returns size (dim_g
xdim_g
) covariance matrix Omega.
References
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.
See Also
Get differences 'h' which are adjusted for overly large degrees of freedom parameters
Description
get_varying_h
adjusts differences for overly large degrees of freedom parameters
for finite difference approximation of the derivatives of the log-likelihood function. StMAR and
G-StMAR models are supported.
Usage
get_varying_h(p, M, params, model)
Arguments
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 |
Details
This function is used for approximating gradient and Hessian of a StMAR or G-StMAR model. Large degrees of freedom parameters cause significant numerical error if too small differences are used.
Value
Returns a vector with the same length as params
. For other parameters than degrees
of freedom parameters larger than 100, the differences will be 6e-6
. For the large degrees of
freedom parameters, the difference will be signif(df/1000, digits=2)
.
Check the stationary condition of specified GMAR, StMAR, or G-StMAR model.
Description
is_stationary
checks the stationarity condition of the specified GMAR, StMAR, or G-StMAR model.
Usage
is_stationary(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL
)
Arguments
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 |
Details
This function falsely returns FALSE
for stationary models when the parameter is extremely close
to the boundary of the stationarity region.
Value
Returns TRUE
or FALSE
accordingly.
References
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.
Examples
# 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))
Check the stationarity and identification conditions of specified GMAR, StMAR, or G-StMAR model.
Description
is_stationary_int
checks the stationarity condition and is_identifiable
checks the identification condition
of the specified GMAR, StMAR, or G-StMAR model.
Usage
is_stationary_int(p, M, params, restricted = FALSE)
is_identifiable(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL
)
Arguments
p |
a positive integer specifying the autoregressive order of the model. |
M |
|
params |
a real valued parameter vector specifying the model.
Symbol |
restricted |
a logical argument stating whether the AR coefficients |
model |
is "GMAR", "StMAR", or "G-StMAR" model considered? In the G-StMAR model, the first |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
Details
is_stationary_int
does not support models imposing linear constraints. In order to use it for a model imposing linear
constraints, one needs to expand the constraints first to obtain an unconstrained parameter vector.
Note that is_stationary_int
returns FALSE
for stationary parameter vectors if they are extremely close to the boundary
of the stationarity region.
is_identifiable
checks that the regimes are sorted according to the mixing weight parameters and that there are no duplicate
regimes.
Value
Returns TRUE
or FALSE
accordingly.
Warning
These functions don't have any argument checks!
References
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.
Maximum likelihood estimation of GMAR, StMAR, or G-StMAR model with preliminary estimates
Description
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.
Usage
iterate_more(gsmar, maxit = 100, custom_h = NULL, calc_std_errors = TRUE)
Arguments
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? |
Details
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
.
Value
Returns an object of class 'gsmar'
defining the estimated model.
References
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.
See Also
fitGSMAR
, GSMAR
, stmar_to_gstmar
,
profile_logliks
, optim
Examples
# 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
Compute the log-likelihood of GMAR, StMAR, or G-StMAR model
Description
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.
Usage
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
)
Arguments
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 |
Value
Returns the log-likelihood value or the terms described in return_terms
.
References
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.
See Also
fitGSMAR
, GSMAR
, quantile_residuals
,
mixing_weights
, calc_gradient
Examples
# 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")
Compute the log-likelihood of GMAR, StMAR, or G-StMAR model
Description
loglikelihood_int
computes the log-likelihood of the specified GMAR, StMAR, or G-StMAR model.
Usage
loglikelihood_int(
data,
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
conditional = TRUE,
parametrization = c("intercept", "mean"),
boundaries = TRUE,
checks = TRUE,
to_return = c("loglik", "mw", "mw_tplus1", "loglik_and_mw", "terms", "term_densities",
"regime_cmeans", "regime_cvars", "total_cmeans", "total_cvars", "qresiduals"),
minval
)
Arguments
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" |
boundaries |
a logical argument. If
Argument |
checks |
|
to_return |
should the returned object be the log-likelihood value, mixing weights, mixing weights including
value for |
minval |
this will be returned when the parameter vector is outside the parameter space and |
Value
Note that the first p observations are taken as the initial values so the mixing weights and conditional moments start from the p+1:th observation (interpreted as t=1).
- By default:
log-likelihood value of the specified model,
- If
to_return=="mw"
: a size
((n_obs-p)\times M)
matrix containing the mixing weights: for m:th component in the m:th column.- If
to_return=="mw_tplus1"
: a size
((n_obs-p+1)\times M)
matrix containing the mixing weights: for m:th component in the m:th column. The last row is for\alpha_{m,T+1}
.- If
to_return=="loglik_and_mw"
: a list of two elements. The first element contains the log-likelihood value and the second element contains the mixing weights.
- If
to_return=="terms"
: a size
((n_obs-p)\times 1)
numeric vector containing the termsl_{t}
.- If
to_return=="term_densities"
: a size
((n_obs-p)\times M)
matrix containing the conditional densities that summed over in the termsl_{t}
, as[t, m]
.- If
to_return=="regime_cmeans"
: a size
((n_obs-p)\times M)
matrix containing the regime specific conditional means.- If
to_return=="regime_cvars"
: a size
((n_obs-p)\times M)
matrix containing the regime specific conditional variances.- If
to_return=="total_cmeans"
: a size
((n_obs-p)\times 1)
vector containing the total conditional means.- If
to_return=="total_cvars"
: a size
((n_obs-p)\times 1)
vector containing the total conditional variances.- If
to_return=="qresiduals"
: a size
((n_obs-p)\times 1)
vector containing the quantile residuals.
References
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.
Calculate mixing weights of GMAR, StMAR or G-StMAR model
Description
mixing_weights
calculates the mixing weights of the specified GMAR, StMAR or G-StMAR model and returns them as a matrix.
Usage
mixing_weights(
data,
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
parametrization = c("intercept", "mean")
)
Arguments
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" |
Details
The first p observations are taken to be the initial values.
Value
- If
to_return=="mw"
: a size
((n_obs-p)\times M)
matrix containing the mixing weights: for m:th component in m:th column.- If
to_return=="mw_tplus1"
: a size
((n_obs-p+1)\times M)
matrix containing the mixing weights: for m:th component in m:th column. The last row is for\alpha_{m,T+1}
.
References
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.
Examples
# 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")
Calculate mixing weights of a GMAR, StMAR, or G-StMAR model
Description
mixing_weights_int
calculates the mixing weights of the specified GMAR, StMAR, or G-StMAR model
and returns them as a matrix.
Usage
mixing_weights_int(
data,
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
parametrization = c("intercept", "mean"),
checks = TRUE,
to_return = c("mw", "mw_tplus1")
)
Arguments
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" |
checks |
|
to_return |
should the returned object contain mixing weights for t=1,..,T ( |
Details
The first p observations are taken to be the initial values.
Value
- If
to_return=="mw"
: a size
((n_obs-p)\times M)
matrix containing the mixing weights: for m:th component in m:th column.- If
to_return=="mw_tplus1"
: a size
((n_obs-p+1)\times M)
matrix containing the mixing weights: for m:th component in m:th column. The last row is for\alpha_{m,T+1}
.
References
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.
Calculate the number of parameters
Description
n_params
calculates the number of parameters that should be in the parameter vector.
Usage
n_params(
p,
M,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL
)
Arguments
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 |
Value
Returns the number of parameters.
Check the parameter vector is specified correctly
Description
parameter_checks
checks dimension, restrictions, and stationarity of the given parameter
of a GMAR, StMAR, or G-StMAR model. Throws an error if any check fails. Does NOT consider the identifiability
condition!
Usage
parameter_checks(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL
)
Arguments
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 |
Value
Throws an informative error if any check fails. Does not return anything.
Pick mixing weights parameters from parameter vector
Description
pick_alphas
picks and returns the mixing weights parameters
(including the non-parametrized one for the last component) from the given
parameter vector.
Usage
pick_alphas(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL
)
Arguments
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 |
Value
Returns a vector of length M
containing the mixing weight parameters \alpha_m
.
Pick degrees of freedom parameters from a parameter vector
Description
pick_dfs
picks and returns the degrees of freedom parameters from
the given parameter vector.
Usage
pick_dfs(p, M, params, model = c("GMAR", "StMAR", "G-StMAR"))
Arguments
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 |
Value
Returns a vector of length M
or M2
containing the degrees of freedom parameters.
Pick \phi_0
(or \mu
), AR-coefficients, and variance parameters from a parameter vector
Description
pick_pars
picks \phi_0
/\mu
, AR-coefficients, and variance parameters from
the given parameter vector.
Usage
pick_pars(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL
)
Arguments
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 |
Value
Returns a ((p+2)\times M)
matrix containing the parameters, column for each component.
The first row for \phi_0
or \mu
depending on the parametrization, the second row
for \phi_1
, ..., the second to last row for \phi_p
, and the last row for \sigma^2
.
@keywords internal
Pick phi0 or mean parameters from parameter vector
Description
pick_phi0
picks and returns the phi0 or mean parameters from parameter vector.
Usage
pick_phi0(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL
)
Arguments
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 |
Value
Returns a vector of length M
containing the phi0 or mean parameters depending
parametrization.
Plot method for class 'gsmarpred' objects
Description
plot.gsmarpred
is plot method for class 'gsmarpred' objects
Usage
## S3 method for class 'gsmarpred'
plot(x, ..., nt, mix_weights = TRUE, add_grid = TRUE)
Arguments
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? |
Details
This method is intended for plotting forecasts of GSMAR processes.
Quantile residual tests for GMAR, StMAR , and G-StMAR models
Description
quantile_residual_tests
performs quantile residual tests for GMAR, StMAR,
and G-StMAR models, testing normality, autocorrelation, and conditional heteroscedasticity
of the quantile residuals.
Usage
## 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
)
Arguments
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. |
Details
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).
Value
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.
Functions
-
plot(qrtest)
: Plot p-values of the autocorrelation and conditional heteroskedasticity tests. -
print(qrtest)
: Print method for class 'qrtest' objects
References
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.
See Also
profile_logliks
, fitGSMAR
, GSMAR
, diagnostic_plot
,
predict.gsmar
, get_test_Omega
,
Examples
## 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))
Forecast GMAR, StMAR, or G-StMAR process
Description
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.
Usage
## 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
)
Arguments
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 |
Details
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.
Value
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 |
References
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.
See Also
simulate.gsmar
, cond_moments
, fitGSMAR
, GSMAR
,
quantile_residual_tests
, diagnostic_plot
Examples
## 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 method for class 'gsmarpred' objects
Description
print.gsmarpred
is a print method for call 'gsmarpred'
objects created with predict.gsmar
.
Usage
## S3 method for class 'gsmarpred'
print(x, ..., digits = 2)
Arguments
x |
object of class |
... |
currently not in use. |
digits |
the number of digits to be printed |
Print method from objects of class 'gsmarsum'
Description
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.
Usage
## S3 method for class 'gsmarsum'
print(x, ..., digits)
Arguments
x |
object of class 'gsmarsum' generated by |
... |
currently not in use. |
digits |
the number of digits to be printed |
Plot profile log-likelihoods around the estimates
Description
profile_logliks
plots profile log-likelihoods around the estimates.
Usage
profile_logliks(gsmar, scale = 0.02, nrows, ncols, precision = 200)
Arguments
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? |
Details
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.
Value
Only plots to a graphical device and doesn't return anything.
References
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.
See Also
quantile_residual_plot
, diagnostic_plot
, cond_moment_plot
, GSMAR
,
quantile_residual_tests
, simulate.gsmar
Examples
## 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)
Plot quantile residual time series and histogram
Description
quantile_residualsPlot
plots quantile residual time series and histogram.
Usage
quantile_residual_plot(gsmar)
Arguments
gsmar |
a class 'gsmar' object, typically generated by |
Value
Only plots to a graphical device and doesn't return anything.
References
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.
See Also
profile_logliks
, diagnostic_plot
, fitGSMAR
, GSMAR
,
quantile_residual_tests
, simulate.gsmar
Examples
## 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)
Compute quantile residuals of GMAR, StMAR, or G-StMAR model
Description
quantile_residuals
computes the quantile residuals of the specified GMAR, StMAR, or G-StMAR model.
Usage
quantile_residuals(
data,
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
parametrization = c("intercept", "mean")
)
Arguments
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" |
Details
Numerical integration is employed if the quantile residuals cannot be obtained analytically with the hypergeometric function using the package 'gsl'.
Value
Returns a (Tx1)
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.
References
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.
Examples
# 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")
Compute quantile residuals of GMAR, StMAR, or G-StMAR model
Description
quantile_residuals_int
computes the quantile residuals of the specified GMAR, StMAR, or G-StMAR model.
Usage
quantile_residuals_int(
data,
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
parametrization = c("intercept", "mean")
)
Arguments
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" |
Details
Numerical integration is employed if the quantile residuals cannot be obtained analytically with the hypergeometric function using the package 'gsl'.
Value
Returns a (Tx1)
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.
References
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.
Create random AR coefficients
Description
random_arcoefs
generates random AR coefficients.
Usage
random_arcoefs(p, forcestat = FALSE, sd = 0.6/p)
Arguments
p |
a positive integer specifying the autoregressive order of the model. |
forcestat |
use the algorithm by Monahan (1984) to force stationarity on the AR parameters (slower)? |
sd |
if |
Details
If forcestat==TRUE
, then the AR coefficients are relatively large, otherwise they are usually relatively small.
Value
Returns px1
vector containing random AR coefficients.
References
Monahan J.F. 1984. A Note on Enforcing Stationarity in Autoregressive-Moving Average Models. Biometrica 71, 403-404.
Create random GMAR, StMAR, or G-StMAR model compatible parameter vector
Description
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.
Usage
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
)
Arguments
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 |
Details
These functions can be used, for example, to create initial populations for the genetic algorithm. Mean-parametrization
(instead of intercept terms \phi_{m,0}
) is assumed.
Value
Returns estimated parameter vector with the form described in initpop
.
References
Monahan J.F. 1984. A Note on Enforcing Stationarity in Autoregressive-Moving Average Models. Biometrica 71, 403-404.
Examples
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)
Create random GMAR, StMAR, or G-StMAR model compatible parameter vector
Description
random_ind_int
creates a random GMAR, StMAR, or G-StMAR model compatible parameter vector.
smart_ind_int
creates a random GMAR, StMAR, or G-StMAR model compatible parameter vector close to argument params
.
Usage
random_ind_int(
p,
M,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
mu_scale,
sigma_scale,
forcestat = FALSE
)
smart_ind_int(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
mu_scale,
sigma_scale,
accuracy,
which_random,
forcestat = FALSE
)
Arguments
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 |
Value
Returns estimated parameter vector with the form described in initpop
.
References
Monahan J.F. 1984. A Note on Enforcing Stationarity in Autoregressive-Moving Average Models. Biometrica 71, 403-404.
Create random regime parameters
Description
random_regime
generates random regime parameters.
Usage
random_regime(
p,
mu_scale,
sigma_scale,
restricted = FALSE,
constraints = NULL,
m,
forcestat = FALSE
)
Arguments
p |
a positive integer specifying the autoregressive order of the model. |
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 |
restricted |
a logical argument stating whether the AR coefficients |
constraints |
specifies linear constraints imposed to each regime's autoregressive parameters separately.
The symbol |
m |
which regime? This is required for models with constraints for which a list of possibly differing constraint matrices is provided. |
forcestat |
use the algorithm by Monahan (1984) to force stationarity on the AR parameters (slower)? Not supported for constrained models. |
Details
If forcestat==TRUE
, then the AR coefficients are relatively large, otherwise they are usually relatively small.
Value
- Regular models:
\upsilon_{m}
=(\phi_{m,0},
\phi_{m}
,\sigma_{m}^2)
where\phi_{m}
=(\phi_{m,1},...,\phi_{m,p})
.- Restricted models:
Not supported!
- Constrained models:
Replace the vectors
\phi_{m}
with vectors\psi_{m}
.
References
Monahan J.F. 1984. A Note on Enforcing Stationarity in Autoregressive-Moving Average Models. Biometrica 71, 403-404.
Reform parameter vector with linear constraints to correspond non-constrained parameter vector.
Description
reform_constrained_pars
reforms the parameter vector of a model with linear constrains
to the "standard form" so that it's comparable with non-constrained models.
Usage
reform_constrained_pars(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL
)
Arguments
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 |
Value
Returns such parameter vector corresponding to the input vector that is the form described in params
for non-restricted or restricted models (for non-constrained models), and can hence be used just as the
parameter vectors of non-constrained models.
Reform any parameter vector into standard form.
Description
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.
Usage
reform_parameters(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE
)
Arguments
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 |
Details
This function does not support models imposing linear constraints. No argument checks in this function.
Value
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"
ormodel == "G-StMAR"
.
@keywords internal
Reform parameter vector with restricted autoregressive parameters to correspond non-restricted parameter vector.
Description
reform_restricted_pars
reforms parameter vector with restricted autoregressive parameters to correspond
non-restricted parameter vector.
Usage
reform_restricted_pars(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE
)
Arguments
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 |
Value
Returns such parameter vector corresponding to the input vector that is the form described in params
for non-restricted models (for non-constrained models). Linear constraints are not supported.
Calculate "distance" between two regimes
Description
regime_distance
scales each regime parameter to the same magnitude
and then calculates distance between scaled regime_pars1
and regime_pars2
.
Usage
regime_distance(regime_pars1, regime_pars2)
Arguments
regime_pars1 |
a numeric vector representing a regime. |
regime_pars2 |
a numeric vector representing another regime, same length as |
Value
Returns "distance" between regime_pars1
and regime_pars2
. Values are scaled
to the same magnitude before calculating the "distance". Read the source code for details.
Transform constrained and restricted parameter vector into the regular form
Description
remove_all_constraints
transforms constrained and restricted parameter vector into the regular form.
Usage
remove_all_constraints(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL
)
Arguments
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 |
Value
Returns such parameter vector corresponding to the input vector that is the form described in params
for non-restricted and non-constrained models.
Simulated data
Description
A dataset containing 200 observations simulated from a GMAR p=1, M=2 process.
Usage
simudata
Format
A numeric vector of length 200.
Source
Simulated
Simulate obsercations from GMAR, StMAR, and G-StMAR processes
Description
simulate.gsmar
simulates observations from the specified GMAR, StMAR, or G-StMAR process.
Can be utilized for forecasting future values of the process.
Usage
## S3 method for class 'gsmar'
simulate(
object,
nsim = 1,
seed = NULL,
...,
init_values = NULL,
ntimes = 1,
drop = TRUE
)
Arguments
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 |
Details
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.
Value
If drop==TRUE
and ntimes==1
(default): $sample
and $component
are vectors
and $mixing_weights
is a (nsim
\times M
) matrix. Otherwise, returns a list with...
$sample
a size (
nsim
\times
ntimes
) matrix containing the simulated values.$component
a size (
nsim
\times
ntimes
) matrix containing the information from which mixture component each value was generated from.$mixing_weights
a size (
nsim
\times M\times
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.
References
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.
See Also
fitGSMAR
, GSMAR
, predict.gsmar
,
add_data
, cond_moments
, mixing_weights
Examples
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
Sort the mixture components of a GMAR, StMAR, or G-StMAR model
Description
sort_components
sorts mixture components of the specified GMAR, StMAR, or G-StMAR model
according to the mixing weight parameters when the parameter vector has the "standard/regular form" for
restricted or non-restricted models.
Usage
sort_components(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE
)
Arguments
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 |
Details
This function does not support models imposing linear constraints.
Value
Returns a parameter vector sorted according to its mixing weight parameters,
described in params
.
Calculate standard errors for estimates of a GMAR, StMAR, or G-StMAR model
Description
standard_errors
numerically approximates standard errors for the given estimates of GMAR, StMAR, or GStMAR model.
Usage
standard_errors(
data,
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
conditional = TRUE,
parametrization = c("intercept", "mean"),
custom_h = NULL,
minval
)
Arguments
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" |
custom_h |
a numeric vector with the same length as |
minval |
this will be returned when the parameter vector is outside the parameter space and |
Value
Returns approximate standard errors of the parameter values in a numeric vector.
Estimate a G-StMAR model based on a StMAR model with large degrees of freedom parameters
Description
stmar_to_gstmar
estimates a G-StMAR model based on a StMAR model with large degree
of freedom parameters.
Usage
stmar_to_gstmar(
gsmar,
maxdf = 100,
estimate,
calc_std_errors,
maxit = 100,
custom_h = NULL
)
Arguments
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 |
Details
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.
Value
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).
References
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.
See Also
fitGSMAR
, GSMAR
, iterate_more
, get_gradient
,
get_regime_means
, swap_parametrization
, stmar_to_gstmar
Examples
# 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
Transform a StMAR or G-StMAR model parameter vector to a corresponding G-StMAR model parameter vector with large dfs parameters reduced.
Description
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.
Usage
stmarpars_to_gstmar(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
maxdf = 100
)
Arguments
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. |
Value
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.
Examples
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 the parametrization of object of class 'gsmar' defining a GMAR, StMAR, or G-StMAR model
Description
swap_parametrization
swaps the parametrization of object of class 'gsmar
'
to "mean"
if the current parametrization is "intercept"
, and vice versa.
Usage
swap_parametrization(gsmar, calc_std_errors = TRUE, custom_h = NULL)
Arguments
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 |
Details
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.
Value
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).
References
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.
See Also
fitGSMAR
, GSMAR
, iterate_more
, get_gradient
,
get_regime_means
, swap_parametrization
, stmar_to_gstmar
Examples
# 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)
Calculate unconditional mean, variance, first p autocovariances and autocorrelations of the GSMAR process.
Description
uncond_moments
calculates the unconditional mean, variance, and the first p autocovariances
and autocorrelations of the GSMAR process.
Usage
uncond_moments(gsmar)
Arguments
gsmar |
a class 'gsmar' object, typically generated by |
Value
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.
References
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.
See Also
Other moment functions:
cond_moments()
,
get_regime_autocovs()
,
get_regime_means()
,
get_regime_vars()
Examples
# 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)
Calculate unconditional mean, variance, and the first p autocovariances and autocorrelations of a GSMAR process.
Description
uncond_moments_int
calculates the unconditional mean, variance, and the first p
autocovariances and autocorrelations of the specified GSMAR process.
Usage
uncond_moments_int(
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
restricted = FALSE,
constraints = NULL,
parametrization = c("intercept", "mean")
)
Arguments
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" |
Details
Differs from the function uncond_moments
in arguments. This function exists for technical
reasons only.
Value
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.
References
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.
Warn about near-unit-roots in some regimes
Description
warn_ar_roots
warns if the model contains near-unit-roots in some regimes
Usage
warn_ar_roots(gsmar, tol = 0.005)
Arguments
tol |
if some root is smaller that |
Details
Warns if some moduli of the autoregressive polynomial's roots are close to one.
Value
Doesn't return anything.
Warn about large degrees of freedom parameter values
Description
warn_dfs
warns if the model contains large degrees of freedom parameter values.
Usage
warn_dfs(
object,
p,
M,
params,
model = c("GMAR", "StMAR", "G-StMAR"),
warn_about = c("derivs", "errors")
)
Arguments
object |
an object to be tested |
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 |
warn_about |
warn about inaccurate derivatives or standard errors? |
Details
Either provide a class 'gsmar' object or specify the model by hand.
Value
Doesn't return anything but throws a warning if any degrees of freedom parameters have value larger than 100.