# How to choose a way to obtain maximum likelihood estimation

Given an example random variables $X_1, X_2,\ldots, X_n$, and assume that we have a distribution function to describe the data (Bernoulli):

$f(x_i;p) = p^{x_i}(1-p)^{(1-x_{I})}$

Here $p$ is the unknown parameter, with which we want to find maximum likelihood estimator (MLE).

In my understanding there are two ways to obtain that MLE:

1. Is by using calculus, do it on paper like this way. This lead us to obtain $\hat{p} = \frac{\sum_{i=1}^n X_i}{n}$. With which then we can just plug-in the $X_1, X_2,\ldots, X_n$ value and get the actual value for $\hat{p}$.

2. Numerical (iterative) search procedure like using bbmle::mle2 package in R.

My question, given a problem how can we decide which method to use to find MLE. With calculus or numerically search procedure?

The best way to distinguish these cases is simply to try to optimise algebraically, and see if this leads you to an explicit solution, or a case that requires numerical methods. If it is possible to get an explicit closed-form solution for the maximising value then you are finished, and no numerical methods are required. If you require numerical methods to find the solution to the critical point equation, then you can either form this iterative process algebraically, or rely on a package such as bbmle in R. At the end of the day, optimisation requires familiarity with calculus; with experience you will be able to anticipate which problems give closed-form solutions and which will require iterative methods.