-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2024-08-23 update : added all result visuals & updated docs.
- Loading branch information
Showing
14 changed files
with
435 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
```@setup tutorial | ||
using Plots, StatsPlots; gr() | ||
Plots.reset_defaults() | ||
``` | ||
|
||
# [Generating Posterior Distribution Samples with UCIWWEIHR ODE Compartmental Based Model with Forecasting.](@id uciwwiehr_model_fitting_with_forecast) | ||
|
||
Here we extend the [previous tutorial](@ref uciwwiehr_model_fitting_no_forecast) to include forecasting capabilities. We start with generating out data using `generate_simulation_data_uciwweihr`'s alternate parameterization where we do not prespecify the effective reproduction number and hospitalization probability but instead preform a log-normal random walk and a logit-normal random walk respectively. We then sample from the posterior distribution using the `uciwweihr_fit.jl` function. We then generate desired quantities and forecast for a given time period with the posterior predictive distribution, using `uciwweihr_gq_pp.jl`. | ||
|
||
|
||
## 1. Data Generation. | ||
|
||
Here we generate two datasets, one with 150 time points and one with 178 time points. We will use the 150 time point dataset for fitting and the 178 time point dataset for forecast evaluation. | ||
|
||
``` @example tutorial | ||
using UCIWWEIHR | ||
# Running simulation function with presets | ||
params = create_uciwweihr_params( | ||
time_points = 150 | ||
) | ||
df = generate_simulation_data_uciwweihr(params) | ||
params_ext = create_uciwweihr_params( | ||
time_points = 178 | ||
) | ||
df_ext = generate_simulation_data_uciwweihr(params_ext) | ||
first(df, 5) | ||
first(df_ext, 5) | ||
``` | ||
|
||
## 2. Sampling from the Posterior Distribution and Posterior Predictive Distribution. | ||
|
||
Here we sample from the posterior distribution using the `uciwweihr_fit.jl` function. First, we setup some presets, then have an array where index 1 contains the posterior/prior predictive samples, index 2 contains the posterior/prior generated quantities samples, and index 3 contains the original sampled parameters for the model. The diference here is that we set `forecast = true` and `forecast_weeks = 4` to forecast 4 weeks into the future. | ||
|
||
``` @example tutorial | ||
data_hosp = df.hosp | ||
data_wastewater = df.log_ww_conc | ||
obstimes = df.obstimes | ||
param_change_times = 1:7:length(obstimes) # Change every week | ||
priors_only = false | ||
n_samples = 200 | ||
forecast = true | ||
forecast_weeks = 4 | ||
samples = uciwweihr_fit( | ||
data_hosp, | ||
data_wastewater, | ||
obstimes, | ||
param_change_times, | ||
priors_only, | ||
n_samples | ||
) | ||
model_output = uciwweihr_gq_pp( | ||
samples = samples, | ||
data_hosp = data_hosp, | ||
data_wastewater = data_wastewater, | ||
obstimes = obstimes, | ||
param_change_times = param_change_times, | ||
forecast = forecast, | ||
forecast_weeks = forecast_weeks | ||
) | ||
first(model_output[1][:,1:5], 5) | ||
``` | ||
|
||
``` @example tutorial | ||
first(model_output[2][:,1:5], 5) | ||
``` | ||
|
||
``` @example tutorial | ||
first(model_output[3][:,1:5], 5) | ||
``` | ||
|
||
## 3. MCMC Diagnostic Plots/Results Along with Posterior Predictive Distribution. | ||
|
||
We can again look at model diagnostics, posterior distribution of time or non-time varying parameters, and the posterior predictive distribution extended for forecasting. | ||
|
||
```@example tutorial | ||
uciwweihr_visualizer( | ||
pp_samples = model_output[1], | ||
gq_samples = model_output[2], | ||
data_hosp = df_ext.hosp, | ||
data_wastewater = df_ext.log_ww_conc, | ||
actual_rt_vals = df_ext.rt, | ||
actual_w_t = df_ext.wt, | ||
actual_non_time_varying_vals = params, | ||
forecast_weeks = forecast_weeks, | ||
bayes_dist_type = "Posterior", | ||
save_plots = false | ||
) | ||
``` | ||
|
||
### 3.1. MCMC Diagnostic Plots. | ||
|
||
![Plot 1](plots/mcmc_diagnosis_plots.png) | ||
|
||
### 3.2. Time Varying Parameter Results Plot. | ||
|
||
![Plot 2](plots/mcmc_time_varying_parameter_plots.png) | ||
|
||
### 3.3. Non-Time Varying Parameter Results Plot. | ||
![Plot 3](plots/mcmc_nontime_varying_parameter_plots.png) | ||
|
||
### 3.4. Posterior Predictive Distribution Plot. | ||
|
||
![Plot 4](plots/mcmc_pred_parameter_plots.png) | ||
|
||
|
||
### [Tutorial Contents](@ref tutorial_home) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.