0

I want to get a mean distribution from several gamma distributions I have fitted on data. What I do is taking all the no, mu, delta paramaters in a np array. Then I average all the values for each parameter and plot the resulting function.

For each distribution :
    .......
    # Fit gamma function on diameter distribution
    no, mu, delta, std = fitgamma(Diam,DN)
    gamma_params1.append([no, mu, delta])
    ax1.plot(Diam, gamma_pluie(Diam, no, mu, delta), color=cmap1(i / 100), alpha = 1)

    no, mu, delta, std = fitgamma(Diam,DS)
    gamma_params2.append([no, mu, delta])
    ax2.plot(Diam, gamma_pluie(Diam, no, mu, delta), color=cmap1(i / 100), alpha = 1)

# Mean distribution ?
mean_gamma1 = np.mean(np.asarray(gamma_params1), axis = 0, dtype=np.float64)
mean_gamma2 = np.mean(np.asarray(gamma_params2), axis = 0, dtype=np.float64)

ax1.plot(Diam, gamma_pluie(Diam,
                           mean_gamma1[0],
                           mean_gamma1[1],
                           mean_gamma1[2]), color = (0,0,0))

ax2.plot(Diam, gamma_pluie(Diam,
                           mean_gamma2[0],
                           mean_gamma2[1],
                           mean_gamma2[2]), color = (0,0,0))

As a result, I have an erroneous average distribution, see image where the average is in black.

enter image description here

Here are some values of parameters if you want to reproduce.

print(np.asarray(gamma_params1)[0:20])

[[1.18877448e+06 7.04345338e+00 1.68131178e+01]
 [1.03580071e+10 1.17231228e+01 2.80801622e+01]
 [1.17608742e+10 1.16680950e+01 2.84500599e+01]
 [3.37787472e+07 8.17963499e+00 2.20031830e+01]
 [4.83799744e+07 8.28895053e+00 2.26656547e+01]
 [5.19290678e+07 8.63384571e+00 2.20782461e+01]
 [1.40177731e+08 9.22200410e+00 2.32053962e+01]
 [5.68214219e+08 9.90427962e+00 2.50426706e+01]
 [5.57257901e+07 8.54239570e+00 2.24352266e+01]
 [1.27453235e+08 9.26482886e+00 2.28948126e+01]
 [1.95639509e+07 8.08465980e+00 2.09512964e+01]
 [3.05655808e+07 8.27016599e+00 2.15814053e+01]
 [3.05999880e+07 8.39995168e+00 2.13405995e+01]
 [2.16642330e+07 8.19273999e+00 2.09438975e+01]
 [1.74341499e+08 9.15535097e+00 2.38455465e+01]
 [1.93303173e+07 8.10004799e+00 2.08898913e+01]
 [3.03928842e+07 8.39236912e+00 2.13497082e+01]
 [1.66088575e+08 9.11634132e+00 2.38010576e+01]
 [1.23082570e+07 7.78323253e+00 2.05413485e+01]
 [2.29486547e+07 8.13571051e+00 2.12599857e+01]]

Weird thing is that it works good with the numpy.median() function... Any idea ?

Result with np.median() :

mean_gamma1 = np.median(np.asarray(gamma_params1), axis = 0)
mean_gamma2 = np.median(np.asarray(gamma_params2), axis = 0)

enter image description here

  • What do you mean by "mean distribution from several gamma distributions"? I don't think "mean distributions" are a thing. You can have a "mean distribution" when you're dealing with a mixture of gamma distributions, but you'll need to know the mixing distribution. – ForceBru Mar 04 '21 at 09:22
  • I edited the post and added the median version. I want something like this but taking the median values seems less relevant than the mean ones. – Karl Montalban Mar 04 '21 at 09:30
  • What about `np.average`? – user8408080 Mar 04 '21 at 09:49
  • Thanks but same result as np.mean :/ – Karl Montalban Mar 04 '21 at 10:03
  • Then it's maybe not possible to average the parameters, have to tried averaging the whole curves? I mean you seem to have calculated them anyway, so this shouldn't be extra work – user8408080 Mar 04 '21 at 10:16

0 Answers0