R/auto.fit.R

Defines functions auto.fit

Documented in auto.fit

# Estimate coefficients of time series by cv

source(paste(getwd(), "/R/SIMle.Legen.v1.R", sep = ""))
source(paste(getwd(), "/R/SIMle.Cheby.v1.R", sep = ""))
source(paste(getwd(), "/R/SIMle.Four.v1.R", sep = ""))
source(paste(getwd(), "/R/SIMle.Csp.v1.R", sep = ""))
source(paste(getwd(), "/R/SIMle.db1-20.v1.R", sep = ""))
source(paste(getwd(), "/R/SIMle.plot.v1.R", sep = ""))
source(paste(getwd(), "/R/SIMle.original_code.v1.R", sep = ""))
source(paste(getwd(), "/R/cv.res.R", sep = ""))


#' Automated estimation of nonlinear time series regression
#' @description This function estimates nonlinear time series regression by sieve methods with chosen bases.
#'
#' @param ts ts is the data set which is a time series data typically
#' @param c the maximum value of number of basis for time input 
#' @param d the maximum value of number of basis for variate input 
#' @param b_time type of basis for time input 
#' @param b_timese type of basis for variate input
#' @param mp_type select type of mapping function, "algeb" indicates algebraic mapping on the real line. "logari" represents logarithmic mapping on the real line
#' @param type select type of estimation."nfix" refers to no fix estimation. "fixt" indicates fix time t estimation. 
#'             "fixx" represents fix variate estimation
#' @param ops Criteria for choosing the number of bases are provided by the package, offering four options: "AIC," "BIC," "CV," and "Kfold," each corresponding to a 
#'        specific Criteria 
#' @param per the percentage for test set used in cross validation option "CV"
#' @param k the number of fold used in k-fold cross validation "Kfold"
#' @param fix_num fix_num indicates the use of fixed-value nonlinear time series regression. The default value is 0, which is employed for non-fixed estimation. 
#'        If "fixt" is chosen, it represents a fixed time value. Otherwise, if not selected, it pertains to a fixed variate value
#' @param r indicates number of variate 
#' @param s s is a positive scaling factor, the default is 1
#' @param upper upper The upper bound for the variate basis domain. The default value is 10. When "algeb" or "logari" is chosen, the domain is automatically set from -upper to upper
#'
#' 
#' @return If "nfix" is selected, the function returns a list where each element is a matrix representing the estimation function in two dimensions. Otherwise, 
#'         if "nfix" is not selected, the function returns a list where each element is a vector representing the estimation function.
#' @export


auto.fit = function(ts, c, d, b_time, b_timese, mp_type, type, ops, per = 0, k = 0, fix_num = 0, r = 1, s = 1, upper = 10){
  best_cd = best_cd.auto.fit(ts, c, d, b_time, b_timese, mp_type, ops, r = r, s = s, per = per, k = k)
  basis_candi = c("Legen","Cheby","tri", "cos", "sin", "Cspli", "db1", "db2", "db3", "db4", "db5",
                  "db6", "db7", "db8", "db9", "db10",
                  "db11", "db12", "db13", "db14", "db15",
                  "db16", "db17", "db18", "db19", "db20",
                  "cf1", "cf2", "cf3", "cf4", "cf5"
  )
  
  if((b_time %in% basis_candi) && (b_timese %in% basis_candi)){
    if(type == "nfix"){
      res = general_esti(ts, best_cd[1], best_cd[2], b_time, b_timese, mp_type, r, s, upper = upper)
      return(res)
    } else if(type == "fixt"){
      res = fix_t_esti(ts, best_cd[1], best_cd[2], fix_num, b_time, b_timese, mp_type, r = r, s = s, upper = upper)
      return(res)
    } else if(type == "fixx"){
      res = fix_x_esti(ts, best_cd[1], best_cd[2], fix_num, b_time, b_timese, mp_type, r = r, s = s, upper = upper)
      return(res)
    } else{
      return(stop("Invalid option!"))
    }
    
  } else{
    return(stop("Invalid option!"))
  }
}

Try the SIMle package in your browser

Any scripts or data that you put into this service are public.

SIMle documentation built on Oct. 11, 2023, 1:07 a.m.