How can I fit t distribution using scipy.stats.t.fit()
with predetermined mean and std?
The question is, I have a standardized dataset, with mean=0
and std=1
, I only want to get df
of t distribution.
But when I do scipy.stats.t.fit(data)
, it outputs df, loc, scale
, and loc&sclae not necessarily equal to 0&1.
How can I solve this? Thanks!
In the call to .fit()
, use the arguments floc=0
and fscale=1
to fix these parameters.
Here's an example. First, import t
and generate a sample to work with:
In [24]: from scipy.stats import t
In [25]: np.random.seed(123)
In [26]: sample = t.rvs(3, loc=0, scale=1, size=10000)
Now use the .fit()
method to fit the t
distribution to the sample, constraining the location to 0 and the scale to 1:
In [27]: t.fit(sample, floc=0, fscale=1)
Out[27]: (3.1099609375000048, 0, 1)
There are more examples (using different distributions) in the fit
docstring and here on stackoverflow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With