Day 232: Coronavirus modeling – Part 5
Well I did it! I finished my model to the best of my abilities. There are a few things I wish I had time to change or do differently, but I think that just comes from actually doing it and not having a clear idea of how I wanted to do it when I started. Let’s take a little look at some of the outputs from the model and I’ll talk a little bit on what the model is designed for, it’s limitations, and the things I wish I could’ve done differently
Part of my initial issues was the formulation for the model. I had to break it out of its original formatting into separate chunks so that I could test each individually. Originally I had it in a state-space model formulation. For those who are not familiar with the way that looks, it looks a little like this
It’s just a giant matrix that you can crank through time (t) with some initial conditions. This is a very compact way of writing it, it’s nice to use, but it also means that I can’t easily see what each equation is doing at each timepoint. I mean you can, but I don’t like it. So I had to break my model out into the individual equations, which look something like this
Now my equations look slightly different because I had an extra state involved. However, this is the general formulation. This way I can step each equation individually like links in a chain to see what is going on. For me (at this stage of my career) it was easier to debug in this form. It’s also unruly overall a pain, but dealing with a system of non-linear ordinary differential equations isn’t easy. So with that if I had more time I would REALLY like to put it back into state space form, it’s much more compact and it would streamline my code significantly.
To complicate matters, there are a LOT of different solutions for the system and not all of them make sense in the real world even though the math works. For example, we could have a negative population in one of the states, the math allows for it, but in the real world you can’t have less than no one sick or exposed. It can be zero, it’s just nonsensical if it were less than zero. So let’s talk about applications and then we can look at one of the state predictions, in this case I think we will look at my infected prediction.

Predicting the next week for the cumulative infected population. This is easy to check that it is correct becuase the CDC specifically lists cases cumulatively.
Right now you are looking at a prediction for a week ahead, but TECHNICALLY this is two weeks. The model hasn’t seen the last week of measurements so it doesn’t know those values. This is a good way to verify that my model is correct, furthermore this model was designed from the start to only predict a week or two ahead and it looks like it does that fairly accurately. Now this is cumulative so it LOOKS better than if we were to view the day to day rate change, which we can because I calculated that as well!

Here we have my infected from the recovered population, which I calculate from the measured number of deaths. The measured infected (Purple) is more random than the prediction, but if we look at the graph above you can see that it totals pretty nicely. In this image, we are only predicting 1 week ahead, not two. IE- The model hasn’t seen the last week of data. I also have a susceptible -> infected prediction, but that isn’t as good because that is purely synthetic without any real measurement to create it, however it was a good check for several other classes and gave another prediction in a very random system
As we can see, the day to day prediction does not follow the measurement as nicely as the cumulative prediction does, but that is because the numbers for the cumulative prediction are so much larger so the error looks a lot smaller. Here it is more apparent, but overall it does a good job of following the trend and making a prediction. This was before I made my two week prediction, so this is “just” a week ahead so I could validate my model before I tried to look further ahead.
The cumulative graph and the rate graph both use data from 5 days ago, so I should be able to further verify my model by adding in the rest of the newly collected measurements, which is the plan for today and will be easy to do. Now, the disclaimer yet again. All models are wrong, all of them, EVERY LAST MODEL IS WRONG. That’s just how it is, a prediction is a guess based on past values, but the system we are modeling is infinitely complex and we need to make a LOT of simplifying assumptions to get even a crude model, like the one I’m showing here.
Some models are dangerous, those are the models without the disclaimers or the ones that people pretend are the final word on the matter. The purpose of my model was first and foremost to learn, that is it. However, I designed it with the express purpose for use in predicting a week or two ahead so that hospitals could better prepare. That is it, I COULD predict months ahead like others are doing, but I do not want that and I don’t think it is useful in the sense that it is more of a educated guess than anything and there is so much variability it is almost not helpful.
In this case, being able to predict a week or two ahead gives hospitals the chance to make the required arrangements, get equipment, and plan for what to do next. It is my opinion that this is infinitely more important than trying to let the general public know when this MAY end. The truth of the matter is this will not end, not until the vaccine is tested and used in >90% of the population, then and only then will this be over. Until then, the best we can do is plan for the week ahead and hope that it isn’t as bad as the week before.
With that, I have a video I’m working on further explaining my model so expect to see that in the upcoming day or two. I think overall these few posts do a good job introducing the idea of a model and how hard it is to get right. I don’t like diving into the math behind something like this, but I will probably do that, plus my class is most likely going to be sharing my code, so you will all most likely get the chance to play with my model should you want to.
But enough about us, what about you?