Showing posts with label matlab. Show all posts
Showing posts with label matlab. Show all posts

Thursday, December 31, 2020

Fitting an SIR Model to COVID-19 Data

LabKitty Mad Scientist logo
The US has one of the highest COVID-19 per capita infection rates in the world. Many factors have contributed to this unfortunate honor, including the Trump administration's bungled response to the pandemic, the Trump administration's bungled response to the pandemic, and also the Trump administration's bungled response to the pandemic. I'm here reminded of Richard Clarke's testimony at the 9/11 commission which he opened with an apology: Your government failed you. Those entrusted with protecting you failed you. I failed you. I suspect we'll get no such apology from The Donald.

The good news -- if we can call it that -- is because of Trump's stunning malfeasance, the humble SIR model is a better description of the COVID pandemic than it otherwise would be. Intervention complicates disease dynamics, adding terms to the equations and expanding the search space of parameters we need to fit. In the absence of a public health response, we're left with only three classifications -- susceptible (S), infected (I), and removed (R) -- and two parameters -- the transmission (β) and recovery (γ) rates -- which describe both our model and our fate.

Additionally, the longer COVID drags on the more data we have to test. Of course, none of the numbers can be trusted as long as Trump lackeys have opportunity to spike the CDC spreadsheets. Videre quam esse, and all that. However, that, too, can be good thing, for it allows us to check if model parameters match what healthcare workers are reporting from the trenches. Any discrepancy indicates malarkey may be afoot, kinda like how Neptune was discovered by analyzing the discrepancies of Uranus.

So, let's fire up Matlab and fit a COVID model. We're all sequestered at home this happy holiday, so what else is there to do?

Tuesday, November 7, 2017

A Primer on Fourier Analysis -- Part II

LabKitty Academy Greal Seal
A LabKitty Primer is an introduction to some technical topic I am smitten with. They differ from most primers as to the degree of mathematical blasphemy on display. I gloss over details aplenty and mostly work only the simplest cases. I show mistakes and dead ends and things any normal person would try that don't work. Also, there's probably a swear word or two. Mostly I want to get you, too, excited about the topic, perhaps enough to get you motivated to learn it properly. And, just maybe, my little irreverent introduction might help you understand a more sober treatment when the time comes.

Previously on A LabKitty Primer on Fourier Analysis, we met the beast and poked it with a stick. We discovered -- glossing over the hard stuff that made Fourier famous -- a Fourier transform is just a fancy way of correlating sines and cosines with a given signal of interest.

That simple worldview works conceptually, but now we're going to look at how the pros do things. As I stated in Part I, my goal is to get you to understand the numbers Matlab's fft( ) function returns, and so we shall. We're still decomposing a signal into its frequency components. Nothing new there. However, Matlab is top-shelf engineering software and not just some lunatic ranting on the Internet. As such, there's a rash of new details we must encompass and eclipse. Some of those new details are unpleasant.

Yes, our tale today is long and fairly horrible. The good news is you have a sagacious and sympathetic guide, one who asks only for your patience and tolerance of occasional stilted prose (but would it kill you to purchase some swag from the LabKitty store in return for all of this free learning goodness? Answer: No, it would not). Still, if you wish to proceed, the gloves must come off. LabKitty degloved, we might say, which is an adjective I advise you do not Google.

It's like grandpap LabKitty used to say: Lace up your mukluks children, 'cause we're goin' to the slaughterhouse.

Let's press on.

Friday, March 4, 2016

Polling -- How do it Know?

LabKitty Academy Greal Seal
Because we are currently living in the Season of the Bitch an election year, you can't swing a dead cat* without hitting a prediction of some sort. These predictions usually come in the form of a poll, or at least the respectable ones do (my Uncle Randall predicting Obama is going to cancel the election so lizard people can extract our vital juices is a different kind of prediction). For example, a recent poll on the CNN website claims Hillary Clinton and Bernie Sanders are tied in the lead-up to the Nevada primaries. Overall, 48% of likely caucus attendees say they support Clinton, 47% Sanders... the article reads (Source: CNN Digital Dashboard 2/17/2016). However, further down the page we find this:
The CNN/ORC Nevada Poll was conducted by telephone February 10-15 among a random sample of 1,006 adult residents of the state. Results among the 245 likely Republican caucusgoers [sic] have a margin of sampling error of plus or minus 6.5 percentage points. For results among the 282 likely Democratic primary voters, it is plus or minus 6 percentage points.
Such a caveat should give any thinking person pause. How can you possibly predict the behavior of millions of voters with just 1,006 phone calls? Isn't this just guesswork? (short answer: No, with a but). Can the result be totally wrong? (short answer: Yes, with a however). What is this voodoo? And what the heck is a margin of sampling error?

Put such questions to a mathozoid, and they will drone on about the null hypothesis and Type-I error and confidence intervals and the standard deviation.

Ask LabKitty and you will get enlightenment.

So, ask away.

Thursday, December 10, 2015

A Primer on Fourier Analysis -- Part I

LabKitty Great Seal
A LabKitty Primer is an introduction to some technical topic I am smitten with. They differ from most primers as to the degree of mathematical blasphemy on display. I gloss over details aplenty and mostly work only the simplest cases. I'll show mistakes and dead ends and things any normal person would try that don't work. Mostly I want to get you, too, excited about the topic, perhaps enough to get you motivated to learn it properly. And, just maybe, my little irreverent introduction might help you understand a more sober treatment when the time comes.

The Fourier transform doesn't only transform data, it transformed civilization. In the guise of the FFT, it created a digital signal processing revolution that took the technique out of the classroom and into everything from GPS to Roombas. It is a staple of STEM education, and for good reason: There is almost no field, no application, no problem that does not yield to or benefit from application of Fourier analysis. If aliens have a Wiki on Earthlings, Fourier and those blankets you can wear may well be the sole entries.

That being said, Fourier analysis can be intimidating to the newcomer. The material has a fierce reputation, often taught as some holy relic impenetrable as death. That's where LabKitty comes in. Yes, there is much about Fourier analysis that only time and dedicated study can unravel. But the basic idea is surprisingly straightforward. And if there's anything textbook authors hate, it's admitting something is straightforward.

Monday, July 20, 2015

Let's make a Mandelbrot set!

LabKitty Academy Greal Seal
LabKitty has a dream. I dream one day all of quantum mechanics, with its hateful partial differential equations and infinite dimensional matrices and renormalizable gauge theory and whatnot, will be replaced by simple mathematics even a child can understand. Perhaps somewhere it already has. This very day, an alien physicist may well be flippering through Wikipedia and snickering.

Feynman diagrams
!, s/he snorts derisively. The puny Earthmeats have yet to discover the true path.

The secret of the Old One, as Einstein put it.

Wednesday, October 22, 2014

A Primer on Mathematical Epidemiology

LabKitty Great Seal
A LabKitty Primer is an introduction to some technical topic I am smitten with. They differ from most primers as to the degree of mathematical blasphemy on display. I gloss over details aplenty and mostly work only the simplest cases. I show mistakes and dead ends and things any normal person would try that don't work. Mostly I want to get you, too, excited about the topic, perhaps enough to get you motivated to learn it properly. And, just maybe, my little irreverent introduction might help you understand a more sober treatment when the time comes.

Note for the confused: This Primer makes reference to events from the recent (2015) Ebola outbreak, which featured some arguably questionable decisions on the part of various healthcare professionals. FYI.

Now that we're all going to die in a global apocalyptic Ebola apocalypse, it's a good time to learn some epidemiology. This will soon be all over the "for your health" segment of the news, so you best get yourself prepared. When survivors have devolved into samizdat armed camps, you'll need something to make yourself useful to the local pod of crazies. Demonstrating facility with this material could be your golden ticket to an MRE and a place in the repopulation efforts.

The bad news is it's differential equations. The good news is it's epidemiology differential equations, and if recent actions of the CDC are any indication, plenty of knuckleheads understand epidemiology. Or don't understand epidemiology, at least the "keep the infected from flying coach" portion of the program. Although, to be fair to the CDC, perhaps the larger problem here is common sense. Apparently we're no longer covering the germ theory of disease in our nursing schools.

As always, I blame the hip hop.

Wednesday, April 9, 2014

The Magic Coin Game

Weirdness abounds in probability (and I mean the kind of probability that can be understood by regular folk, not the kind that involves things like measure theory. That kind of probability also contains weirdness, but it is only understood by mathozoids who I imagine use some sort of proboscis to acquire nutrients when the rest of us aren't looking).

Perhaps the most famous of all probability weirdness is the Monty Hall problem, named after the eponymous host of the '70s game show in which it appeared. Briefly: you are shown three doors. Behind one door is a good thing (a car, money, Claire Danes' underpants). Behind the other two doors are bad things (a goat, a beating, Hitler's underpants). You pick one of the three doors. Monty shows what's behind one of the doors you didn't pick. You must decide to stick with your original selection or switch to the door Monty didn't show you. Monty then opens your door and shows you what you have won.

The famous result is that switching improves your chance of getting the good thing. That seems redonkulous, but careful analysis shows it to be true.

Explanations of the Monty Hall problem have turned up everywhere from AskReddit to Parade Magazine. If you are holding a probability textbook (and why wouldn't you be?) it's probably mentioned in it somewhere. I won't discuss the solution here (see: the Google avalanche returned by searching on "monty hall problem"). Rather, the MHP got me thinking about other odd fish that lurk in the dark sea called probability. Other weirdnesses proffered by Lady Luck, her strapless evening gown and feminine jowels calling us forth, seeking to separate us from nous and paycheck.

I am fortune's fool! Romeo exclaimed. Yes you are, Mr. DiCapricorn. And you better keep your paws off Claire or there's going to be trouble.

I call this weirdness: The Magic Coin Game.

Friday, April 4, 2014

Let's make a bifurcation diagram!

Here is the discrete logistic equation:

N(n+1) = N(n) + r N(n) [ 1 - N(n) / K ]

Here is the bifurcation diagram of the discrete logistic equation:

bifurcation diagram for the discrete logistic equation

Question: how do we get the latter from the former?

It is here that the mathozoids begin to titter on about Lyapunov exponents and Dulac criterions and Poincare-Bendixson theorems and eigenvalue linearizations and whatnot. Bist du allein klug?* Because for someone trying to get their head around the bifurcation diagram for the first time? NOT HELPFUL.

And, yes, I know there's supposed to be a soupcon on the end of "Poincare."

I'm omitting it to demonstrate my contempt.