Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code background #16

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ r_output <- function(x) {
}

plain_output <- function(x) {
lang_output(x, "")
lang_output(x, "md") # not great, but at least renders nicely
}
5 changes: 5 additions & 0 deletions differentiability.qmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Differentiability

```{r}
#| include: false
source("common.R")
```

Random walk suppression and other uses
5 changes: 5 additions & 0 deletions installation.qmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Installation

```{r}
#| include: false
source("common.R")
```

Package installation is hard, let's go shopping.

## Packages
Expand Down
5 changes: 5 additions & 0 deletions monty.qmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Monty

```{r}
#| include: false
source("common.R")
```

Before showing how to fit odin models to data, we'll focus for a bit on monty itself. If you are anxious to get on and fit the model from @sec-data-filter, you might skip ahead to @sec-inference, where we resume this.

There are a bunch of things we want to cover in this chapter so likely it will be split into a few:
Expand Down
10 changes: 9 additions & 1 deletion odin.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ library(odin2)

## A simple example {#sec-odin-sir}

Here is a small system of equations for an "SIR" (Susceptible-Infected-Recovered) model, implemented as a set of ordinary differential equations:
Here is a small system of differential equations for an "SIR" (Susceptible-Infected-Recovered) model:

\begin{gather*}
\frac{dS}{dt} = -\beta S \frac{I}{N}\\
\frac{dI}{dt} = \beta S \frac{I}{N} - \gamma I\\
\frac{dR}{dt} = \gamma I
\end{gather*}

And here is an implementation of these equations in `odin`:

```{r}
sir <- odin({
Expand Down
5 changes: 5 additions & 0 deletions references.qmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# References {.unnumbered}

```{r}
#| include: false
source("common.R")
```

::: {#refs}
:::
2 changes: 2 additions & 0 deletions stochasticity.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ sir <- odin({

This is a discrete-time model (using `update()` and not `deriv()`) as stochastic models must run in discrete time. We use `dt` to scale the rates, and adjusting `dt` will change the way that stochasticity affects the dynamics of the system.

The call to `Binomial()` samples from a binomial distribution, returning the number of successes from `S` (or `I`) draws, each with probability `p_SI` (or `p_IR`).

```{r}
sir
```
Expand Down
Loading