0

The likelihood that I get using R glm or Countr, (renewalCount) is different from when I calculate the likelihood by hand, using R estimated parameters. I am trying to fit a dataset with some functions in R, but the likelihood values are not consistent with what I get from other languages. Another weird thing is that I get the same result with glm(...,family=poisson) for different datasets!

D = matrix(c(1:9))
Numb = matrix(c(10, 4, 5, 3, 1, 2, 1, 1, 1))
Number = data.frame(Numb)
agg_poiss <- glm(formula = D ~ 1, family = poisson, data = Number)
agg_wei <- renewalCount(formula = D ~ 1, data = Number, dist = "weibull", 
computeHessian = FALSE, control = renewal.control(trace = 0))

For Poisson case, I get: (Intercept) 1.6094, which means a Poisson parameter of exp(1.6094) but t gives me the likelihood -21.53659 in R, which becomes different when I calculate by hand.

sam
  • 77
  • 6
  • 2
    `glm(formula = D ~ 1, family = poisson, data = Number)` is strange: that does not use the dataframe `Number`. Why do you do `data = Number` ? And how do you get the log-likelihood in R and by hand ? – Stéphane Laurent May 04 '19 at 17:27
  • 3
    By hand: `sum(dpois(D, exp(1.6094), log = TRUE))`. With the `logLik` function: `logLik(agg_poiss)`. Both give `-21.53659`. – Stéphane Laurent May 04 '19 at 17:33
  • 2
    Likelihoods are often calculated "up to a constant", and different methods may well use (ignore) different constants. Thus ratios of likelihoods and differences in log likelihoods will be consistent between methods, but actual likelihood values will not be consistent. (Though, in this case, as Stephane points out, it looks like the math is your problem, not the constants.) – Gregor Thomas May 04 '19 at 18:49
  • Thanks for replying @StéphaneLaurent . So, 'D' is just the counts and 'Numb' is the response variable (Numb(i) shows the number of times D(i) happened). Where should I use 'Numb' or 'Number' to get the fitted Poisson distribution to this coun data? Apparently, I am using it wrongly now. – sam May 14 '19 at 20:33
  • I just found it. Basically, I got confused by the Countr package guide and messed up glm too. My data structure is wrong. It should contain just the number of events at each data point. – sam May 14 '19 at 20:41

0 Answers0