ErrorCrit_RMSE.R 1.24 KB
Newer Older
1
ErrorCrit_RMSE <- function(InputsCrit, OutputsModel, warnings = TRUE, verbose = TRUE) {
2
  
3
  ## Arguments check
4
  if (!inherits(OutputsModel, "OutputsModel")) {
5
    stop("'OutputsModel' must be of class 'OutputsModel'")
6
7
  }
  
8
  OutputsCritCheck <- .ErrorCrit(InputsCrit = InputsCrit, crit = "RMSE")
9
  
10
11
  if (!OutputsCritCheck$CritCompute) {
    CritValue <- NA
12
  } else {
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    ## ErrorCrit
    Numer <- sum((OutputsCritCheck$VarSim - OutputsCritCheck$VarObs)^2, na.rm = TRUE)
    Denom <- sum(!is.na(OutputsCritCheck$VarObs))
    
    if (Numer == 0) {
      Crit <- 0
    } else {
      Crit <- sqrt(Numer / Denom)
    }
    if (is.numeric(Crit) & is.finite(Crit)) {
      CritValue <- Crit
    }
    
    ## Verbose
    if (verbose) {
      message("Crit. ", OutputsCritCheck$CritName, " = ", sprintf("%.4f", CritValue), "\n")
    }
30
31
32
  }
  
  
33
  ## Output
34
  OutputsCrit <- list(CritValue       = CritValue,
35
36
37
38
                      CritName        = OutputsCritCheck$CritName,
                      CritBestValue   = OutputsCritCheck$CritBestValue,
                      Multiplier      = OutputsCritCheck$Multiplier,
                      Ind_notcomputed = OutputsCritCheck$Ind_TS_ignore)
39
40
41
42
43
  
  class(OutputsCrit) <- c("RMSE", "ErrorCrit")
  return(OutputsCrit)
  
}