2

I built a glm model and used it to predict probabilities for the test data.

model = glm(y ~ x, data=dt, family=binomial(link='logit'))
pred = predict(model, newdata=test.dt, type='response')

How do I find the test log-likelihood for the predicted probabilities?

user572780
  • 257
  • 3
  • 10
  • Could you please share a reproducible piece of your data on which you want to apply the model and extract the log-likelihood. – Anoushiravan R Mar 30 '21 at 17:01

1 Answers1

2

Something like

dbinom(dt$y, prob=pred, size=1, log=TRUE)

should give you the log-likelihood (assuming that these are binary/Bernoulli responses). You could also calculate the log-likelihood directly as dt$y*log(pred) + (1-dt$y)*log(1-pred) (I think)

If you want the combined log-likelihood just sum() the above value ... or logLik(model)

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453