R/run_simest.R

#' Run 2D simulation-estimation experiment
#'
#' Function that simulates data sets and estimates parameters using both circular and
#'     non-circular/regular approach.
#' @param param Numeric vector of length 2, consiting of \eqn{\alpha_0} and \eqn{\alpha_1}.
#' @param dim Numeric vector of length 3, indicating dimension size on form spatial1 x spatial2 x temporal
#' @param burnin Integer, size of temporal burnin
#' @param cutoff Integer, number of spatial points to be "cut off" in each spatial direction in order
#' to make the simulated process non-circular. If \code{cutoff=0}, the process is circular.
#' @param W Neighbourhood matrix
#' @param ncores Integer, number of cores used for parallell computing
#' @param K Integer, determines the number of Monte Carlo simulations to be performed
#' @param n.iterations Integer, maximum number of iterations
#' @return Simulated STARCH process in form of a matrix of dimension \code{dim}.
#' @import doParallel
#' @import foreach
#' @examples
#' run_2d_simest(param = c(0.3, 0.05),
#'               dim = c(5,5,100),
#'               K = 50,
#'               n.iterations = 30,
#'               ncores = detectCores()-1,
#'               burnin = 100,
#'               cutoff = 0,
#'               W = neighbourmatrix(5,25))
#' @export

run_2d_simest<-function(param = c(.3,.05),
              dim = c(5,5,1000),
              K = 100,
              n.iterations = 30,
              ncores = doParallel::detectCores()-1,
              burnin = 1000,
              cutoff= 0,
              W=neighbourmatrix(dim[1],prod(dim[1:2]))){

  #This function shall run the experiments
  doParallel::registerDoParallel(cores=ncores)
  result<-foreach::foreach(i = 1:K, .combine=rbind) %dopar% {
    X<-simulation_2d_arch(param, dim, burnin, cutoff)
    cir<-est(X=X, n.iterations=n.iterations, return_all = FALSE, W = W, circular = TRUE, LSE=TRUE)
    reg<-est(X=X, n.iterations=n.iterations, return_all = FALSE, W = W, circular = FALSE, LSE=TRUE)
    retur<-c(cir, reg)
    retur
  }
  return(t(matrix(apply(result, 2, mean), ncol=2)))
}
Sondre91/STGARCH documentation built on May 9, 2019, 1:52 p.m.