# statsmodels.sandbox.distributions.transformed.TransfTwo_gen.fit¶

TransfTwo_gen.fit(data, *args, **kwds)

Return MLEs for shape (if applicable), location, and scale parameters from data.

MLE stands for Maximum Likelihood Estimate. Starting estimates for the fit are given by input arguments; for any arguments not provided with starting estimates, self._fitstart(data) is called to generate such.

One can hold some parameters fixed to specific values by passing in keyword arguments f0, f1, …, fn (for shape parameters) and floc and fscale (for location and scale parameters, respectively).

Parameters
dataarray_like

Data to use in calculating the MLEs.

argsfloats, optional

Starting value(s) for any shape-characterizing arguments (those not provided will be determined by a call to _fitstart(data)). No default value.

kwdsfloats, optional

Starting values for the location and scale parameters; no default. Special keyword arguments are recognized as holding certain parameters fixed:

• f0…fn : hold respective shape parameters fixed. Alternatively, shape parameters to fix can be specified by name. For example, if self.shapes == "a, b", faand fix_a are equivalent to f0, and fb and fix_b are equivalent to f1.

• floc : hold location parameter fixed to specified value.

• fscale : hold scale parameter fixed to specified value.

• optimizer : The optimizer to use. The optimizer must take func, and starting position as the first two arguments, plus args (for extra arguments to pass to the function to be optimized) and disp=0 to suppress output as keyword arguments.

Returns
mle_tupletuple of floats

MLEs for any shape parameters (if applicable), followed by those for location and scale. For most random variables, shape statistics will be returned, but there are exceptions (e.g. norm).

Notes

This fit is computed by maximizing a log-likelihood function, with penalty applied for samples outside of range of the distribution. The returned answer is not guaranteed to be the globally optimal MLE, it may only be locally optimal, or the optimization may fail altogether. If the data contain any of np.nan, np.inf, or -np.inf, the fit routine will throw a RuntimeError.

Examples

Generate some data to fit: draw random variates from the beta distribution

>>> from scipy.stats import beta
>>> a, b = 1., 2.
>>> x = beta.rvs(a, b, size=1000)


Now we can fit all four parameters (a, b, loc and scale):

>>> a1, b1, loc1, scale1 = beta.fit(x)


We can also use some prior knowledge about the dataset: let’s keep loc and scale fixed:

>>> a1, b1, loc1, scale1 = beta.fit(x, floc=0, fscale=1)
>>> loc1, scale1
(0, 1)


We can also keep shape parameters fixed by using f-keywords. To keep the zero-th shape parameter a equal 1, use f0=1 or, equivalently, fa=1:

>>> a1, b1, loc1, scale1 = beta.fit(x, fa=1, floc=0, fscale=1)
>>> a1
1


Not all distributions return estimates for the shape parameters. norm for example just returns estimates for location and scale:

>>> from scipy.stats import norm
>>> x = norm.rvs(a, b, size=1000, random_state=123)
>>> loc1, scale1 = norm.fit(x)
>>> loc1, scale1
(0.92087172783841631, 2.0015750750324668)
{"ft_lang_label":"__label__en","ft_lang_prob":0.54181427,"math_prob":0.9684169,"size":3132,"snap":"2020-10-2020-16","text_gpt3_token_len":815,"char_repetition_ratio":0.12851663,"word_repetition_ratio":0.014861995,"special_character_ratio":0.25798213,"punctuation_ratio":0.19344263,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9660928,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-04-09T00:43:04Z\",\"WARC-Record-ID\":\"<urn:uuid:194a1a3a-eb20-4751-a4eb-63f3cd229870>\",\"Content-Length\":\"29901\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3ccfb8d1-9d5b-4704-b71f-11e50fa3ed44>\",\"WARC-Concurrent-To\":\"<urn:uuid:0ac6a215-3d5c-4d2c-8c1d-9a110849370b>\",\"WARC-IP-Address\":\"185.199.111.153\",\"WARC-Target-URI\":\"https://www.statsmodels.org/stable/generated/statsmodels.sandbox.distributions.transformed.TransfTwo_gen.fit.html\",\"WARC-Payload-Digest\":\"sha1:A5FN7E6I7YGBHAGJFVHRTBZLAESRRCI3\",\"WARC-Block-Digest\":\"sha1:TZECHZZVF6FZRZKFWKICY6NG7DF7W2D3\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-16/CC-MAIN-2020-16_segments_1585371826355.84_warc_CC-MAIN-20200408233313-20200409023813-00066.warc.gz\"}"}