\name{RatioRMS}
\alias{RatioRMS}
\alias{.RatioRMS}
\title{
Computes the Ratio Between The RMSE of Two Experiments
}
\description{
Calculates the ratio of the RMSE for two forecasts of the same observations.\cr
The ratio RMSE(ens, obs) / RMSE(ens.ref, obs) is output.\cr
The p-value is provided by a two-sided Fischer test.

.RatioRMS provides the same functionality but taking two matrices of ensemble members (ens and ens.ref) as input.
}
\usage{
RatioRMS(var_exp1, var_exp2, var_obs, posRMS = 1, pval = TRUE)

.RatioRMS(exp, exp.ref, obs, pval = TRUE)
}
\arguments{
  \item{var_exp1}{
Array of experimental data 1.
  }
  \item{var_exp2}{
Array of experimental data 2.
  }
  \item{var_obs}{
Array of observations.
  }
   \item{posRMS}{
Dimension along which the RMSE are to be computed = the position of the start dates.
  }
  \item{pval}{
Whether to compute the p-value of Ho : RMSE1/RMSE2 = 1 or not. TRUE by default.
  }
   \item{exp}{
Matrix of experimental data 1.
  }
  \item{exp.ref}{
Matrix of experimental data 2.
  }
  \item{obs}{
Vector of observations.
  }
}
\value{
RatioRMS: A list containing the following components :\cr
ratiorms - the ratio of the rms of the two ensembles \cr
p.val - the p value \cr
The dimension corresponds to the ratio between the RMSE (RMSE1/RMSE2) and the p.value of the two-sided Fisher test with Ho: RMSE1/RMSE2 = 1.\cr
.RatioRMS:
\item{$ratiorms}{
The ratio of the root mean square errors, 
  }
  \item{$conf.int}{
Corresponding to the p values of the ratio of the rmse statistics (only present if \code{pval = TRUE}).
  } 

}
\examples{
# See examples on Load() to understand the first lines in this example
  \dontrun{
data_path <- system.file('sample_data', package = 's2dverification')
expA <- list(name = 'experiment', path = file.path(data_path,
             'model/$EXP_NAME$/$STORE_FREQ$_mean/$VAR_NAME$_3hourly',
             '$VAR_NAME$_$START_DATE$.nc'))
obsX <- list(name = 'observation', path = file.path(data_path,
             '$OBS_NAME$/$STORE_FREQ$_mean/$VAR_NAME$',
             '$VAR_NAME$_$YEAR$$MONTH$.nc'))

# Now we are ready to use Load().
startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101')
sampleData <- Load('tos', list(expA), list(obsX), startDates,
                   output = 'lonlat', latmin = 27, latmax = 48, 
                   lonmin = -12, lonmax = 40)
  }
  \dontshow{
startDates <- c('19851101', '19901101', '19951101', '20001101', '20051101')
sampleData <- s2dverification:::.LoadSampleData('tos', c('experiment'),
                                                c('observation'), startDates,
                                                output = 'lonlat',
                                                latmin = 27, latmax = 48,
                                                lonmin = -12, lonmax = 40)
  }
leadtimes_dimension <- 4
initial_month <- 11
mean_start_month <- 12
mean_stop_month <- 2                                
sampleData$mod <- Season(sampleData$mod, leadtimes_dimension, initial_month, 
                         mean_start_month, mean_stop_month)
sampleData$obs <- Season(sampleData$obs, leadtimes_dimension, initial_month, 
                         mean_start_month, mean_stop_month)                              
clim <- Clim(sampleData$mod, sampleData$obs)
ano_exp <- Ano(sampleData$mod, clim$clim_exp)
ano_obs <- Ano(sampleData$obs, clim$clim_obs)
rrms <- RatioRMS(Mean1Dim(ano_exp[ , 1:2, , , , ], 1)[, 1, , ], 
                 ano_exp[ , 3, , , , ][, 1, , ],
                 Mean1Dim(ano_obs, 2)[1, , 1, , ], 1)
PlotEquiMap(rrms[1, , ], sampleData$lon, sampleData$lat, 
            toptitle = 'Ratio RMSE')
  \dontrun{
  library(easyVerification)  
  dim(ano_obs) <- dim(ano_obs)[-2] # see ?veriApply for how to use the 'parallel' option
  rrms2 <- veriApply(".RatioRMS", ano_exp[, 1:2, , , ,], ano_exp[, 2:3, , , ,], ano_obs, tdim = 3, ensdim = 2)
  }
}
\author{
History:\cr
0.1  -  2011-11  (V. Guemas, \email{vguemas at ic3.cat})  -  Original code\cr
1.0  -  2013-09  (N. Manubens, \email{nicolau.manubens at ic3.cat})  -  Formatting to R CRAN\cr
2.0  -  2017-02  (A. Hunter, \email{alasdair.hunter at bsc.es})  -  Adapted to veriApply()
}
\keyword{datagen}
