I have data consisting of service times which I want to model with the gamma distribution. I want to use the method of moments to estimate the parameters of the gamma distribution.
I get the following theoretical moments: $$ \begin{split} \mathbb{E}[X] &= \frac{r}{\lambda}\\ \mathbb{E}\left[X^2\right] &= \mathbb{Var}[X] + \mathbb{E}[X]^2 = \frac{r}{\lambda^2} + \frac{r^2}{\lambda^2} = \frac{r(r+1)}{\lambda^2} \end{split} $$ Thus I get that $$ \begin{split} r &= \lambda \mathbb{E}[X] \\ \lambda^2 &= \frac{r(r+1)}{\mathbb{E}\left[X^2\right]} \end{split} $$
But when I try to compute the estimators for $\lambda$ and $r$, I get wrong results. What have I done wrong in my derivation of the formula for $\lambda$ above?