View source: R/geneticAlgorithm.R
GAfit | R Documentation |
GAfit
estimates the specified reduced form STVAR model using a genetic algorithm.
It is designed to find starting values for gradient based methods and NOT to obtain final estimates
constituting a local maximum.
GAfit(
data,
p,
M,
weight_function = c("relative_dens", "logistic", "mlogit", "exponential", "threshold",
"exogenous"),
weightfun_pars = NULL,
cond_dist = c("Gaussian", "Student", "ind_Student", "ind_skewed_t"),
parametrization = c("intercept", "mean"),
AR_constraints = NULL,
mean_constraints = NULL,
weight_constraints = NULL,
ngen = 200,
popsize,
smart_mu = min(100, ceiling(0.5 * ngen)),
initpop = NULL,
mu_scale,
mu_scale2,
omega_scale,
B_scale,
weight_scale,
ar_scale = 0.2,
upper_ar_scale = 1,
ar_scale2 = 1,
regime_force_scale = 1,
penalized,
penalty_params = c(0.05, 0.5),
allow_unstab,
red_criteria = c(0.05, 0.01),
bound_by_weights,
pre_smart_mu_prob = 0,
to_return = c("alt_ind", "best_ind"),
minval,
fixed_params = NULL,
fixed_params_in_smart_mu = TRUE,
seed = NULL
)
data |
a matrix or class |
p |
a positive integer specifying the autoregressive order |
M |
a positive integer specifying the number of regimes |
weight_function |
What type of transition weights
See the vignette for more details about the weight functions. |
weightfun_pars |
|
cond_dist |
specifies the conditional distribution of the model as |
parametrization |
|
AR_constraints |
a size |
mean_constraints |
Restrict the mean parameters of some regimes to be identical? Provide a list of numeric vectors
such that each numeric vector contains the regimes that should share the common mean parameters. For instance, if
|
weight_constraints |
a list of two elements, |
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 (which has the least regimes with time varying mixing weights practically at zero) so far. |
initpop |
a list of parameter vectors from which the initial population of the genetic algorithm
will be generated from. The parameter vectors hould have the form
For models with...
Above, |
mu_scale |
a size |
mu_scale2 |
a size |
omega_scale |
a size |
B_scale |
a size |
weight_scale |
For...
|
ar_scale |
a positive real number between zero and one adjusting how large AR parameter values are typically
proposed in construction of the initial population: larger value implies larger coefficients (in absolute value).
After construction of the initial population, a new scale is drawn from |
upper_ar_scale |
the upper bound for |
ar_scale2 |
a positive real number adjusting how large AR parameter values are typically proposed in some random mutations (if AR constraints are employed, in all random mutations): larger value implies smaller coefficients (in absolute value). Values larger than 1 can be used if the AR coefficients are expected to be very small. If set smaller than 1, be careful as it might lead to failure in the creation of parameter candidates that satisfy the stability condition. |
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. Set to zero for no favoring or large
number for heavy favoring. Without any favoring the genetic algorithm gets more often stuck in an area of the
parameter space where some regimes are wasted, but with too much favouring the best genes might never mix into
the population and the algorithm might converge poorly. Default is |
penalized |
Perform penalized LS estimation that minimizes penalized RSS in which estimates close to breaking or not satisfying the
usual stability condition are penalized? If |
penalty_params |
a numeric vector with two positive elements specifying the penalization parameters: the first element determined how far from the boundary of the stability region the penalization starts (a number between zero and one, smaller number starts penalization closer to the boundary) and the second element is a tuning parameter for the penalization (a positive real number, a higher value penalizes non-stability more). |
allow_unstab |
If |
red_criteria |
a length 2 numeric vector specifying the criteria that is used to determine whether a regime is
redundant (or "wasted") or not.
Any regime |
bound_by_weights |
should the parameter space be constrained to areas where the transition weights do allocate
enough weights to each regime compared to the number of observations in the regime? See the source code of
the function |
pre_smart_mu_prob |
A number in |
to_return |
should the genetic algorithm return the best fitting individual which has "positive enough" mixing
weights for as many regimes as possible ( |
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 |
fixed_params |
a vector containing fixed parameter values for intercept, autoregressive, and weight parameters
that should be fixed in the initial population. Should have the form:
For models with...
Note that |
fixed_params_in_smart_mu |
should the fixed parameters be fixed in the smart mutation phase as well? If |
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 |
Only reduced form models are supported!
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).
By "redundant" or "wasted" regimes we mean regimes that have the time varying mixing weights practically at zero for almost all t. A model including redundant regimes would have about the same log-likelihood value without the redundant regimes and there is no purpose to have redundant regimes in a model.
Some of the AR coefficients are drawn with the algorithm by Ansley and Kohn (1986). However,
when using large ar_scale
with large p
or d
, numerical inaccuracies caused
by the imprecision of the float-point presentation may result in errors or nonstationary AR-matrices.
Using smaller ar_scale
facilitates the usage of larger p
or d
. Therefore, we bound
upper_ar_scale
from above by 1-pd/150
when p*d>40
and by 1
otherwise.
Structural models are not supported here, as they are best estimated based on reduced form parameter estimates
using the function fitSSTVAR
.
Returns the estimated parameter vector which has the form described in initpop
,
with the exception that for models with cond_dist == "ind_Student"
or
"ind_skewed_t"
, the parameter vector is parametrized with B_1,B_2^*,...,B_M^*
instead of B_1,B_2,...,B_M
, where B_m^* = B_m - B_1
. Use the function change_parametrization
to change back to the original parametrization if desired.
Ansley C.F., Kohn R. 1986. A note on reparameterizing a vector autoregressive moving average model to enforce stationarity. Journal of statistical computation and simulation, 24:2, 99-106.
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.
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.