ErrorCrit_RMSE.R 1.13 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
  EC <- .ErrorCrit(InputsCrit = InputsCrit, Crit = "RMSE",  OutputsModel = OutputsModel, warnings = warnings)
9
  
10
11
12
  CritValue <- NA
  
  if (EC$CritCompute) {
13
    ## ErrorCrit
14
15
    Numer <- sum((EC$VarSim - EC$VarObs)^2, na.rm = TRUE)
    Denom <- sum(!is.na(EC$VarObs))
16
17
18
19
20
21
22
23
24
25
26
27
    
    if (Numer == 0) {
      Crit <- 0
    } else {
      Crit <- sqrt(Numer / Denom)
    }
    if (is.numeric(Crit) & is.finite(Crit)) {
      CritValue <- Crit
    }
    
    ## Verbose
    if (verbose) {
28
      message(sprintf("Crit. %s = %.4f", EC$CritName, CritValue))
29
    }
30
31
32
  }
  
  
33
  ## Output
34
  OutputsCrit <- list(CritValue       = CritValue,
35
36
37
38
                      CritName        = EC$CritName,
                      CritBestValue   = EC$CritBestValue,
                      Multiplier      = EC$Multiplier,
                      Ind_notcomputed = EC$Ind_TS_ignore)
39
40
41
42
43
  
  class(OutputsCrit) <- c("RMSE", "ErrorCrit")
  return(OutputsCrit)
  
}