hi I’m trying to generate a sample from my distribution with similar proportions/similar trend as I have in observed data
how would I do so?
right now I only can just do a sample from my data with the same distribution, but not the same trend:
my data:
and
generated data:
so it’s only similar in it’s value distribution, not in it’s trend
my code:
import pymc3 as pm
import matplotlib.pyplot as plt
import seaborn as sns
obs = [56.0, 78.0, 36.0, 68.0, 50.0, 45.0, 58.0, 65.0, 90.0, 50.0, 60.0, 63.0, 48.0, 74.0, 73.0, 66.0, 55.0, 65.0, 73.0, 61.0, 55.0, 86.0, 42.0, 43.0, 51.0, 45.0, 49.0, 55.0, 43.0, 42.0, 33.0, 40.0, 39.0, 40.0, 60.0, 53.0, 46.0, 38.0, 36.0, 40.0, 49.0, 35.0, 24.0, 35.0, 45.0, 41.0, 37.0, 32.0, 30.0, 19.0, 28.0, 35.0, 33.0, 46.0, 43.0, 46.0, 52.0, 36.0, 54.0, 40.0, 22.0, 28.0, 37.0, 36.0, 27.0, 33.0, 30.0, 34.0, 23.0, 39.0, 21.0, 25.0, 29.0, 33.0, 26.0, 47.0, 18.0, 44.0, 22.0]
plt.plot(obs);
plt.show()
sns.distplot(obs, hist=True, kde=True, bins=int(180 / 5), color='darkblue')
plt.show()
with pm.Model() as model:
alpha = pm.Exponential('alpha', lam=5)
beta = pm.Exponential('beta', lam=5)
g = pm.Gamma('g', alpha=alpha, beta=beta, observed=obs)
trace = pm.sample(return_inferencedata=True, cores=1)
post_pred = pm.sample_posterior_predictive(trace.posterior)
stats = pm.summary(trace, kind="stats")
alpha_param = stats['mean'][0]
beta_param = stats['mean'][1]
gg = pm.Gamma.dist(alpha=alpha_param, beta=beta_param)
distr = gg.random(size=1000)
sns.distplot(distr, hist=True, kde=True, bins=int(180 / 5), color='darkblue')
plt.show()
plt.plot(distr);
plt.show()