I'm working on this problem:
A random sample of $n$ items is selected from the large number of items produced by a certain production line in one day. Find the MLE for the ratio $r$, the proportion of defective items divided by the proportion of non-defective items.
I believe I can make sense of this as follows. Let $N$ be the "large number of items produced." Assuming $N>>n$, we may model the number of defective items in the random sample as a binomial variable with parameters $n$ and $p$. The number of non-defective items in the sample will be a binomial variable with parameters $n$ and $q=1-p$.
We want the MLE for $r=\frac{p}{1-p}$. By the "invariance principle" for MLEs, this should be
$$\hat{r}_{MLE}=\frac{x/n}{1-x/n}=\frac{x}{n-x}$$
where $x$ is the number of defective items we observe in the sample. Is this right? I'm bothered by the fact that the problem does not specify the name of the number of defective items observed, so I must give an answer using my own notation. In other words, I must introduce the letter $x$.
I also get stuck trying to derive this result directly, without the invariance principle. The probability of observing $x$ defective items is
$$P(x;p)={n\choose x}p^x(1-p)^{n-x}={n\choose x}r^xp^n$$
But I don't see how to write this probability solely as a function of $r$, so I don't see how to show directly that this probability is maximized when $r=\frac{x}{n-x}$.
New Idea: if $r=\frac{p}{1-p}$, then $r-rp=p$, so $p(1+r)=r$, so $p=\frac{r}{1+r}$. Therefore the probability as a function of $r$ is
$$P(x;r)={n\choose x}r^x\left(\frac{r}{1+r}\right)^n$$
Differentiating with respect to $r$ gives
$${n\choose x}xr^{x-1}\left(\frac{r}{1+r}\right)^n+{n\choose x}r^xn\left(\frac{r}{1+r}\right)^{n-1}\frac{1}{(1+r)^2}=0$$
This implies
$$x\frac{r}{1+r}+rn\frac{1}{(1+r)^2}=0$$
So
$$xr(1+r)+rn=0 \implies xr^2+xr+rn=0 \implies xr+x+n=0$$
So
$$r=\frac{-n-x}{x}$$
This is close but obviously not the same as what I get when I use the invariance principle. What have I done wrong?
Your first solution is correct. For your second solution, note that \begin{align*} P(X=x|r) &= {n \choose x}p^{x}(1-p)^{n-x} \\ &= {n \choose x}\left(\frac{r}{1+r}\right)^{x}\left(\frac{1}{1+r}\right)^{n-x} \\ &= {n \choose x}r^{x}(1+r)^{-n} \end{align*} Which doesn't quite agree with your solution. In order to maximize $P(X=x|r)$, it is often easier to maximize $\log(P(X=x|r))$ instead. The solution is the same because $\log$ is strictly increasing. Note that \begin{align*} l(r) := \log(P(X=x|r)) &= \log{n \choose x} + x \log r -n \log(1+r) \end{align*} Therefore, \begin{align*} \frac{\partial l(r)}{\partial r} &= xr^{-1} -n(1+r)^{-1} \\ \frac{\partial^2 l(r)}{\partial r^2} &= -xr^{-2}-n(1+r)^{-2} \end{align*} Since $\frac{\partial^2 l(r)}{\partial r^2} \leq 0$, $l(r)$ is concave and is maximized at $\frac{\partial l(r)}{\partial r} = 0$. Obtain \begin{align*} \frac{\partial l(r)}{\partial r} &= 0 \\ xr^{-1}-n(1+r)^{-1} &= 0 \\ nr &= x(1+r) \\ (n-x)r &= x \\ r &= \frac{x}{n-x} \end{align*} Therefore, $\hat{r}_{MLE}=\frac{X}{n-X}$, which is precisely the estimator you obtained previously.