Skip to content

Commit 565076c

Browse files
Update index.qmd with edge case for data-fitting (#631)
* 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. * Update tutorials/bayesian-differential-equations/index.qmd --------- Co-authored-by: Penelope Yong <[email protected]>
1 parent 11243c3 commit 565076c

File tree

1 file changed

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

1 file changed

+3
-1
lines changed

tutorials/bayesian-differential-equations/index.qmd

Lines changed: 3 additions & 1 deletion
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,12 @@ 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.
115116
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?).
117+
In the case of continuous observations (e.g. data derived 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 itself also be a parameter with a prior distribution).
116118

117119
```{julia}
118120
@model function fitlv(data, prob)

0 commit comments

Comments
 (0)