maximum-likelihood of a sequence of events described by a Bernoulli distribution

I am having quite some troubles with the following homework:

In a city it's measured for the whole year whether it rained or not. A distribution $\textrm{Bernoulli}(r_t|\rho)$ characterizes the observations $\{r_t\}_{t=1}^{365}$ where $r_t = 1$ if it rained that day and $r_t = 0$ if it did not rain.

My goal is finding the value of $\rho$ as a maximum likelihood.

One first step is to find the likelihood of the entire set of observations, which I believe is:

$p(r_1,r_2,\ldots,r_t|\rho) = \prod_{t=1}^{365}\rho^{r_t}(1 - \rho)^{1-r_t}$

Considering $n_1$ as the number of rainy days, and $n_0$ the number of not raining days the likelihood is simplified:

$p(r_1,r_2,\ldots,r_t|\rho) =\rho^{n_1}(1 - \rho)^{n_0}$

Hence, the log-likelihood calculated as follows:

$\mathrm{log}p(r_1,r_2,\ldots,r_t|\rho) = n_1\mathrm{log}(\rho) + n_0\mathrm{log}(1-\rho)$

Its derivative seems to be:

$\frac{\mathrm{d}}{\mathrm{d}\rho}\mathrm{log}p(r_1,r_2,\ldots,r_t|\rho) = \frac{n_1}{\rho} + \frac{n_0}{1- \rho}$

Setting the derivative to 0:

$\rho = \frac{n_1}{n_1 - n_0}$

Plugging in the yearly measurements $n_1 = 217$, $n_0 = 148$:

$\rho = \frac{217}{217-148} = 3.145$

Unfortunately this value is not allowed for $\rho$, which should be in the interval $[0,1]$.

What's wrong? I did the calculations several times with the same result.

$$\frac{d \log(p)}{d \rho} = \frac{n_1}{\rho} - \frac{n_0}{1-\rho} \Rightarrow \rho = \frac{n_1}{n_0+n_1}$$
• hmm, why do you have a minus between $n_1/\rho$ and $n_0/(1-\rho)$ ? Sep 17 '14 at 11:30
• I don't know why someone downvoted this answer since it correctly points out that the OP mistakenly wrote the derivative of $\log(1-\rho)$ as $\frac{1}{1-\rho}$ instead of as $-\frac{1}{1-\rho}$ as told to us by the chain rule of differentiation. Sep 17 '14 at 14:05
• francesco the minus is there because $\frac{d}{d\rho} \log(1-\rho)=\frac{1}{1-\rho}\cdot -1$ by the chain rule of differentiation. Sep 17 '14 at 15:21
{"ft_lang_label":"__label__en","ft_lang_prob":0.8392352,"math_prob":0.9998072,"size":1320,"snap":"2022-05-2022-21","text_gpt3_token_len":453,"char_repetition_ratio":0.11854103,"word_repetition_ratio":0.0,"special_character_ratio":0.36666667,"punctuation_ratio":0.11985019,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9999672,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-01-16T20:17:56Z\",\"WARC-Record-ID\":\"<urn:uuid:7e090559-07e4-4369-a4bf-967176530dc7>\",\"Content-Length\":\"140240\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3175957c-834b-4769-84c5-ebb5b28f38ce>\",\"WARC-Concurrent-To\":\"<urn:uuid:3b97784b-4d27-441a-bab4-0d66945bde32>\",\"WARC-IP-Address\":\"151.101.1.69\",\"WARC-Target-URI\":\"https://stats.stackexchange.com/questions/115753/maximum-likelihood-of-a-sequence-of-events-described-by-a-bernoulli-distribution\",\"WARC-Payload-Digest\":\"sha1:3Z337YWOHQDW6BESLAK6SYCT7AOG3526\",\"WARC-Block-Digest\":\"sha1:CJYLCXOMO5N4WEAILELGMKK64YIBRXGC\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-05/CC-MAIN-2022-05_segments_1642320300010.26_warc_CC-MAIN-20220116180715-20220116210715-00112.warc.gz\"}"}