likelihood value calculation with glm I have 2 questions regarding the likelihood value calculation with glm. It seems that sometimes it calculates the likelihood value including the binomial coefficient and sometimes it does not. Tow cases are described below:

*

*Why does glm calculate the log-likelihood value differently for the following two cases at the bottom in respect to the binomial coefficient? The first case is taken from here. Is that just an inconsistency or is there a reason behind?


*For logistic regression with binomial family it seems that glm does not compute the likelihood value. is that because it tries to calculate the binomial coefficient which it cont? Because as far as I understand the log-likelihood value can still be computed, as the binomial coefficient disappears when taking the derivative.
Case 1)
Y <- matrix(c(1,2,4,3,2,0),3,2)
X <- c(0,1,2)

fit.glm <- glm(Y ~ X,family=binomial (link=logit))
summary(fit.glm)
logLik(fit.glm)  
## Both are equal but with the binomial coefficient:
LogLik <- Y[,1]%*%log(fitted(fit.glm))+Y[,2]%*%log(1fitted(fit.glm))+sum(log(factorial(Y[,1]+Y[,2])/(factorial(Y[,2])*factorial(Y[,1]))))


> logLik(fit.glm)
'log Lik.' -2.336075 (df=2)

Case 2)
Y2<-c(1,0,1,1,1,1,1,0,1,0,0,0,0,0,0,0)
X2<-c(0,1,2,1,2,0,0,0,1,2,2,2,2,1,2,1)                             
fit.glm2 <- glm(Y2~X2, family=binomial (link=logit))
summary(fit.glm2)

logLik(fit.glm2)
## Both are equal but without the binomial coefficient:
LogLik2<-Y2%*%log(fitted(fit.glm2))+(1-Y2)%*%log(1-fitted(fit.glm2))

> logLik(fit.glm2)
'log Lik.' -9.8958 (df=2)

 A: You are comparing two different regression models: logistic regression and binomial regression.
In logistic regression the outcome is a binary random variable (each data point corresponds to one trial, whose outcome is either a success or a failure) and the likelihood function is:
$$
\begin{aligned}
\prod_{i=1}^np_i^{y_i}\left(1-p_i\right)^{1-y_i}
\end{aligned}
$$
In binomial regression the outcome is a binomial random variable (each data point corresponds to a pre-determined number of trials under settings $x$) and the likelihood function is:
$$
\begin{aligned}
\prod_{i=1}^n\binom{n_i}{x_i}p_i^{y_i}\left(1-p_i\right)^{n_i-y_i}
\end{aligned}
$$
where $p_i=\operatorname{logit}^{-1}\left(x_i\beta\right)$. The mathematical expressions correspond exactly to your R formulas.
If we group the observations according to the predictors $x$, then the logistic and binomial regressions are equivalent: we get the same inference for the parameters $\beta$, the same fitted values and residuals, etc. However, as you point out, the likelihood functions are equivalent up to a (known) proportionality constant which is a function of the data.
x <- c(0, 1, 2, 1, 2, 0, 0, 0, 1, 2, 2, 2, 2, 1, 2, 1)
y <- c(1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0)

m1 <- glm(cbind(y, 1 - y) ~ x, family = binomial)
broom::tidy(m1)
#> # A tibble: 2 × 5
#>   term        estimate std.error statistic p.value
#>   <chr>          <dbl>     <dbl>     <dbl>   <dbl>
#> 1 (Intercept)    0.860     0.958     0.897   0.370
#> 2 x             -0.956     0.690    -1.39    0.165
logLik(m1)
#> 'log Lik.' -9.8958 (df=2)

# Group the observations according to the predictors.
X <- unique(x)
Y <- table(x, y)[, c(2, 1)] # successes in 1st column, failures in 2nd column

m2 <- glm(Y ~ X, family = binomial)
broom::tidy(m2)
#> # A tibble: 2 × 5
#>   term        estimate std.error statistic p.value
#>   <chr>          <dbl>     <dbl>     <dbl>   <dbl>
#> 1 (Intercept)    0.860     0.958     0.897   0.370
#> 2 X             -0.956     0.690    -1.39    0.165
logLik(m2)
#> 'log Lik.' -3.162398 (df=2)

