Skip to content

Commit d305b1c

Browse files
exercises
1 parent c0b6755 commit d305b1c

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

exploration-exercises.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ per-capita rates or mass-action rates. There are a variety of
107107
functions](https://canmod.github.io/macpan2/reference/engine_functions)
108108
that you can use to build more complex functional forms for these rates.
109109

110-
| <img src="images/exercise.svg" width="120" /> |
111-
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
112-
| Building a simple model with seasonal cycles in transmission. What are some other forms of complexity in the functional forms of rates? Try to implement them. Keep in mind that you can use tilde-based expressions to define intermediate variables. |
110+
| <img src="images/exercise.svg" width="120" /> |
111+
|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
112+
| Build a simple model with seasonal cycles in transmission. What are some other forms of complexity in the functional forms of rates? Try to implement them. Keep in mind that you can use tilde-based expressions to define intermediate variables. |
113113

114114
## Unbalanced Flows
115115

@@ -231,7 +231,7 @@ early_on_covid_reports = read_csv("https://raw.githubusercontent.com/canmod/macp
231231

232232
Here are some `ggplot2` recipes for visualizing goodness-of-fit. If you
233233
had a fitted calibrator called `model_calibrator` that were fitted to
234-
`observed_data`, you can use this formula.
234+
`observed_data`, you can use this recipe (not run).
235235

236236
``` r
237237
fitted_data = mp_trajectory(model_calibrator)
@@ -242,25 +242,48 @@ fitted_data = mp_trajectory(model_calibrator)
242242
)
243243
```
244244

245+
If you would like to visualize uncertainty around this fitted
246+
trajectory, you can use the `geom_ribbon` function in `ggplot2`.
247+
248+
``` r
249+
fitted_data = mp_trajectory_sd(model_calibrator, conf.int = TRUE)
250+
(ggplot()
251+
+ geom_point(aes(time, value), data = observed_data)
252+
+ geom_line(aes(time, value), data = fitted_data)
253+
+ geom_ribbon(aes(time, ymax = conf.high, ymin = conf.low), data = fitted_data)
254+
+ theme_bw()
255+
)
256+
```
257+
245258
## Confidence Intervals for Estimated Parameters
246259

247260
| <img src="images/exercise.svg" width="120" /> |
248261
|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
249262
| For one of your calibrated models, use the [mp_tmb_coef](https://canmod.github.io/macpan2/reference/mp_tmb_coef.html) function to get parameter estimates with confidence intervals. |
250263
| Note that you will need to use `conf.int = TRUE` option that is a little hidden in the documentation, but it is there. Did any of your parameters have an interval that overlaps zero? If so try to fix this by fitting the log transformed version of the offending parameter. If you call the log of your parameter `log_{name-of-parameter}`, the confidence intervals will be automatically back-transformed to the original scale and will not overlap zero. Did you get any NaNs (not a number)? This is a sign of a bad fit. |
251264

252-
## Forecasts
265+
## Forecasts and Scenarios
253266

254267
Let’s keep it simple again and get more practice simulating and fitting.
268+
You can use this calibrated model to practice making forecasts and
269+
exploring scenarios.
255270

256271
``` r
257272
exercise(
258-
"Simulate 50 time steps of incidence (i.e., the infection flow) from the SIR model in the library with defaults. Create a calibrator but change the default values of `beta` and `gamma` so that the optimizer will need to do work to find the true values."
273+
"Simulate 50 time steps of incidence (i.e., the infection flow) from the SIR model in the library with defaults. Create a calibrator but change the default values of `beta` and `gamma` so that the optimizer will need to do work to find the true values. Then calibrate your model to the simulation data using [mp_optimize](https://canmod.github.io/macpan2/reference/mp_optimize.html). After optimizing use [mp_forecaster](https://canmod.github.io/macpan2/reference/mp_forecaster) to extend 50 more time steps, so that the entire simulation would be 100 time steps. Use [mp_trajectory_sd](https://canmod.github.io/macpan2/reference/mp_trajectory.html) to produce forecasts with confidence intervals."
259274
)
260275
```
261276

262-
| <img src="images/exercise.svg" width="120" /> |
263-
|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
264-
| Simulate 50 time steps of incidence (i.e., the infection flow) from the SIR model in the library with defaults. Create a calibrator but change the default values of `beta` and `gamma` so that the optimizer will need to do work to find the true values. |
277+
| <img src="images/exercise.svg" width="120" /> |
278+
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
279+
| Simulate 50 time steps of incidence (i.e., the infection flow) from the SIR model in the library with defaults. Create a calibrator but change the default values of `beta` and `gamma` so that the optimizer will need to do work to find the true values. Then calibrate your model to the simulation data using [mp_optimize](https://canmod.github.io/macpan2/reference/mp_optimize.html). After optimizing use [mp_forecaster](https://canmod.github.io/macpan2/reference/mp_forecaster) to extend 50 more time steps, so that the entire simulation would be 100 time steps. Use [mp_trajectory_sd](https://canmod.github.io/macpan2/reference/mp_trajectory.html) to produce forecasts with confidence intervals. |
280+
281+
``` r
282+
exercise(
283+
"Create a scenario for beta, where transmission increases by a factor of 1.2 at time 60 (10 time steps after the data end). The answers for this exercise are [here](https://github.com/canmod/macpan-workshop/blob/main/code/simple-scenario.R)."
284+
)
285+
```
265286

266-
## Scenario
287+
| <img src="images/exercise.svg" width="120" /> |
288+
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
289+
| Create a scenario for beta, where transmission increases by a factor of 1.2 at time 60 (10 time steps after the data end). The answers for this exercise are [here](https://github.com/canmod/macpan-workshop/blob/main/code/simple-scenario.R). |

0 commit comments

Comments
 (0)