thesis

Useful R code for the Dirichlet distribution

Simulation To simulated a Dirichlet sample quickly we use the method on the Wikipedia page for the Dirichlet distribution. rdirichlet <- function(N=1,K=c(1,1)) { # Simulations from the Dirichlet Distribution, according to the method of Wikipedia lk <- length(K) sim <- matrix(0,N,lk) gams <- matrix(0,N,lk) for (i in 1:lk) { gams[,i] <- matrix(rgamma(N,K[i]),N,1) } gamtotal <- matrix(rowSums(gams),N,lk) sim <- gams/gamtotal return(sim) } Frequentist Parameter estimation The simplest method of parameter estimation is the method of moments: