Generate a Random Model
r_model.Rd
This function may be used to generate random state space or VARMA models.
The main argument is a model template, which defines the type of model to generate,
see e.g. model structures()
.
If bounds for the poles and/or the zeroes are given,
then the procedure simply generates random models until a model which satisfies the constraint is found.
Of course this is a very crude method and it may need a large number of randomly generated model.
Usage
r_model(
template,
ntrials.max = 100,
bpoles = NULL,
bzeroes = NULL,
rand.gen = stats::rnorm,
...
)
Arguments
- template
A model template as computed e.g. by
model2template()
.- ntrials.max
Maximum number of trials.
- bpoles, bzeroes
Lower bounds on the poles and zeroes of the model (such that stability and invertibility assumptions are satisfied). If set to
NA
, then the corresponding test is skipped.- rand.gen
(optional) A function to generate the random, "free" parameters.
- ...
Additional parameters, passed on to
rand.gen
. In particular, if the "free" paramameters are generated byrnorm()
, then the standard deviationsd
may be set. Choosing small values forsd
makes it easier to find a stable and miniphase model. Of course this "trick" only works if the reference model, which is obtained with a zero parameter vector, satisfies the constraints.
Examples
# Generate a random VARMA model in echelon form ############
# Compute the appropriate model template
tmpl = tmpl_arma_echelon(nu = c(1,2,1))
# Create a random model, which is stable but not necessarily miniphase
model = r_model(tmpl, bpoles = 1, sd = 0.5)
model
#> ARMA model [3,3] with orders p = 2 and q = 2
#> AR polynomial a(z):
#> z^0 [,1] [,2] [,3] z^1 [,1] [,2] [,3] z^2 [,1]
#> [1,] 1 0.000000 0 -0.2230435 -0.09862739 -0.19911985 0.00000000
#> [2,] 0 1.000000 0 0.0000000 0.10891433 0.00000000 0.08518435
#> [3,] 0 0.418622 1 0.2510531 0.06956840 0.05433312 0.00000000
#> [,2] [,3]
#> [1,] 0.0000000 0.0000000
#> [2,] -0.3917393 0.8690266
#> [3,] 0.0000000 0.0000000
#> MA polynomial b(z):
#> z^0 [,1] [,2] [,3] z^1 [,1] [,2] [,3] z^2 [,1]
#> [1,] 1 0.000000 0 -0.5002612 -0.26449849 -0.2369659 0.0000000
#> [2,] 0 1.000000 0 1.3306812 0.03203034 -0.2724562 -0.5397279
#> [3,] 0 0.418622 1 0.0840577 -0.12188649 0.1518820 0.0000000
#> [,2] [,3]
#> [1,] 0.0000000 0.0000000
#> [2,] 0.2843032 -0.8556644
#> [3,] 0.0000000 0.0000000
#> Left square root of noise covariance Sigma:
#> u[1] u[2] u[3]
#> u[1] 0.13235178 0.0000000 0.0000000
#> u[2] 0.12266369 -0.5161338 0.0000000
#> u[3] -0.05594441 -0.2964049 0.6447166
# Check whether the poles satisfy the constraint
min(abs(poles(model)))
#> There are determinantal roots at (or close to) infinity.
#> Roots close to infinity got discarded.
#> [1] 1.10882
min(abs(zeroes(model)))
#> There are determinantal roots at (or close to) infinity.
#> Roots close to infinity got discarded.
#> [1] 1.118997