# =========================================================================
# Cross validation mode wrapper for bocm.R
# Omits jth row and makes prediction on remaining data
# requires Exp to be a two dimensional array (no. of years * no. of exp)
# requires Obs to be a vector of length=no. of years
# =========================================================================

# Data_WMMt <- Data_WMM[,,16,25]
# Exp <- Data_WMMt[,1:4]
# Obs <- Data_WMMt[,5]


bocm_wrapper <- function(j, obs, exp) {
  
  # combine data
  Data <- as.data.frame(cbind(exp, obs))
  
  
  # remove jth row from dataset
  if(j > 0) {
    Data <- Data[-j, ]
  }
  
  
  # for dataset without jth row 
  # extract prediction based on best OLS combination of models (OLS)
  #source("~/2_SForecastAssessment/R/Tests/bocm/bocm.R")
  #source("~/Desktop/BSC/Journal/R/Tests/bocm/bocm.R")
  weight <- bocm(Data[ ,-5], Data[ ,5])[[1]]
  predict <- weight %*% Exp[j,]
  
  return(predict)
  
}

#bocm_wrapper(5, Obs,Exp)