I am trying to to fit the data set to an SEIR model, however, I have encountered several problems while doing so and can not make it function..
Here is the most basic version of the code as well as the most basic set of data to test it with. Could you please have a look and help me solve this issue? I have been struggling several long days to solve it, but I am unable do it.
The goal is to fit the data set (which represents the "Infected population" (II in the code) into the model, so that the fit function produces appropriate parameters k1,k2,k3,k4 for the best fit.
data set:
flulist = {{0, 0.001}, {1, 0.003}, {2, 0.007}, {3, 0.025}, {4,
0.072}, {5, 0.222}, {6, 0.282}, {7, 0.256}, {8, 0.233}, {9,
0.189}, {10, 0.123}, {11, 0.07}, {12, 0.025}, {13, 0.011}, {14,
0.004}}
model:
model1 = ParametricNDSolveValue[{
SS'[t] == -k1*SS[t]*II[t] + k2*RR[t],
EE'[t] == k1*SS[t]*II[t] - k3*EE[t],
II'[t] == k3*EE[t] - k4*II[t],
RR'[t] == -k2*RR[t] + k4*II[t],
SS[0] == 0.79, EE[0] == 0, II[0] == 0.31, RR[0] == 0},
II, {t, 0, 300}, {k1, k2, k3, k4}];
fit = FindFit[flulist, model1[k1, k2, k3, k4][t], {k1, k2, k3, k4}, t]
It takes a long time to calculate, and in the end it still gives error messages instead of any results. From working examples online, this process should take a second (not 10 minutes), so something is obviously not right with the fitting process. I would not mind taking it 10 minutes, but it does not yield results.
I have tried different integration Methods, Accuracy/PrecisionGoal, Non/LinearModelFit/FindFit/Predict.. literally everything I found on the internet, however, I can not get the fitting process to work for this system of equations.
The possible reasons that might be causing this error could be:
- Fit function might be confusing which equation out of the system of equations it is supposed to match with the data (e.g. it is supposed to find best parameters to match infected, II equation, but does it actually do it?)
- integration method problem
- Initial parameters SS[0] == 0.79, EE[0] == 0, II[0] == 0.31, RR[0] == 0,, are firmly set. Even though it tries to match the data with different initial value eg. first data point has II[0]=0.001, not II[0] == 0.31.
I have tried approaching all the above problems but.. I would not be posting here if I hadn't tried everything.
If you can fix this, or create an entirely new/different approach to find the best fit, I would be grateful. Thank you very much for helping.
{6, 282}
. $\endgroup${k1 -> 5.7926, k2 -> 33.3961, k3 -> 0.620497, k4 -> 2.71203}
. $\endgroup$