1
votes

I've applied logistic regression using glm in R as follows:

 model <- glm(y ~ x, family=binomial(link='logit'), data=training_data)

Now I want to compute the log-likelihood of observing my test data given model, so I can see if it's doing better than other models.

logLik computes the log-likelihood of observing the training data given the model -- this is precisely the parameter that was maximised during model fitting. But how do I get the log likelihood of observing the test data given the model?

1

1 Answers

0
votes
prob=predict(model, newdata=..., type="response")

If you do: ?predict.glm you will be able to see how to specify the type argument for the appropriate values.

And, thanks to Ben Bolker's comment - to complete the answer: sum(log(prob*resp + (1-prob)*(1-resp))).