File: ddirichlet.R

package info (click to toggle)
r-cran-mixtools 2.0.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,944 kB
  • sloc: ansic: 781; makefile: 6
file content (11 lines) | stat: -rwxr-xr-x 345 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
ddirichlet <- function (x, alpha) 
{
    if (length(x) != length(alpha))
	stop("Mismatch between dimensions of x and alpha in ddirichlet().\n")
        logD <- sum(lgamma(alpha)) - lgamma(sum(alpha))
        s <- sum((alpha - 1) * log(x))
        pd <- exp(sum(s) - logD)
	  pd[any(x < 0 | x > 1)] <- 0
	  if(sum(x) != 1) pd <- 0
	  return(pd)
}