[R-gregmisc-users] SF.net SVN: r-gregmisc:[2020] pkg/gtools/R/dirichlet.R
Brought to you by:
warnes
|
From: <wa...@us...> - 2015-05-23 22:12:59
|
Revision: 2020
http://sourceforge.net/p/r-gregmisc/code/2020
Author: warnes
Date: 2015-05-23 22:12:57 +0000 (Sat, 23 May 2015)
Log Message:
-----------
ddirichlet() was incorrectly returning NA when x[i]=0 and
alpha[i]=1. In this case, the one calculation became (-Inf * 0),
which R evaluates to NaN. The correction is to detect this case and
substitute -Inf instead of NaN.
Modified Paths:
--------------
pkg/gtools/R/dirichlet.R
Modified: pkg/gtools/R/dirichlet.R
===================================================================
--- pkg/gtools/R/dirichlet.R 2015-05-08 22:49:28 UTC (rev 2019)
+++ pkg/gtools/R/dirichlet.R 2015-05-23 22:12:57 UTC (rev 2020)
@@ -29,9 +29,9 @@
dirichlet1 <- function(x, alpha)
{
logD <- sum(lgamma(alpha)) - lgamma(sum(alpha))
- s<-sum((alpha-1)*log(x))
+ s <-(alpha-1)*log(x)
+ s <- ifelse(alpha==1 & x==0, -Inf, s)
exp(sum(s)-logD)
-
}
# make sure x is a matrix
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|