\name{BrierScore}
\alias{BrierScore}
\alias{.BrierScore}
\title{
Compute Brier Score And Its Decomposition And Brier Skill Score
}
\description{
Computes the Brier score (BS) and the components of its standard decomposition as well with the two within-bin components described in Stephenson et al., (2008). It also returns the bias-corrected decomposition of the BS (Ferro and Fricker, 2012). BSS having the climatology as the reference forecast.\cr
\cr
.BrierScore provides the same functionality, but taking a matrix of ensemble members (exp) as input.
}
\usage{
BrierScore(obs, pred, thresholds = seq(0, 1, 0.1))

.BrierScore(exp, obs, thresholds = seq(0, 1, 0.1))
}
\arguments{
  \item{obs}{
Vector of binary observations (1 or 0)
  }
  \item{pred}{
Vector of probablistic predictions with values in the range [0,1]
  }
  \item{thresholds}{
Values used to bin the forecasts.  By default the bins are {[0,0.1), [0.1, 0.2), ... [0.9, 1]}
  }
  \item{exp}{
Matrix of predictions with values in the range [0,1] for the .BrierScore function
  }
}
\value{
Both BrierScore and .Brier score provide the same outputs:
  \itemize{
    \item{$rel}{standard reliability}
    \item{$res}{standard resolution}
    \item{$unc}{standard uncertainty}
    \item{$bs}{Brier score}
    \item{$bs_check_res}{rel-res+unc}
    \item{$bss_res}{res-rel/unc}
    \item{$gres}{generalized resolution}
    \item{$bs_check_gres}{rel-gres+unc}
    \item{$bss_gres}{gres-rel/unc}
    \item{$rel_bias_corrected}{bias-corrected rel}
    \item{$gres_bias_corrected}{bias-corrected gres}
    \item{$unc_bias_corrected}{bias-corrected unc}
    \item{$bss_bias_corrected}{gres_bias_corrected-rel_bias_corrected/unc_bias_corrected}
    \item{$nk}{number of forecast in each bin}
    \item{$fkbar}{average probability of each bin}
    \item{$okbar}{relative frequency that the observed event occurred}
    \item{$bins}{bins used}
    \item{$pred}{values with which the forecasts are verified}
    \item{$obs}{probability forecasts of the event}
  }
}
\examples{
# Minimalist examples with BrierScore
# See ?UltimateBrier to see how to apply BrierScore to multidimensional arrays
a <- runif(10)
b <- round(a)
x <- BrierScore(b, a)
x$bs - x$bs_check_res
x$bs - x$bs_check_gres
x$rel_bias_corrected - x$gres_bias_corrected + x$unc_bias_corrected
  \dontrun{
a <- runif(10)
b <- cbind(round(a),round(a)) # matrix containing 2 identical ensemble members...
x2 <- BrierScore(a, b)
  }

# Example of .BrierScore with veriApply
  \dontrun{
example(Load)
clim <- Clim(sampleData$mod, sampleData$obs)
ano_exp <- Ano(sampleData$mod, clim$clim_exp)
ano_obs <- Ano(sampleData$obs, clim$clim_obs)
runmean_months <- 12
dim_to_smooth <- 4
# Smooth along lead-times   
smooth_ano_exp <- Smoothing(ano_exp, runmean_months, dim_to_smooth)
smooth_ano_obs <- Smoothing(ano_obs, runmean_months, dim_to_smooth)
dim_to_mean <- 2  # Mean along members 
corr <- Corr(Mean1Dim(smooth_ano_exp, dim_to_mean),
             Mean1Dim(smooth_ano_obs, dim_to_mean),
             compROW = required_complete_row,
             limits = c(ceiling((runmean_months + 1) / 2),
             leadtimes_per_startdate - floor(runmean_months / 2)))


library(easyVerification)
BrierScore2 <- s2dverification:::.BrierScore
veriApply("BrierScore2", a, b, )
  }
}
\references{
Wilks (2006) Statistical Methods in the Atmospheric Sciences.\cr
Stephenson et al. (2008). Two extra components in the Brier score decomposition. Weather and Forecasting, 23: 752-757.\cr
Ferro and Fricker (2012). A bias-corrected decomposition of the BS. Quarterly Journal of the Royal Meteorological Society, DOI: 10.1002/qj.1924.\cr
}
\author{
History:\cr
0.1  -  2012-04  (L. Rodrigues, \email{lrodrigues at ic3.cat})  -  Original code\cr
0.2  -  2017-02  (A. Hunter, \email{alasdair.hunter at bsc.es})  -  Adapted to veriApply()
}
\keyword{datagen}
