I would like to write R code to build the dirichlet mixture model. The loglikelihood I used for the beta distribution is as below:
(,)=(−1)ln¯+(−1)ln(1−)¯+lnΓ(+)−lnΓ()−lnΓ()
and I need help for initialising parameters (alpha, beta and setting extra parameters for the gamma distribution used in the code).
###E step: compute the likelihood of each cell over each component
log_like <- function(theta, X) {
N = nrow(X)
alpha <- theta[1]
beta <- theta[2]
log_lik <- N*log(pgamma(alpha + beta) - N*log(pgamma(alpha) - N*log(pgamma(beta)) + (alpha -1)*N*log(X) + (beta - 1) *N* log(1-X)
return(-log_lik)
}
###M-step:
MLE_estimates <- optim(fn = log_like,
par = c(1,1),
lower = c(-Inf, -Inf),
upper = c(Inf, Inf),
hessian = TRUE,
method = "L-BFGS-B",
# custom Inputs
x = vaf_trim$vaf
)
And here's the data set I want to fit. (randomly generated from the negative binomial distribution.
0.25 2 0.23 3 0.22 4 0.21 5 0.21 6 0.21 7 0.21 8 0.21 9 0.20 10 0.20 11 0.20 12 0.20 13 0.19 14 0.19 15 0.19 16 0.19
I think I figured out. This might work. Feel free to comment if you find any errors.