% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scores.R
\name{brier_score}
\alias{brier_score}
\title{Brier score for binary and categorical forecasts}
\usage{
brier_score(p, y)
}
\arguments{
\item{p}{Numeric vector in \verb{[0, 1]} for binary forecasts, or a numeric
matrix whose rows are probability vectors for categorical forecasts.}

\item{y}{For binary vector input, numeric vector in \verb{\{0, 1\}}. For
categorical matrix input, integer vector in \verb{\{1, ..., K\}}, where
\code{K = ncol(p)}.}
}
\value{
Numeric vector of scores in \verb{[-1, 0]}. Higher is better.
}
\description{
Computes the positively oriented Brier/quadratic score. Vector probability
input is treated as binary; matrix probability input is treated as
categorical.
}
\details{
For binary forecasts, this computes
\deqn{S(p, y) = -(p-y)^2.}

For categorical forecasts, this computes
\deqn{S(\mathbf{p}, y) = -\frac{1}{2}\|\mathbf{p} - e_y\|_2^2,}
where \code{e_y} is the one-hot vector of the realised category.

With the convention that category 2 corresponds to the binary event
\code{y = 1}, the categorical formula recovers the binary formula exactly
when \code{K = 2}.
}
\section{Bounds}{

Score differences lie in \verb{[-1, 1]}, so use \code{c = 1} for Theorem 1 and
\code{c = 2} for Theorems 2 and 3.
}

\examples{
p <- c(0.2, 0.7, 0.9)
y <- c(0, 1, 1)
brier_score(p, y)

}
