I recently came across NaN behavior when applying TMBs built in dmultinom density function. This was caused because of a zero in one of the probabilities p container. This is expected because of the log(p) call in the source code see here.
In R's dmultinom function they exclude density evaluations where p = 0. Would this be good to add? The alternative is to add a zerofun like function that would add an increment to p to prevent the case p = 0.
For anyone interested I wrote a function called dmultinom_upd which excludes density evaluations when p = 0. See the zipped file for cpp and R script that tests it against TMBs built in dmultinom method.
I recently came across NaN behavior when applying TMBs built in
dmultinom
density function. This was caused because of a zero in one of the probabilitiesp
container. This is expected because of thelog(p)
call in the source code see here.In R's
dmultinom
function they exclude density evaluations wherep = 0
. Would this be good to add? The alternative is to add a zerofun like function that would add an increment top
to prevent the casep = 0
.For anyone interested I wrote a function called
dmultinom_upd
which excludes density evaluations whenp = 0
. See the zipped file for cpp and R script that tests it against TMBs built indmultinom
method.TMB Version:
‘1.9.1’
R Version:
R version 4.2.1
Operating System:
Windows 10
testmultinomial.zip