I am trying to maximize a Poisson likelihood function for an array of values, of the form
llhij = -mij + kij*ln(mij/kij).
(where I use the numerical approximation ln(k!) ~ k*ln(k)).
For my purposes, the mij are the number of events predicted by a model, and the kij are the number of events observed. For the total log-likelihood, I sum the likelihoods of all elements of the array.
In some cases, the m = k = 0, and the log likelihood becomes (-Inf - -Inf) = NaN.
Is it an acceptable solution to deal with this by replacing the NaN values with zero? The way that I have implemented this solution in my (Matlab) code (following an example from a similar analysis) is
if(any(isnan(llh(:))))
llh(isnan(llh)) = 0;
end
...
m = sum(sum(llh, 1),2);
If I do not reset the NaN values of the likelihood, the entire llh is returned as NaN and the maximization fails.
By setting the NaN elements of the likelihood array to zero, this procedure effectively causes the elements that would be NaN to be ignored in the analysis, but I am having difficulty justifying this procedure, and am concerned that it introduces or ignores errors later in the analysis (the point is to calculate a set of confidence intervals in addition to the MLE, and the intervals are quite large where they should be essentially zero).
Is this a conceptually acceptable way to deal with these NaN elements, and if not, is there a more formal solution?