In performing Iteratively Reweighted Least Squares (IRLS) to derive $\hat{\beta}$ estimates for logistic regression, all the resource I've read online say to use weights inversely proportional to the variance of each $Y_i$. For example, see step 4, below (taken from here):
However, in R code implementations of IRLS I've found online, the weights are set as the variance, not the inverse of the variance (e.g. here or here).
For example, see the below image. It sets s = mu * (1 - mu)
, which is the variance given that $Y$ in logistic regression has a Bernoulli distribution. So when the weights matrix, S
, is calculated, shouldn't it be S = diag(1/s)
instead of S = diag(s)
? What am I missing here?
Having this clarified would be very helpful. I know that for weighted least squares, $w_i = \dfrac{1}{\sigma_i^2}$ is standard, so why does the weight matrix in IRLS implementations not invert the variance?