Difference between binary and count data of same data on logistic regression in R I confuse that the difference of Residuals deviance between binary and count data of the same data, by logistic regression in R. I'd like to know the way to calculate the both Residual deviance. Please give me some advice.
binary data
x<-c(2,2,2,2,2,3,3,3,3,3,5,5,5,5,5,6,6,6,6,6)
yesno<-c(1,1,0,0,0,1,0,0,0,0,1,1,1,0,0,1,1,1,1,0)
modelb<- glm(yesno~x,family=binomial)
(resultb<-summary(modelb))
#            Estimate Std. Error z value Pr(>|z|)
#(Intercept)  -2.0608     1.3486  -1.528    0.126
#x             0.5152     0.3147   1.637    0.102
#    Null deviance: 27.726  on 19  degrees of freedom
#Residual deviance: 24.744  on 18  degrees of freedom
#AIC: 28.744

deviance(modelb)
#[1] 24.74444
-2*logLik(modelb)
#'log Lik.' 24.74444 (df=2)

count data
x<-c(2,3,5,6)
yes<-c(2,1,3,4)
no<-c(3,4,2,1)
modelc<- glm(cbind(yes,no)~x,family=binomial)
(resultc<-summary(modelc))
#            Estimate Std. Error z value Pr(>|z|)
#(Intercept)  -2.0608     1.3486  -1.528    0.126
#x             0.5152     0.3147   1.637    0.102
#    Null deviance: 4.2576  on 3  degrees of freedom
#Residual deviance: 1.2762  on 2  degrees of freedom
#AIC: 13.096

deviance(modelc)
#[1] 1.276154
-2*logLik(modelc)
#'log Lik.' 9.096343 (df=2)

 A: I tried the case of proportion(=yes/yes+no), using above best answer. Yes, I got it.
But, I couldn’t understand the case without “weight=n”. A little bit more for complete understanding.
#-----with “weight=n”
modelcp<- glm(yp~x,family=binomial,weight=n)
(result<-summary(modelcp))
#            Estimate Std. Error z value Pr(>|z|)
#(Intercept)  -2.0608     1.3486  -1.528    0.126
#x             0.5152     0.3147   1.637    0.102
#    Null deviance: 4.2576  on 3  degrees of freedom
#Residual deviance: 1.2762  on 2  degrees of freedom

beta <- c(-2.0608, 0.5152)
logistic <- function(x) 1 / (1 + exp(-x)) # Common helper function
Lambda.0 <- function(beta, x, success, failure,y, with.binomial=TRUE) {
  p <- logistic(beta[1] + beta[2] * x)
  cnst <- ifelse(isTRUE(with.binomial), sum((lchoose((success + failure), success))), 0)
  cnst + sum(n*(y * log(p) + (1-y) * log(1-p)))
}
-2 * Lambda.0(beta, x, yes, no, yp) # 9.096343: includes log binomial coefficients
-2 * Lambda.0(beta, x, yes, no, yp,with.binomial=FALSE) # 24.74444
sum(lchoose(n, yp*n)) * -2 # -15.64809 = 24.74444 - 9.096343


#-----without “weight=n”
modelcpout<- glm(yp~x,family=binomial)
(result<-summary(modelcpout))
#            Estimate Std. Error z value Pr(>|z|)
#(Intercept)  -2.0608     3.0155  -0.683    0.494
#x             0.5152     0.7038   0.732    0.464
#    Null deviance: 0.85152  on 3  degrees of freedom
#Residual deviance: 0.25523  on 2  degrees of freedom

deviance(modelcpout)
#[1] 0.2552307
-2*logLik(modelcpout)
#'log Lik.' 3.094208 (df=2)

