4
$\begingroup$

I'm looking for a "hack" in R that would allow me to calculate the log-likelihood of a GLM fit on a separate test set easily regardless of the distribution. For instance for a Gamma GLM, this is how we could extract the training likelihood:

 x_train <- rnorm(1000, mean=100)
 y_train <- rnorm(1000, mean=100)
 mdl <- glm(y_train ~ x_train, family=Gamma(link="log"))
 loglik_train <- logLik(mdl) 

If I have test data available, what is a quick way to calculate the log-likelihood of observing these new datapoints given the parameterized model estimated from the training set?

I wish to avoid doing the full calculation (making predictions, calculating for each prediction the likelihood and then summing) since I will have different distribution GLMs & link functions et cetera...

Thanks a lot for any suggestions!

$\endgroup$

0

Your Answer

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