What is the equation to calculate the log likelihood of a null model in logistic regression? I would like to calculate the log likelihood of the null model for a logistic regression manually. Ultimately, this is to calculate McFadden's pseudo-R2, and, yes, I could have software generate the log likelihood of the null model (that is my current workaround) but am looking to expand my understanding through manual calculation. I have looked online, but I am not confident that I have found the proper equation to do so.
What is the proper equation for this?
I tried the following equation from this lecture: $$ \ln L(\hat p) = n\bar y\ln(\hat p) + (n-n\bar y)\ln(1 - \hat p) $$
Where $ \hat p  = \bar y = \frac{\sum y_i}{n}$
However, this gives me huge log likelihood values. For example, with a sample size of 4000 and 50% of the labels in each category ($ p = 0.50 $), this gives a log likelihood of -5545.18. When using this to calculate McFadden's pseudo-R2 with a model log-likelihood, it's resulting in clearly erroneous R2 values > 0.99. When I run a model with only the intercept (array of 1s) to calculate the null model log likelihood in python's sklearn, I find pseudo-R2 values in the range of 0.01 - 0.09 (so no, it's not as simple as missing a $ 1 - ... $ for the R2 calculation, which was my initial guess). Could someone clarify what is wrong with this equation above or the proper way to calculate log likelihood for the null intercept model by hand?
 A: I don't know python, but testing your equation with wikipedia's example worked. using the student pass/fail table at the beginning of the article, I got the same log-odds as the maximized null that the article got, namely -13.8629, by the following scheme code:
(let* ([Y '(0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1)])
       [len  (length Y)] ;; len  is 20
       [ybar (mean Y)])  ;; ybar is .5
  (+ (* len ybar (log ybar))
     (* (- len (* len ybar))
        (log ybar))))

Did you perhaps accidentally, when calculating the deviance, multiply also the alternative hypothesis model's likelihood by the number of points?
$$
D = 2\left(\sum_i\frac{1}{1+e^{(X\beta)_i}} - n[\bar y \log(\bar y)+(1-\bar y)\log(1-\bar y)]\right)
$$
where X is the design matrix including the adjoined column vector of 1's and β is the parameter column vector.
A: $$L(y,\hat p)\\=\dfrac{1}{n}
\sum_{i=1}^n
\bigg[
y_i\log(\hat p_i)+
(1-y_i)\log(1-\hat p_i)
\bigg]
$$
In your case, the (null) model predicts $\bar y$ every time, so $\hat p_i=\bar y$ for every $i$.
To calculate your McFadden $R^2$, take that result as the denominator, and then the numerator is that equation with the $\hat p_i$ predicted by the model of interest.
$$
R^2_{McFadden} = 1 - \dfrac{
\dfrac{1}{n}
\sum_{i=1}^n
\bigg[
y_i\log(\hat p_i)+
(1-y_i)\log(1-\hat p_i)
\bigg]
}{
\dfrac{1}{n}
\sum_{i=1}^n
\bigg[
y_i\log(\bar y)+
(1-y_i)\log(1-\bar y)
\bigg]\\
= 1 - \dfrac{
\sum_{i=1}^n
\bigg[
y_i\log(\hat p_i)+
(1-y_i)\log(1-\hat p_i)
\bigg]
}{
\sum_{i=1}^n
\bigg[
y_i\log(\bar y)+
(1-y_i)\log(1-\bar y)
\bigg]
}
}
$$
