Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python testing if my data follows a lognormal distribution

Tags:

python

scipy

Hi I have a distribution of results that is positively skewed so I want to test if it is a good fit to a log-normal distribution or a Gumbell distribution.

I have used scipy before so I would be particularly interested in a solution that uses that.

My data is as follows:

listofdata =[2.6631285853098805, 1.948723030911822, 0.7325723211390256, 2.2214185217697033, 3.1973557053902932, 2.721464385217916, 6.047370467406893, 2.1765253837023133, 1.306088411159033, 2.037397915785744, 0.6862715889678953, 1.6537292516821143, 0.6817011291422773, 0.60568083550246, 3.4541516258461225, 1.656598441242852, 0.9973472121207236, 3.994828136966692, 1.2493128240123388, 1.318803895196777, 1.8219708475333733, 1.7803822001562708, 3.5163486988690806, 1.4751609825413308, 0.9884113209191469, 1.2980162786357938, 6.113447232418334, 1.3977589458544686, 1.3801647781025739, 1.590725233816818, 1.1810871981759308, 0.8465477721823732, 3.840200049154681, 1.7554665652380321, 1.5723775058591742, 4.500040304113793, 3.160488460719387, 1.3047308289360104, 2.274979276414489, 0.9723041606774018, 1.1567129068539885, 2.5565846148750895, 2.207555444411525, 3.9312893279475367, 0.9645189125969524, 2.335251067183356, 2.137155238698881, 1.692118350167095, 3.7484654065657317, 2.462059088568015, 1.709511478987372, 5.715634836586185, 4.007251296312767, 0.7920956096185022, 2.022714463787213, 3.6688048370106, 2.403327178013035, 1.3352007066736067, 1.66939693318501, 2.874196897009085, 1.1881850454957774, 2.579568121065461, 3.5966255826677638, 3.6845567419377976, 1.811342042134277, 2.72660313403154, 1.5281549016493845, 3.0009286822719448, 1.9066586300548696, 1.458152722378702, 4.3986928824471185, 2.469956971757018, 2.234841611733566, 2.167520317680794, 2.8227039648170944, 2.1680491069116337, 2.791952773940272, 2.7561204297857445, 3.864343552457842, 4.163309180742488, 1.3885516350912332, 1.5804900958284296, 1.7802071358399305, 1.053751762721538, 1.4606173223348946, 1.6396991782893227, 3.975995706374045, 1.7069750915722237, 2.7394711066762856, 2.932233687553241, 2.801765372352213, 1.8055086910114486, 4.386319520417248, 6.231899492086985, 1.9099936593860443, 1.4623481604454012, 1.6664581852371045, 0.9640381031320316, 3.798087950415322, 5.941754430001641, 0.6396615233190119, 1.6475205547422664, 0.9206837382120625, 1.13649665702186, 3.190532670519826, 1.8179993080793222, 1.2883848748915967, 1.6886913583637237, 3.0253353325933525, 2.5459601801373424, 3.553558930272823, 3.0167019019366195, 2.093910031934536, 2.387012247818087, 6.599382663248629, 2.2250434798564247, 2.217618989085747, 5.029331918631793, 3.8614067384474655, 1.5238916754723622, 1.4413941704278046, 3.7037545029041326, 1.3380847555974584, 2.81986125570312, 1.6722094303958446, 0.8333766382783666, 3.415118103622843, 0.9638789362679631, 1.0872082475073852, 0.653371376107782, 1.9328274820705817, 5.719890351366793, 3.727756437255686, 4.013921036687349, 5.274583205793386, 5.075972778513814, 3.2332547305133743, 4.784095191295217, 1.749928666320386, 0.9466632533417737, 1.7473617554197174, 1.7327087344009329, 4.254653689587041, 2.704724201264992, 1.302947557035884, 4.544662425542001, 1.7359099700035927, 3.762424742225096, 3.2821877078112833, 2.3782263261571073, 5.100654633325338, 4.066351496553931, 3.97552948329211, 2.5951057372086663, 1.7714901372033298, 1.525460925528444, 4.751135330410933, 1.8478272067456718, 4.522860286225603, 1.33108096647635, 1.4631079480345421, 3.3889471890043175, 5.375750765463488, 1.572192614906169, 1.8849615994731381, 2.1640833393579335, 1.400734015801129, 1.199408997635476, 1.283800021440095, 3.969005754593775, 4.688120068063393, 0.6094648531043163, 1.3376356639533813, 1.4298774989278287, 1.682937405662949, 1.5503814228713855, 5.1908910399526915, 3.3491293091840024, 1.6974575131253573, 1.9853315310458242, 2.1905668019808564, 1.8187658425231694, 1.4888560838650278, 2.0158070339920764, 2.0791245525913955, 1.8269910833823249, 1.376401604937098, 2.9200172207676696, 1.4064524965873375, 3.933919109117903, 1.6981680652230462, 0.9253776818632217, 3.425663590986357, 2.4371772991536425, 1.3415420778437126, 2.5286957289128504, 1.5631285450027126, 2.3792763267009724, 2.112288439090446, 0.853331930788329, 3.01387170836307, 3.868024990596985, 2.3046965854680486, 1.4412029778159994, 3.9219205615541917, 4.912245175829266, 1.5603334400589013, 2.060750001743202, 2.2176605660206063, 2.1638446665173547, 6.069381531603165, 1.4174522634614846, 2.6557438655852477, 2.3035186997719967, 3.4088606969399393, 3.8218576477085096, 0.9220973744491742, 2.7727867248032334, 3.5597658039422537, 1.0705020358064419, 2.446479128826161, 5.8158612152005515, 1.7227692291642485, 1.2786263253762058, 1.094889840451913, 2.004283509510617, 2.4416686355784467, 5.001676036540756, 1.7314916420110538, 1.0192792374065558, 1.376025503501194, 1.9554409006370301, 2.911617211807391, 6.058430670167684, 1.3812081238895986, 4.525492684961262, 3.0477125394845994, 0.9271038124867458, 2.965930100533376, 2.143607628397433, 3.2324344761887347, 3.7712935020551077, 1.1845418838483626, 1.2951075263854706, 2.640592456495699, 1.1492445590222249, 2.139926413691671, 1.415089804907359, 1.001728381293617, 2.9862128133023242, 1.722988802145494, 2.7998080908644276, 2.069879670956732, 2.763383217528315, 2.321711598999366, 4.3227378002122006, 1.5810984288128, 3.076173072407175, 2.3282175076493217, 1.2022065905379693, 1.769249151091106, 1.6128692411271346, 1.379811277656916, 2.7008791469980555, 3.039836410984219, 1.3679957379842678, 3.0028470634866715, 2.9206849757337867, 1.4454681539613488, 2.3185725366247314, 2.2148330412723114, 2.1522529057362476, 4.12832262797084, 4.276295290166637, 1.1908214069483278, 1.6615379521658384, 0.9022115996830166, 5.312270194426526, 2.5121965619024538, 1.7550141990482993, 1.9771937741057517, 2.5367219088304527, 1.3631537379612273, 4.301202799295913, 2.046943419762249, 3.3237322475962516, 2.0978315839682526, 2.973408753252409, 3.4607880004390497, 3.4569611078641524, 2.237036802429213, 5.996833779655401, 2.620377791494286, 1.4514003425523585, 4.432585331847452, 6.890304980819486, 4.708229269332186, 2.683235474594801, 1.393334095590592, 2.1876660156460845, 1.715925142349704, 4.496556395378718, 1.0899670522676954, 1.3555804411348507, 1.6257532470905858, 1.1305247113980272, 1.3973829944943303, 1.4514613497570399, 4.416290665552117, 4.670174218054661, 1.455709899721808, 2.8568093861539525, 2.549283449230063, 1.523048849798295, 0.776152455009981, 1.1927682656178262, 1.4698682343959604, 0.9268397464195571, 2.1434126568063565, 1.1031837372307678, 2.2013642799807367, 3.89474349953697, 1.3835302910509315, 2.328532153978324, 2.3652662157964532, 1.460171504244943, 2.353475705620087, 6.505381032718413, 1.0627882008788103, 1.481573631085678, 2.135527174377069, 2.097130442026503, 1.0554115389981575, 1.3683875605618936, 6.058430670167684, 1.413608877073841, 0.9163216347346066, 2.2169974272656985, 1.491360564704439, 2.2610376866959654, 0.9996350752044578, 3.082605699458043, 1.1805687265794973, 1.3244957400729278, 1.7612812885785958, 0.7201988411797062, 1.893224708694436, 0.8953041203583892, 1.1970462872638223, 2.382324056346477, 1.9433581408100171, 3.0426055429459553, 2.98659983050751, 2.041207210280311, 3.113805787569811, 2.8152908162760584, 2.133493802789269, 1.062025175014912, 1.9187070234303867, 3.039891409580889, 2.842364992201135, 3.0964741881318454, 1.325725951307561, 1.6139351127268926, 2.0964970963061775, 6.094065297595637, 1.9328960213975168, 0.8643295749025923, 1.4574352176412393, 0.8829513097988297, 1.7000672527406895, 4.969916526049599, 2.0098709212613244, 1.8295321928593353, 2.9767045248525736, 5.094576736772535, 1.6897634221302613, 2.7251772959355436, 2.668543530304771, 3.818645906555901, 1.5801536429044638, 2.267034140667636, 4.215234687025543, 1.082202224737796, 2.0533223399257743, 1.2580587946235826, 1.1993837400744838, 1.4873982438211786, 1.441834660966117, 1.1333851437009688, 1.2650447265844944, 2.1434218190387244, 1.4636742455652325, 1.1237341223973887, 4.254700905473931, 2.5883325431123354, 1.5009640100274624, 0.8640023787861196, 2.10057993883928, 6.23023641387366, 2.3394033877896057, 2.054202713804114, 2.2471673823043266, 0.8697105719270324, 2.5736959967597044, 1.5968034536981917, 1.9360852185713497, 2.207347119502118, 5.995124760786587, 2.3184067425093993, 3.7792955774416104, 2.5600355259438516, 2.063983561817452, 2.1762570501494904, 1.9545853743984374, 1.284400919767211, 1.113409023729889, 6.925691011137326, 2.3341975139709237, 0.8958568879715244, 2.8300657056369234, 1.5028745032136048, 1.234165494499155, 0.8726718755983369, 1.518786148775064, 1.6584564684852126, 3.727613206060198, 3.2677276129035024, 2.72620420011582, 2.1128179320322604, 1.284251736220551, 2.0414978371537824, 4.499862707847422, 1.597854901409971, 1.7453554200318762, 1.7718980536944515, 1.8213597882243564, 6.925691011137326, 3.267712843906213, 1.4599115046304525, 2.298227722215677, 1.2714446242676447, 1.5638811171853495, 1.3669668521364768, 2.2204318393208844, 2.8243994341950276, 2.044273083814221, 1.9899375494728138, 1.4368589390064357, 1.332446098309913, 1.2156754847339364, 6.233075393442153, 1.8298441247714783, 6.1823442730375415, 1.4379664358797641, 4.1257007707626485, 1.9044630711575907, 2.470553995968077, 5.866250292601297, 1.255662181816604, 1.5140048525842649, 2.657060232661468, 2.778908460715467, 4.231890673028045, 5.931473602301425, 2.68535304385847, 1.4343877983634117, 1.3679492613277606, 3.004958007907305, 2.7087570724571948, 2.915722773553568, 1.0355520668809162, 0.9224800557295452, 2.494795916039982, 2.2348421734045703, 1.6201077679873268, 2.7813118895693942, 1.198310995491613, 2.3040660679490537, 1.2932237171327532, 2.834421862128772, 1.387968872040949, 1.024888336344895, 1.370532116447396, 2.6421835520219816, 1.307180593341525, 3.007495630469009, 2.876374021350295, 1.242985291946491, 1.3809912706970524, 4.38616276706074, 1.3962400102325887, 4.148812526715677, 0.7690549533611034, 3.500610634498923, 0.6946915612824682, 3.7250741821763427, 1.477922330517788, 3.1116113270191703, 4.16246893729159, 3.087825061769616, 3.600963894162931, 5.093131858053347, 2.6177087969890294, 3.514093669751753, 1.8414608524694474, 1.4842151016706226, 2.7202701086573478, 3.454150906498137, 1.6986509194055657, 1.3237619954001847, 1.408311312479748, 4.293873222920515, 2.8337402354759322, 1.5382438398514413, 2.7071429486111462, 2.0743820281228986, 1.0654447643277418, 3.9570723319709376, 1.0235266820133686, 1.0019799701700438, 0.8022216046489916, 2.598136255775342, 3.5704954064092025, 2.50573097683083, 6.241715435280128, 0.9617848446586663, 2.789996754666902, 2.34290795966932, 1.0746084576917496, 2.9484305982585175, 2.7462636109212664, 1.5188419792977246, 2.054685248073509, 2.365927360649732, 1.9494668145689167, 2.9421449628084586, 1.5185140216743662, 2.573136048496998, 4.354862282941338, 1.3234907145399237, 2.54964139539378, 3.142802328924847, 2.6709728331131712, 4.438413270023023, 3.7200423628230848, 3.8223619809512575, 4.5367727771413575, 1.019930017485342, 1.3660281441774373, 2.1669618687480696, 5.68366536642535, 4.551469748029795, 3.330198375677071, 3.4241899352978296, 1.4409221435878752, 1.92152191393692, 5.303429640376464, 0.8902493656335649, 0.8484118348433071, 3.140582424364573, 3.85601499325702, 2.4330666696369803, 6.058431338539675, 4.185483681795529, 4.396912357632606, 3.1985724580568213, 1.2622032913354244, 5.071286922400795, 1.3577349076124052, 0.8386698665930794, 1.583960030146625, 2.3165090264333568, 2.4268724248578684, 1.3103225230814022, 2.848158441342469, 1.5830995853818086, 1.623850822661541, 4.131845973675001, 3.6583424474137143, 3.256075028727502, 1.378949943606347, 1.1548851827309252, 4.042005794764293, 0.8767602008278913, 2.0588224565452387, 2.769542660383933, 2.7389826447953625, 1.847221632704498, 1.988084035898203, 2.5996665022037986, 1.7318042565547218, 2.2037727392705513, 3.8471428538245505, 2.430388568655724, 0.9944268869340591, 1.4952205655327475, 4.843766010646061, 1.1086439860938186, 1.826784919886825, 1.3055612039004134, 2.2404340831671905, 1.2729546869394994, 1.7632930086409375, 1.6919598475253337, 2.946514032261155, 1.7605124901475733, 1.4434407191536027, 1.010622271635282, 1.2895021199482586, 1.3175421234935245, 2.526015815718631, 2.4642424103584175, 1.1973702301666782, 2.2325460171325524, 1.6168912451241, 1.7498546608031689, 2.098356053647092, 3.314708785562868, 2.4571380603389907, 2.07546261668025, 1.2223602012291284, 2.3280094595669305]

I have cut down the list due to the character limit. However the distribution should look like this:

data that I want to fit against lognormal distribution

EDIT: How would I quantitatively find how 'suitable' the data is to the distribution?

like image 730
piccolo Avatar asked Apr 22 '16 14:04

piccolo


1 Answers

You can simply use scipy.stats.lognorm.fit to fit your data to a lognormal distribution. This will give you a tuple

(0.60845558877160033, 0.27409944344131409, 1.8037732130179509)

which represents shape, location, and scale respectively. If you want the more common parameters of mu and sigma, you can obtain them like so

shape, location, scale = scipy.stats.lognorm.fit(listofdata)
mu, sigma = np.log(scale), shape

You can use the scipy.stats.gumbel_l.fit function similarily for that respective distribution, which will return the location and scale.

As far as how to test goodness of fit for each distribution, one possibility would be to use the Kolmogorov-Smirnov test with scipy.stats.kstest.

like image 186
miradulo Avatar answered Nov 01 '22 05:11

miradulo