[SciPy-User] How do I use vonmises.fit()?
Tue Mar 30 15:51:07 CDT 2010
On Tue, Mar 30, 2010 at 4:34 PM, <firstname.lastname@example.org> wrote:
> On Tue, Mar 30, 2010 at 3:10 PM, David Ho <email@example.com> wrote:
>> Hi all!
>> I want to fit some data with a Von Mises distribution, and get the mean and
>> "kappa" parameters for that distribution.
>> I'm a little confused about scipy.stats.distributions.vonmises.fit().
>> Just as a test, I tried this:
>>>>> vm_rvs = scipy.stats.vonmises.rvs(1.2, 2.3, size=10000) # the first
>>>>> argument appears to be "kappa", and the second argument is the mean.
>> array([ 1.17643696e-01, 3.38956854e-03, 1.27331662e-27])
>> I got an array of 3 values, none of which seem to be equal to the mean or
>> kappa of the distribution.
>> I looked around in some of the docstrings, but I couldn't find any clear
>> documentation of what these values are supposed to correspond to.
>> I would've expected vonmises.fit() to return something like:
>> array([ 1.2, 2.3])
>> What am I doing wrong?
>> Thanks for your help,
> When I did I check of the fit method for all distributions, then
> vonmises most of the time didn't produce any useful results,
> especially estimated scale of almost zero.
> The problem is that vonmises doesn't have a well defined pdf on the real line
>>>> import matplotlib.pyplot as plt
>>>> plt.plot(scipy.stats.vonmises.pdf(np.linspace(-10,10),1.2, loc=2.3))
> Since vonmises is intended for circular data, and I don't know much
> about circular statistics (except for what Anne explained on the
> mailing list), I never tried to get it to work like the other
> It might be possible to patch vonmises to work on the real line but I
> never tried.
Here is a way that seems to work
* set bounds a,b
* use mean of random variable as starting value to start inside the
support of the distribution
>>> vm_rvs = scipy.stats.vonmises.rvs(1.2, 2.3, size=10000)
>>> stats.vonmises.a = -np.pi
>>> stats.vonmises.b = np.pi
array([ 1.19767227, 2.30077064, 0.99916372])
>> --David Ho
>> PS: I also don't fully understand the "scale" and "loc" parameters for all
>> of the continuous random variables.
>> Does "loc" always correspond to the mean, and "scale" always correspond to
>> the square root of the variance, or something else?
> loc=0, scale=1 is the standard distribution, the loc and scale
> parameters transform the distribution of the transformation x~ =
> If the standard distribution has mean or variance different from 0, 1
> then the transformed distribution has mean and variance different from
> loc, scale.
> the stats method shows the implied variance scale:
>>>> scipy.stats.vonmises.stats(1.2, loc=2.3, scale=2)
> (array(2.2999999999999998), array(5.4900668161122423))
>>>> scipy.stats.vonmises.stats(1.2, loc=0, scale=1)
> (array(1.5832118030775403e-017), array(1.3725167040280606))
>> SciPy-User mailing list
More information about the SciPy-User