ErrorCrit_RMSE.R 1.23 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
9
10
  if (!inherits(InputsCrit, "Single")) {
    stop("'ErrorCrit_RMSE' can only be used with 'InputsCrit' of class 'Single'")
  }

11
  EC <- .ErrorCrit(InputsCrit = InputsCrit, Crit = "RMSE",  OutputsModel = OutputsModel, warnings = warnings)
12

13
  CritValue <- NA
14

15
  if (EC$CritCompute) {
16
    ## ErrorCrit
17
18
    Numer <- sum((EC$VarSim - EC$VarObs)^2, na.rm = TRUE)
    Denom <- sum(!is.na(EC$VarObs))
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
    }
28

29
30
    ## Verbose
    if (verbose) {
31
      message(sprintf("Crit. %s = %.4f", EC$CritName, CritValue))
32
    }
33
  }
34
35


36
  ## Output
37
  OutputsCrit <- list(CritValue       = CritValue,
38
39
40
41
                      CritName        = EC$CritName,
                      CritBestValue   = EC$CritBestValue,
                      Multiplier      = EC$Multiplier,
                      Ind_notcomputed = EC$Ind_TS_ignore)
42

43
44
  class(OutputsCrit) <- c("RMSE", "ErrorCrit")
  return(OutputsCrit)
45

46
}