# Check if log-likelihood function is correctly derived

This question is a continuation of this one. By guesswork, I found out that $$\vec{\theta}=(5.2,5.3,1.0)=$$ $$(A,B,C)$$ was a good guess that made my model

$$y_i=A\sin\left(\frac{x_i}{B}\right)+C\epsilon_i,\tag1$$

fit the $$(x_i,y_i)$$ points pretty well. This should mean that if I compute the log-likelihood function $$\ell(\vec{\theta})$$ at the particular values of $$\vec{\theta}$$ that I guessed, I should come close to the maximum value. In my other question I obtained the likelihood function

$$L(A,B,C | x_i,y_i)= \prod_{i=1}^n \phi\left(\frac{y_i - A \sin(x_i/B)}{C}\right).\tag2$$

Since the standard normal density is $$\phi(x)=\frac{1}{\sqrt{2\pi}}e^{-x^2/2}$$ I have

\begin{align} L(A,B,C | x_i,y_i) &= \frac{1}{(\sqrt{2\pi})^{23}}\prod_{i=1}^{23}\exp{\left(-\frac{1}{2}\left(\frac{y_i-A\sin\left(\frac{x_i}{B}\right)}{C}\right)^2\right)}\tag3\\ &=\frac{1}{(\sqrt{2\pi})^{23}}\exp\left(-\frac{1}{2C^2}\sum_{i=1}^{23}\left(y_i-A\sin\left(\frac{x_i}{B}\right)\right)^2\right)\tag4 \end{align}

Taking the logarithm yields the log-likelihood function $$\ell$$ to be \begin{align} \ell(A,B,C|x_i,y_i)&=\ln\left(\frac{1}{(\sqrt{2\pi})^{23}}\right)+\ln\left(\exp\left(-\frac{1}{2C^2}\sum_{i=1}^{23}\left(y_i-A\sin\left(\frac{x_i}{B}\right)\right)^2\right)\right)\tag5\\ &= \ln\left(\frac{1}{(\sqrt{2\pi})^{23}}\right)-\frac{1}{2C^{2}}\sum_{i=1}^{23}\left(y_i-A\sin\left(\frac{x_i}{B}\right)\right)^2.\tag6 \end{align}

I used R to compute $$\ell(\hat{\theta})$$ at $$\hat{\theta}=(5.2,5.3,1.0)$$ and found that the result was $$\approx-43.42094$$, however, computing the same function at $$\hat{\theta}=(12,12,8)$$ gave me $$\approx -35.60867.$$

This should not be since i should get very close to the maximum using the guessed values. This leads me to believe that I've calculated my log-likelihood function incorrectly, or my code is incorrect, or I've just misunderstood the entire assignment.

Can anyone help me finding out which it is?

• @Xi'an - Are you sure? In which step? I don't see why it should be $1/c^23$ – Parseval Dec 6 '18 at 10:50
• @Xi'an - I've checked it for 3 hours since I saw your comment. I honestly don't see why $C$ should be raised tot the 23:d power anywhere :S I must be blind to something. – Parseval Dec 6 '18 at 15:39

If$$y_i=A\sin\left(\frac{x_i}{B}\right)+C\epsilon_i,\tag1$$then the density of $$y_i$$ is$$\frac{1}{C}\varphi\left(\left\{y_i-A\sin\left(\frac{x_i}{B}\right)\right\}/C\right)$$