# How to do maximum likelihood estimation when numerical derivatives cannot be calculated

I am trying to estimate a model from Camerer, Ho and Chong 2002 p151.

$$i$$ is individual, $$t$$ is time

$$j\in m$$ which is action set

$$s, a$$ are two types of individuals

$$s_i(t)$$ is chosen action by subject $$i$$ in period $$t$$.

$$P$$ is probability.

$$A^j_i(a,t)=\frac{\phi N(t-1)A^j_i(t-1)}{N(t)} +\frac{[\delta+(1-\delta)I(s^j_i,s_i(t))]\pi(s^j_i,s_{-i}(t))}{N(t)}$$ $$N(t)=(1-\kappa)\phi N(t-1)+1, \quad t\geq 1$$ $$P^j_i(a,t+1)=\frac{exp(\lambda A^j_i(a,t))}{\sum^{m_i}_{k=1}exp(\lambda A^k_i(a,t))}$$ $$A^j_i(s,t)=\sum^{m_{-i}}_{k=1}[\alpha'P^k_{-i}(s,t+1)+(1-\alpha')P^k_{-i}(a,t+1)]\pi_i(s_i^j,s^k_{-i})$$ $$P^j_i(s,t+1)=\frac{exp(\lambda A^j_i(s,t))}{\sum^{m_i}_{k=1}exp(\lambda A^k_i(s,t))}$$ $$L_i=\alpha[\prod^T_{t=1}P^{s_i(t)}_i(s,t)]+(1-\alpha)[\prod^T_{t=1}P^{s_i(t)}_i(a,t)]$$ $$Log L=\sum_i^n log L_i$$ Parameters needed to be estimated are $$\phi$$, $$\delta$$, $$\kappa$$, $$\lambda$$, $$\alpha$$, $$\alpha'$$.

My question is how to estimate this model using maximum likelihood model in Stata. I got error ''could not calculate numerical derivatives''. I think this is because $$A^j_i(s,t)$$ and $$P^j_i(s,t+1)$$ are dependent, but I don't know how to solve this problem.

I could also try R or Python or Matlab.

• If you can find an helpful latent variable representation, the EM algorithm can handle it. For instance, the sum of two terms can be broken by a binary latent variable. (The double-meaning notation $Pĵ_i(\cdot,t)$ is quite poor, one should use $P$ and $Q$ for instance.) Sep 5 at 5:31
• if Stat has MCMC, that may counterintuitively be the simplest way to get this model off the group from a software perspective. Sep 5 at 12:47
• As long as the log-likelihood is differentiable you can use reverse mode automatic differentiation to calculate the derivatives for you without any extra effort on your part. See ADMB or its successor TMB which integrates better with R. Sep 5 at 16:12

There are optimisation algorithms that don't require derivatives. You can divide them into

• algorithms that assume derivatives exist but don't require them
• algorithms that don't assume smoothness

A good example of the first is Powell's quadratic approximation algorithms newuoa and bobyqa (available in the R minqa package and used by the lme4 package). In relatively low-dimensional problems these are often faster than using a gradient-based algorithm with numeric derivatives.

Algorithms that don't assume smoothness include the famous Nelder-Mead simplex algorithm and simulated annealing algorithms.

In your case I think the objective function should actually be smooth, but it's a bit hard to tell since so many things aren't defined.

M. J. D. Powell (2007) "Developments of NEWUOA for unconstrained minimization without derivatives", Cambridge University, Department of Applied Mathematics and Theoretical Physics, Numerical Analysis Group, Report NA2007/05, http://www.damtp.cam.ac.uk/user/na/NA_papers/NA2007_05.pdf.

M. J. D. Powell (2009), "The BOBYQA algorithm for bound constrained optimization without derivatives", Report No. DAMTP 2009/NA06, Centre for Mathematical Sciences, University of Cambridge, UK. http://www.damtp.cam.ac.uk/user/na/NA_papers/NA2009_06.pdf.

• Thanks for the suggestion! I ended up using python because somehow I cannot use minqa in R (everytime I use newuoa it terminates the session.) One follow-up question: because $A^j_i(s,t)$ and $P_i^j(s, t+1)$ are dependent on each other, I got error that $P_i^j(s, t+1)$ is not defined when it is used in $A^j_i(s,t)$. I read from a paper that 'finding a fixed point is necessary as a part of fitting the model'. So I wonder how to proceed from here. Sep 12 at 17:46