Hi,
I am trying to plot the multi-switchpoint posterior distributions, but the graph output looks different from the posterior distributions, can anyone tell me what I am doing wrong, please?
The results of the posterior distributions are:
And my code for the plot is below
early_rate_samples = trace['lambda_1']
late_rate_samples = trace['lambda_2']
later_rate_samples = trace['lambda_3']
changepoint_samples = trace['tau_1']
changepoint_2_samples = trace['tau_2']
#N samples from the corresponding posterior distribution.
N = ((changepoint_samples.shape[0]) + (changepoint_2_samples.shape[0]))
expected_Outbreaks_per_week = np.zeros(number_of_weeks)
for week in range(0, number_of_weeks):
# ix is a bool index of all changepoint samples corresponding to
# the changepoint occurring prior to value of 'week'
ix = (week <= changepoint_samples) & (changepoint_2_samples >= week)
expected_Outbreaks_per_week[week] = (early_rate_samples[ix].sum() + late_rate_samples[ix].sum() + later_rate_samples[~ix].sum()) / N
plt.plot(range(number_of_weeks), expected_Outbreaks_per_week, lw=4, color="#E24A33",
label="expected number of Outbreak incident")
plt.xlim(0, number_of_weeks)
plt.xlabel("Time (weeks)")
plt.ylabel("Expected # Outbreaks")
plt.title("Expected number of Outbreak Incident")
plt.ylim(0, 15)
plt.bar(np.arange(len(twitter_df['twitter_stream_count'])), twitter_df['twitter_stream_count'], color="#348ABD", alpha=0.65,
label="observed Outbreak per week")
plt.legend(loc="upper left");
The graph below plotted from the code looks completely way off the posterior distribution outputs.
Can you tell me what I am doing wrong here, please?
Thanks