% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/stepwise_ARCHmX.R
\name{stepwise}
\alias{stepwise}
\title{Performing Stepwise Variable Selection for an ARCH-m(X) or GARCHX Process}
\usage{
stepwise(
  target_model, 
  direction="forward",
  criterion="pvalue",
  adjust_method="fdr",
  alpha.level=0.05,
  trace = TRUE
)
}
\arguments{
\item{target_model}{A model object of class \code{ARCHmX}, \code{ARCHmXAdditive}, or \code{GARCHX}. This model must be fit on all available covariates and, in the case of \code{ARCHmX} and \code{ARCHmXAdditive}, the covariate hypothesis testing must have been set to \code{TRUE}. This model defines all the relevant attributes of the candidate models the stepwise selection process will consider.}
\item{direction}{The mode of stepwise search, can be one of "forward", "backward", "both_null" (both directions starting with the empty model), "both_full" (both directions starting with the full model), "bestsubset", and "onepass", with a default of "forward".}
\item{criterion}{The criterion for taking additional steps, default is "pvalue".}
\item{adjust_method}{Correction for multiple testing accumulation of error. See \link{p.adjust}.}
\item{alpha.level}{Defines the adjusted p-value significance level, default is 0.05.}
\item{trace}{If `TRUE`, information is printed for each step of variable selection. Default is `FALSE`. Offers summaries of prospective models as each predictor in the scope is added to or removed from the model. `max_pvalue` indicates the maximum p-value from the multiple tests for each predictor in the model.}
}
\value{
The final model chosen by the stepwise-selection process. 
}
\description{
Returns the fitted ARCH-m(X), additive ARCH-m(X), or GARCHX model resulting from the specified stepwise selection algorithm. 
}
\details{
The \code{forward} selection routine starts with a (null or empty) ARCH model. At each iteration, the current model is compared to an array of all possible models with one additional covariate. A forward step is taken to the candidate model with all significant covariates providing the most improvement in the specified criterion. If no such model exists, or if all covariates are exhausted, the current model is returned. 

The \code{backward} selection routine starts with the full ARCH-m(X), additive ARCH-m(X), or GARCHX model with all possible covariates. At each iteration, the current model is compared to an array of all possible models with one covariate removed. A backward step is taken to the candidate model providing the most improvement in the specified criterion until a model is found with all significant covariates, or until the logic reaches the empty model.

The \code{both_null} and \code{both_full} selection routines start with the null and full models, respectively. At each iteration, both forward and backward steps are attempted as outlined above. This continues until no step is taken, and the current model will be returned. The \code{pvalue} criterion can not be used for these routines since the p-value contstraints for forward and backward selection are incompatible with one another. 

The \code{best_subset} selection routine will build models for every possible combination of covariates and return the one with the best value for the specified criterion. 

The \code{onepass} selection routine builds the full model and returns a new model containing every covariate identified as significant within the full model. The only criterion available for \code{onepass} is \code{pvalue}. 

The user may specify p-value corrections to apply to the p-values used within the desired stepwise selection routine. All options provided by \code{p.adjust} are exposed to the user; the default is set to \code{fdr}.
}
\examples{
\donttest{
# We simulate a time series as in the simulate_ARCHmX example.
set.seed(1)
n <- 2000
alpha <- c(0.01, 0.02, 0.03)
valinit <- 200
X <- matrix(rnorm((n + valinit) * 5), ncol = 5)

m <- function(X) {
  abs(X[, 1])
}

data <- sim.ARCHmX(n = n, alpha = alpha, m = m, X = X, delta = 2, valinit = valinit)
p <- length(alpha)

# Output will show the trace from the empty model to the model with Covariate 1, 
# which is returned as stepwise_model.
target_ARCHmX_model <- ARCHmX(X = data$X, p = p, eps = data$eps)
stepwise_model <- stepwise(target_ARCHmX_model, direction="forward", criterion="pvalue") 
}
}