Binomial deviance (source code)

= Binomial deviance

For independent binomial counts $Y_i\sim\operatorname{Bin}(m_i,p_i)$ with observed proportions $y_i=Y_i/m_i$ and fitted probabilities $\widehat p_i$, the deviance from the saturated model is
$$
D=2\sum_i m_i\left[y_i\log\frac{y_i}{\widehat p_i}+(1-y_i)\log\frac{1-y_i}{1-\widehat p_i}\right],
$$
with the usual convention $0\log0=0$.