In response to this question I have added som R code to show how to manually apply the formula for calculation of deviance residuals
The model in the code is a logit model where
$$p_i := Pr(Y_i = 1) = \frac{\exp(b_0 + b_1x_i)}{1+\exp(b_0 + b_1x_i)}.$$
I define $v_i := b_0 + b_1x_i$ such that the model can be written as
$$p_i := Pr(Y_i = 1) = \frac{\exp(v_i)}{1+\exp(v_i)}.$$
Estimating the model I get estimates $\hat b_0$ and $\hat b_1$. Using these estimates the predicted latent values
$$\hat v_i := \hat b_0 + \hat b_1 x_i,$$
are calculated and then the predicted probabilities are calculated
$$\hat p_i =\frac{\exp(\hat v_i )}{1+\exp(\hat v_i )}.$$
Using these predicted probabilities the formula for the deviance residuals are applied in the coding step
sign(y-pred_p) * ifelse(y==1,sqrt(-2*log(pred_p)),sqrt(-2*log(1-pred_p)))
which is simply an application of the formula
$d_i =
\begin{cases}
\sqrt{-2\ln(\hat p_i)} &\text{if } Y_i=1\\
-\sqrt{-2\ln(1-\hat p_i)} &\text{if } Y_i=0\\
\end{cases}$
# Simulate some data
N <- 1000
b0 <- 0.5
b1 <- 1
x <- rnorm(N)
v <- b0 + b1*x
p <- exp(v)/(1+exp(v))
y <- as.numeric(runif(N)<p)
# Estimate model
model <- glm(y~x,family=binomial)
summary_model <- summary(model)
summary_dev_res <- summary_model$deviance.resid
# This is the output you get:
quantile(summary_dev_res)
# Calculate manually deviance residuals
# First calculate predicted v's
pred_v <- coef(model)[1] + coef(model)[2]*x
# The calculate predicted probabilities
pred_p <- exp(pred_v)/(1+exp(pred_v))
# Apply formula for deviance residuals
dev_res <- sign(y-pred_p) * ifelse(y==1,sqrt(-2*log(pred_p)),sqrt(-2*log(1-pred_p)))
# Check that it is the same as deviance residuals returned from summary
plot(summary_dev_res,dev_res)
points(seq(-3,3,length.out=100),seq(-3,3,length.out=100),type="l",col="red",lwd=2)
# all points should be on the red line
# Also compare the quantiles ...
quantile(summary_dev_res)
quantile(dev_res)