ErrorCrit_RMSE.R 1.16 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
  CritValue <- NA
11

12
  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
    if (Numer == 0) {
      Crit <- 0
    } else {
      Crit <- sqrt(Numer / Denom)
    }
    if (is.numeric(Crit) & is.finite(Crit)) {
      CritValue <- Crit
    }
25

26
27
    ## 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
  class(OutputsCrit) <- c("RMSE", "ErrorCrit")
  return(OutputsCrit)
42

43
}
Dorchies David's avatar
Dorchies David committed
44
45

class(ErrorCrit_RMSE) <- c("FUN_CRIT", class(ErrorCrit_RMSE))