Message Boards Message Boards

Fit data with SIR model for epidemics?

Posted 5 years ago

Hello, I am completely new to Mathematica and am having problems with fitting my data to SIR model (modeling epidemics). I don't know how to fit two sets of data (cases and deaths) at once. There might be other mistakes also.

Clear[b, k, f, s, i, r, c, d, all, i0, r0];
tmax = 250.;
all = 100000.;
b = 0.255;
k = 0.2;
i0 = 1.;
r0 = 0.;

{s[t_], i[t_], r[t_]} = {s[t], i[t], r[t]} /.
   NDSolve[{
      s'[t] == -b*s[t]*i[t]/all,
      i'[t] == b*s[t]*i[t]/all - k*i[t],
      r'[t] == (k*i[t]),
      s[0] == all,
      i[0] == i0,
      r[0] == r0},
     {s, i, r}, {t, 0., tmax}][[1]];
f = 0.7;
c[t] == -s[t] + all;
d[t] == f*r[t];
Plot[{c, d}, {t, 0., tmax}]
data = Import["C:\\Users\\...\\Desktop\\NKP\\datafile.txt", 
   "Table"];
cases = data[[All, {1, 2}]];
deaths = data[[All, {1, 3}]];

(*Now I want to fit c[t] to cases and d[t] to deaths at the same time \
so I get one result for b,k and f each.*)
POSTED BY: Vita Hudi

You should look at the documentation for ParametricNDSolveValue under Examples/Applications/Parameter Fitting for an example work flow on fitting parameters. If you still have difficulties, then you will should post the data set too so it is easier to help.

POSTED BY: Tim Laska
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract