diff --git a/R/ErrorCrit_RMSE.R b/R/ErrorCrit_RMSE.R index 6cab33bc57147355c0603f6cfd86daf8904c1bee..ce1b78fe09e7880cea9cb744013b9dd279815dca 100644 --- a/R/ErrorCrit_RMSE.R +++ b/R/ErrorCrit_RMSE.R @@ -1,19 +1,22 @@ ErrorCrit_RMSE <- function(InputsCrit, OutputsModel, warnings = TRUE, verbose = TRUE) { - + ## Arguments check if (!inherits(OutputsModel, "OutputsModel")) { stop("'OutputsModel' must be of class 'OutputsModel'") } - + if (!inherits(InputsCrit, "Single")) { + stop("'ErrorCrit_RMSE' can only be used with 'InputsCrit' of class 'Single'") + } + EC <- .ErrorCrit(InputsCrit = InputsCrit, Crit = "RMSE", OutputsModel = OutputsModel, warnings = warnings) - + CritValue <- NA - + if (EC$CritCompute) { ## ErrorCrit Numer <- sum((EC$VarSim - EC$VarObs)^2, na.rm = TRUE) Denom <- sum(!is.na(EC$VarObs)) - + if (Numer == 0) { Crit <- 0 } else { @@ -22,22 +25,22 @@ ErrorCrit_RMSE <- function(InputsCrit, OutputsModel, warnings = TRUE, verbose = if (is.numeric(Crit) & is.finite(Crit)) { CritValue <- Crit } - + ## Verbose if (verbose) { message(sprintf("Crit. %s = %.4f", EC$CritName, CritValue)) } } - - + + ## Output OutputsCrit <- list(CritValue = CritValue, CritName = EC$CritName, CritBestValue = EC$CritBestValue, Multiplier = EC$Multiplier, Ind_notcomputed = EC$Ind_TS_ignore) - + class(OutputsCrit) <- c("RMSE", "ErrorCrit") return(OutputsCrit) - + } diff --git a/R/UtilsErrorCrit.R b/R/UtilsErrorCrit.R index 4e200bb28ec42c6378c4ab75ab7cfb59868a66ca..89b4e25fdb440b20683f45006a01a4a60a28c987 100644 --- a/R/UtilsErrorCrit.R +++ b/R/UtilsErrorCrit.R @@ -9,11 +9,7 @@ stop("'InputsCrit' must be of class 'InputsCrit'", call. = FALSE) } if (inherits(InputsCrit, "Multi") | inherits(InputsCrit, "Compo")) { - if (Crit == "RMSE") { - stop("'InputsCrit' must be of class 'Single'. Use the 'ErrorCrit' function on objects of class 'Multi' with RMSE", call. = FALSE) - } else { - stop(paste0("'InputsCrit' must be of class 'Single'. Use the 'ErrorCrit' function on objects of class 'Multi' or 'Compo' with ", Crit), call. = FALSE) - } + stop(paste0("'InputsCrit' must be of class 'Single'. Use the 'ErrorCrit' function on objects of class 'Multi' or 'Compo' with ", Crit), call. = FALSE) }