# I have a problem in log likelihood which I wrote for custom distribution

I have a custom distribution and data as follows

 i={42, 180, 35, 392, 63, 230, 112, 281, 42, 28, 42, 120, 148, 16, 310, 28, 68, 336, 21.5, 50, 19, 30, 12, 120, 140, 170, 17, 115, 31, 21,  52, 164, 225, 225, 151, 60, 200, 46, 210, 14};
MO = ProbabilityDistribution[{"CDF",  1 - ((\[Alpha]*E^-x)/(1 - (1 - \[Alpha])*E^-x))}, {x,  0, \[Infinity]}, Assumptions -> {\[Alpha] > 0}]


i used maximum likelihood as follow

mlmo = FindDistributionParameters[i, MO, ParameterEstimator -> "MaximumLikelihood"]


and the output was as follows

{\[Alpha] -> 4.57761*10^7}


When I used loglikelihood as follow the results was as follows

LogLikelihood[MO, {42, 180, 35, 392, 63, 230, 112, 281, 42, 28, 42, 120, 148, 16, 310, 28, 68, 336, 21.5, 50, 19, 30, 12, 120, 140, 170, 17, 115, 31, 21, 52, 164, 225, 225, 151, 60, 200, 46, 210,  14}] /.  {\[Alpha] -> 4.57761*10^7}


The output was -3885.87. I used this code and wrote log likelihood manual to get parameter

bbb = Total[logpdf = (Log[PDF[MOE, i]])]
Dbal = D[bbb, \[Alpha]]
b = FindRoot[Dbal, {\[Alpha], 1}]


This the output

This is the loglikelihood

LogLikelihood[MOE, {42, 180, 35, 392, 63, 230, 112, 281, 42, 28, 42, 120, 148, 16,310, 28, 68, 336, 21.5, 50, 19, 30, 12, 120, 140, 170, 17, 115,  31, 21, 52, 164, 225, 225, 151, 60, 200, 46, 210, 14}] /. {\[Alpha] -> 2.2402116078266955*^21}


The output is better: -3283.72 Now, what does the output mean?

• Is MOE the same as MO? I assume it is. Your i contains one inexact number, namely 21.5. Please replace it by the exact number 215/10. I assume you do that. I think the warnings appear because you evaluate E^x for large x such as Max[i]==392, which generates huge (!) numbers. It seems that you can avoid the warning using something like Block[{\$MaxExtraPrecision=1000}, FindRoot[Dbal,{\[Alpha],1}, WorkingPrecision->1000, MaxIterations->1000]]//N. But, more generally, please check if you are on the right track, I do not know the background of this calculation. Commented Aug 20, 2022 at 14:31
• Thanks, more I wanted it really Commented Aug 20, 2022 at 19:08

Edit: Added why the candidate distribution almost certainly didn't generate the observed data.

While there are numeric stability issues with estimating $$\alpha$$ given your data and candidate distribution, the main issue is that candidate distribution will not fit your data.

Consider the difference between the 99.5% and 0.5% quantiles (i.e., the width of the middle 99% of the data:

MO = ProbabilityDistribution[{"CDF", 1 - ((α*E^-x)/(1 - (1 - α)*E^-x))},
{x, 0, ∞}, Assumptions -> {α > 0}];
width = Quantile[MO, 995/1000] - Quantile[MO, 5/1000]
(* -Log[(199 + α)/199] + Log[1 + 199 α] *)
(* 10.5866 *)


The limit of the width of the middle 99% of the data as $$\alpha -> \infty$$ is

Limit[width, α -> ∞] // N
(* 10.5866 *)


The range of your data is

Max[i] - Min[i]
(* 380 *)


380 is much, much larger than 10.5866 and it is extremely unlikely that the candidate distribution could possibly the source of the data.

Essentially your distribution is missing a scaling parameter. $$x$$ needs to be divided by a constant.

i = {42, 180, 35, 392, 63, 230, 112, 281, 42, 28, 42, 120, 148, 16,
310, 28, 68, 336, 21.5, 50, 19, 30, 12, 120, 140, 170, 17, 115, 31,
21, 52, 164, 225, 225, 151, 60, 200, 46, 210, 14};
MO = ProbabilityDistribution[{"CDF", 1 - ((α*E^-(x/β))/(1 - (1 - α)*E^-(x/β)))},
{x, 0, ∞}, Assumptions -> {α > 0, β > 0}]
mle = FindDistributionParameters[i, MO, ParameterEstimator -> "MaximumLikelihood"]
(* {α -> 1.3236, β -> 99.906} *)

Show[Histogram[i, {50}, "PDF"],
Plot[PDF[MO /. mle, x], {x, 0, 400}]]
`

You might want to question whoever gave you that candidate distribution.