A probability distribution is given by $$f_X(x) = \frac{e^\frac{-x}{\lambda}x}{\lambda}$$ if $x > 0$ and $f_X(x) = 0$ otherwise. $\lambda$ is an unknown positive number. Knowingly that for a sample of dimension 40, $\sum_{i = 1}^{40} = 142.89$, what is the maximum likelihood estimation of $\lambda$?
I did
$$L(\lambda | \underline{x}) = \prod_{I=1}^{n}(\frac{e^\frac{-x}{\lambda}x}{\lambda}) = \frac{1}{\lambda^{2n}}e^{\frac{-1}{\lambda}\sum_{i=1}^nx_i}\prod_{I=1}^{n}(x_i)$$ $$\ln(L(\lambda | \underline{x})) = -2n\ln(\lambda) - \frac{1}{\lambda}\sum_{i=1}^{n}x_i + \sum_{i=1}^n\ln(x_i)$$ Now differentiate such that first derivative is zero (to have a stationary point) and such that the second derivative is less than zero (to make sure it is a maximum). And I end up with:
$$\hat{\lambda}: \frac{-2n}{\lambda} + \frac{1}{\lambda^2}\sum_{i=1}^nx_i = 0, \frac{2n}{\lambda^2}-\frac{1}{\lambda^3}\sum_{i=1}^n < 0$$
Solving for $\hat{\lambda}$ I get $$\hat{\lambda} = \frac{\sum_{i=1}^nx_i}{-2n}$$ which is negative because de sum is positive and $n$ is positive. But $\lambda > 0$ as it said in the question. What am I doing wrong?
From the distribution of gamma distribution,
$$f(x) = \frac1{\Gamma(k)\theta^k}x^{k-1}e^{-\frac{x}{\theta}}$$
Now, let $\theta$ be $\lambda$ and $k$ be $2$, we know that
$$f(x) = \frac1{\Gamma(2)\lambda^2}xe^{-\frac{x}\lambda}=\frac{xe^{-\frac{x}\lambda}}{\lambda^2}$$ is a valid distribution.
From your working, it shows that you are aware that power of $2$ should be there in the denominator.
Now, from $$-\frac{2n}{\lambda}+\frac1{\lambda^2}\sum_{i=1}^n x_i = 0$$
We have $$\frac1{\lambda^2}\sum_{i=1}^n x_i = \frac{2n}{\lambda}$$
Multiply by $\frac{\lambda^2}{2n}$,
$$\lambda = \frac1{2n}\sum_{i=1}^n x_i > 0$$
Note that the second derivative is
$$\frac{2n}{\lambda^2}-\frac2{\lambda^3}\sum_{i=1}^n x_i=\frac2{\lambda^2}\left(n-\frac{\sum_{i=1}^n x_i}{\lambda} \right)<0$$