1

EDIT: see here

I am new to Mathematica and I am trying to work though deriving the maximum likelihood estimator for the Poisson distribution as an exercise to familiarize myself with how Mathematica works. I am a bit stuck in that I can't seem to symbolically differentiate the log likelihood function. This is what I have done:

loglfn = Log[Product[(\[Lambda]^(Subscript[x, j]))/(Exp[\[Lambda]]*
      Factorial[Subscript[x, j]]), {j, 1, n}]]

$$\log \left(\prod _{j=1}^n \frac{e^{-\lambda } \lambda ^{x_j}}{x_j!}\right)$$

I then want to differentiate this function with respect to $\lambda$, but I can't seem to figure out how to do it. Following this answer, I've tried:

Simplify[D[loglfn, \[Lambda]], j \[Element] Integers && 1 <= j <= n]

as well as just D[loglfn, \[Lambda]] but in both cases the output I get is:

$$\frac{\partial \left(\prod _{j=1}^n \frac{e^{-\lambda } \lambda ^{x_j}}{x_j!}\right)}{\partial \lambda }$$

while I am looking for

$$ -n + (1/\lambda)\sum_{j=1}^n {x_j} $$

Any help is much appreciated!

Ben S.
  • 111
  • 2
  • It's possible to get this result by manually using the rule that a log of a product is a sum of logs, and then simplifying the interior of the derivative of that sum directly, but I would be interested in seeing a more automatic way with Mathematica. – eyorble Nov 30 '22 at 23:01
  • Right that's my question. I thought Mathematica would "just do it" haha. – Ben S. Nov 30 '22 at 23:03
  • 3
    You could try the following answer – Carl Woll Nov 30 '22 at 23:07
  • @CarlWoll aha that seems like the very same question, thank you. – Ben S. Nov 30 '22 at 23:09

0 Answers0