Skip to content
Prev 312708 / 398506 Next

problem with convergence in mle2/optim function

Dear Berend,

Thank you so much for your help!  I was able to write the gradient 
function for my NLL function.  For you're and others' possible interest, 
here is my final gradient function:

Following from my description of the problem below, gr.p1, gr.p2, 
gr.mu1, and gr.mu2 are the (very large) gradient equations of NLL2, 
below, with respect to the parameters p1, p2, mu1, and mu2, 
respectively.  The gradient function is:

# Gradient function of NLL1
grr <- function(par, y){
  p1 <- par[1]
  p2 <- par[2]
  mu1 <- par[3]
  mu2 <- par[4]
  t <- y[,1]
  n1 <- y[,2]
  n2 <- y[,3]
  n3 <- y[,4]
  gr.p1 <- ....
  gr.p2 <- ....
  gr.mu1 <- ....
  gr.mu2 <- ....
  gr.mat <- matrix(c(gr.p1, gr.p2, gr.mu1, gr.mu2), ncol = 4)
  -colSums(gr.mat)
}

I verified this gradient function with numerical approximation with the 
grad() function [numDeriv package].

Thanks again.
Adam Zeilinger
On 10/10/2012 3:57 AM, Berend Hasselman wrote: