[SciPy-User] MLE with stats.lognorm

Christian K. ckkart@hoc....
Sun Oct 9 10:46:44 CDT 2011


Am 09.10.11 14:14, schrieb josef.pktd@gmail.com:
> On Sun, Oct 9, 2011 at 8:06 AM,  <josef.pktd@gmail.com> wrote:
>> On Sun, Oct 9, 2011 at 7:51 AM, Christian K. <ckkart@hoc.net> wrote:
>>> Hi,
>>>
>>> I wonder whether I am doing something wrong or if the following is to be
>>> expected (using sciyp 0.9):
>>>
>>> In [38]: from scipy import stats
>>>
>>> In [39]: dist = stats.lognorm(0.25,scale=200.0)
>>>
>>> In [40]: samples = dist.rvs(size=100)
>>>
>>> In [41]: print stats.lognorm.fit(samples)
>>> C:\Python26\lib\site-packages\scipy\optimize\optimize.py:280: RuntimeWarning:
>>> invalid value encountered in subtract
>>>  and max(abs(fsim[0]-fsim[1:])) <= ftol):
>>> (1.0, 158.90310231282845, 21.013288720647015)
>>>
>>> In [42]: print stats.lognorm.fit(samples, floc=0)
>>> [2.2059200167655884, 0, 21.013288720647015]
>>>
>>> Even when fixing loc=0.0, the results from the MLE for s and scale are very
>>> different from the input parameters. Is lognorm
>>>
>>> Any hints are highly appreciated.
>>
>> I just looked at similar cases, for the changes in scipy 0.9 and
>> starting values, see
>> http://projects.scipy.org/scipy/ticket/1530
>>
>> Essentially, you need to find better starting values and give it to fit.
>>
>> Can you add it to the ticket? It's not quite the same, but I guess it
>> is also that fix_loc_scale doesn't make sense.

Ok. I'll do it.

>> Note, I also get many of these warnings,
>>
>>> invalid value encountered in subtract
>>>  and max(abs(fsim[0]-fsim[1:])) <= ftol):
>>
>> they are caused when np.inf is returned for invalid arguments. In many
>> cases optimize.fmin evaluates parameters that are not valid, but most
>> of the time that doesn't seem to cause any problems, exept it's
>> annoying.
> 
> for example with starting value for loc
>>>> print stats.lognorm.fit(x, loc=0)
> (0.23800805074491538, 0.034900026034516723, 196.31113801786194)

I see. Is there any workaround/patch to force loc=0.0? What is the
meaning of loc anyway?
I have some more observations: in case the fmin warning is shown, the
result equals the initial guess:

In [17]: stats.lognorm.fit(samples)
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/optimize/optimize.py:280:
RuntimeWarning: invalid value encountered in subtract
  and max(abs(fsim[0]-fsim[1:])) <= ftol):
Out[17]: (1.0, 172.83866358041575, 24.677880663838486)

In [18]: stats.lognorm._fitstart(samples)
Out[18]: (1.0, 172.83866358041575, 24.677880663838486)

Christian




More information about the SciPy-User mailing list