[R] NaN Log-lik value in EM algorithm (fitting Gamma mixture model)
Duncan Murdoch
murdoch.duncan at gmail.com
Thu Sep 15 02:04:05 CEST 2016
On 14/09/2016 4:46 PM, Aanchal Sharma wrote:
> Hi,
>
> I am trying to fit Gamma mixture model to my data (residual values obtained
> after fitting Generalized linear Model) using gammamixEM. It is part of the
> script which does it for multiple datasets in loop. The code is running
> fine for some datasets but it terminates for some giving following error:
>
> " iteration = 1 log-lik diff = NaN log-lik = NaN
> Error in while (diff > epsilon && iter < maxit) { :
> missing value where TRUE/FALSE needed"
>
> Seems like EM is not able to calculate log-lik value (NaN) at the first
> iteration itself. any idea why that can happen?
> It works fine for the other genes in the loop. Tried looking for difference
> in the inputs, but could not come up with anything striking.
>
THere are lots of ways to get NaN in numerical calculations. A common
one if you are using log() to calculate log likelihoods is that rounding
error gives you a negative likelihood, and then log(lik) comes out to NaN.
You just need to look really closely at each step of your calculations.
Avoid using log(); use the functions that build it in (e.g. instead of
log(dnorm(x)), use dnorm(x, log = TRUE)).
Duncan Murdoch
More information about the R-help
mailing list