Skip to content

Commit 17bf8ff

Browse files
matthraspenelopeysm
authored andcommitted
Update index.qmd with edge case for data-fitting
This case came from attempting to adapt the code to fitting experimental data to an ODE model derived from chemical equations. It turns out that using the Normal distribution is recommended in the general case according to one of my supervisors.
1 parent 6555834 commit 17bf8ff

File tree

1 file changed

+3
-2
lines changed
  • tutorials/bayesian-differential-equations

1 file changed

+3
-2
lines changed

tutorials/bayesian-differential-equations/index.qmd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ To make the example more realistic, we generate data as random Poisson counts ba
8282
Poisson-distributed data are common in ecology (for instance, counts of animals detected by a camera trap).
8383
We'll assume that the rate $\lambda$, which parameterizes the Poisson distribution, is proportional to the underlying animal densities via a constant factor $q = 1.7$.
8484

85+
8586
```{julia}
8687
sol = solve(prob, Tsit5(); saveat=0.1)
8788
q = 1.7
@@ -108,11 +109,11 @@ Practically, this helps us to illustrate the results without needing to run over
108109
Note we also have to take special care with the ODE solver.
109110
For certain parameter combinations, the numerical solver may predict animal densities that are just barely below zero.
110111
This causes errors with the Poisson distribution, which needs a non-negative mean $\lambda$.
111-
To avoid this happening, we tell the solver to aim for small abolute and relative errors (`abstol=1e-6, reltol=1e-6`).
112+
To avoid this happening, we tell the solver to aim for small absolute and relative errors (`abstol=1e-6, reltol=1e-6`).
112113
We also add a fudge factor `ϵ = 1e-5` to the predicted data.
113114
Since `ϵ` is greater than the solver's tolerance, it should overcome any remaining numerical error, making sure all predicted values are positive.
114115
At the same time, it is so small compared to the data that it should have a negligible effect on inference.
115-
If this approach doesn't work, there are some more ideas to try [here](https://docs.sciml.ai/DiffEqDocs/stable/basics/faq/#My-ODE-goes-negative-but-should-stay-positive,-what-tools-can-help?).
116+
If this approach doesn't work, there are some more ideas to try [here](https://docs.sciml.ai/DiffEqDocs/stable/basics/faq/#My-ODE-goes-negative-but-should-stay-positive,-what-tools-can-help?). In the case of continuous observations (e.g. deriving from modelling chemical reactions), it is sufficient to use a Normal distribution with the mean as the data point and an appropriately chosen variance (which can also be a parameter with a prior distribution).
116117

117118
```{julia}
118119
@model function fitlv(data, prob)

0 commit comments

Comments
 (0)