I am doing an EM estimation, in the M step of which I need Max Likelihood Estimation, which has 24 parameters. I tried the nlm/optim/maxLik functions in R. They are all very slow. Any suggestions are welcome. Thanks. This is the LogL function: (choices, M, S, K, N and Alpha are known.)
logl <- function(theta,choices,M,S,K,N,Alpha){
betas <- theta[(1:(S*(K+1)))]
betas<-matrix(betas,S,K+1,byrow=TRUE)
loglik <-for (n in 1:N){
pr1s=foreach (s=1:S) %dopar%{
pr11=foreach (i = 1:K) %dopar%{
exp(sum(betas[s,]*choices[[n]][i,]))/exp(sum(M[[i]]%*%betas[s,]))}
pr11=as.numeric(pr11)
prod(pr11)
}
pr1sn=as.numeric(pr1s)
l[n]= sum(Alpha*pr1sn)
}
L=-sum(log((l)))
return(L)}
What I want to get is :
ops=nlm(logl,theta.start,choices=choices,M=M,S=2,K=11,N=3,Alpha=Alpha,hessian=TRUE)