1

I would like to calculate the held-out likelihood value or log-likelihood value of a fitted model against a hold out dataset. Below is a simplified example:

     tr = data.frame(y=rnorm(100, 10, 1), x=1)
     tst = data.frame(y=rnorm(50, 9, 1), x=1) 
     lmx <- lm(y ~ x, data=tr)
     logLik(lmx) # it gives the log likelihood value of training data
#> 'log Lik.' -140.2452 (df=2)
     logLik(lmx, newdata=tst) # **It does not work!!!**
#> 'log Lik.' -140.2452 (df=2)

Created on 2020-10-18 by the reprex package (v0.3.0)

I can write out the loglikelihood function and evaluate dataset y against it. But I am hoping that it can be done a simpler way in some R packages.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Xiaojie Zhou
  • 164
  • 2
  • 6

0 Answers0