1
$\begingroup$

I still keep checking from my previous question here. The next, I tried the case of proportion(=yes/yes+no), using previous best answer. Yes, I got it. But, I couldn’t understand the case without “weight=n”. When estimating as the proportion without “weight=n”, I can’t understand how to estimate deviance(or log-likelihood). please give me some advice.

x   <- c(2, 3, 5, 6)
yes <- c(2, 1, 3, 4)
no  <- c(3, 4, 2, 1)
n   <- yes + no
yp  <- yes / n

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

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

#-----Using modified method of best answer on my previous question-----#
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*n/(success + failure)))),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)  

my previous question : Difference between binary and count data of same data on logistic regression in R

$\endgroup$
4
  • $\begingroup$ Isn't this answered here? stats.stackexchange.com/questions/141412/… $\endgroup$ Commented Jan 28, 2020 at 17:10
  • $\begingroup$ Thank you for your information. I think it's related. But, I can't understand how to calculate "3.0942"... It means, where does "logLik(modelcout)=-1.547104" come from? humm... I confuse. $\endgroup$
    – 51sep
    Commented Jan 29, 2020 at 16:34
  • $\begingroup$ I uploaded my answer of this question, but I don't have confidence about it yet. If someone makes it, please give me some advice, thank you. stats.stackexchange.com/questions/446966/… $\endgroup$
    – 51sep
    Commented Feb 1, 2020 at 16:54
  • $\begingroup$ @51sep Does this answer your question: stats.stackexchange.com/questions/259502 ? if it is not, can you explain why. If it is, can you confirm. $\endgroup$ Commented Dec 5, 2020 at 10:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.