In order to fit given data to theoretical distribution and then draw random values from that distribution, does this scheme work with all distributions in scipy.stats?
from scipy.stats import beta, expon, gamma, genpareto, genextreme, lognorm, kappa3, pearson3, weibull_min
data = [529, 7065, 2739, 1838, 817, 1376, 3791, 5070,
736, 805, 577, 2963, 7017, 3026, 2542, 2160,
221, 3340, 582, 1080, 1040, 1310, 5500, 4800,
485, 7110, 4150, 2700, 4610, 1270, 10476, 1975,
731, 150, 1163, 985, 5476, 5762, 1750, 609, 1009,
14704, 678, 3837, 1069, 948, 460, 1819, 5958,
1356, 2025, 1136, 4500, 882, 8230, 3521, 1561,
695, 3380, 1210, 4311]
d = {"beta": beta,
"expon": expon,
"gamma": gamma,
"genpareto": genpareto,
"genextreme": genextreme,
"lognorm": lognorm,
"kappa3": kappa3,
"pearson3": pearson3,
"weibull_min": weibull_min} # there could be more later
ans = {}
for nm, f in d.items():
params = f.fit(data)
ans[nm] = f.rvs(*params, size=100)
I am mainly concerned about the ans[nm] = f.rvs(*params, size=100) line. Does *params always insert appropriate arguments into the rvs method? Or is it necessary to tinker with input based on distribution? For example, in case of pearson3, is it necessary to separately calculate skew?
from fit theoretical distribution and draw random values
No comments:
Post a Comment