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!