{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## A Live [SEIR](https://en.wikipedia.org/wiki/Compartmental_models_in_epidemiology#The_SEIR_model) Model for Covid-19 with Error Bars in Julia\n", "\n", "#### Author: Dan Segal (@[djsegal](https://github.com/djsegal/))\n", "\n", "as requested by Prof. Alan Edelman, MIT\n", "\n", "----\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "using Measurements\n", "\n", "param_error = 0.05\n", "\n", "α = 0.2 ± param_error\n", "γ = 0.5 ± param_error\n", "\n", "# β = f(social distancing, masks, etc.)\n", "\n", "E₀ = 1e-4\n", "u₀ = [ 1 - E₀ ; E₀ ; 0 ; 0 ]\n", "\n", "tspan = (0.0, 200.0); # 200 days\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "using DifferentialEquations\n", "\n", "function seir!(du,u,p,t)\n", " S,E,I,_ = u\n", " α,β,γ = p\n", "\n", " dS = ( -β*I*S )\n", " dE = ( +β*I*S ) - α*E\n", " dI = ( -γ*I ) + α*E\n", " dR = ( +γ*I )\n", "\n", " du .= (dS, dE, dI, dR)\n", "end\n", "\n", "labels = [\n", " \"Susceptible\", \"Exposed\", \n", " \"Infected\", \"Recovered\"\n", "];\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ " \n" ], "text/plain": [ "HTML{String}(\" \\n\")" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
(social distancing, immunity, vaccines reduce β)
\n" ], "text/plain": [ "HTML{String}(\"(social distancing, immunity, vaccines reduce β)
\\n\")" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "(social distancing, immunity, vaccines reduce β)
\n", "\"\"\")\n", "\n", "beta_slider = slider(0.25:0.25:2, value=1, label=\"β\") \n", "\n", "@demo for β in beta_slider\n", " title!(\"Covid-19 SEIR Model with Error Bars\") ;\n", " xlabel!(\"Time (Days)\") ; ylabel!(\"%\") \n", " \n", " soln = solve(ODEProblem(\n", " seir!, u₀, tspan, [α, β ± param_error, γ]\n", " ), saveat=0.5)\n", " \n", " x, y = soln.t, 100*Array(soln)\n", " ylims!(0, 100) # using percentages\n", " \n", " for (index, label) in enumerate(labels)\n", " plot!(\n", " x, y[index,:], label=label, \n", " alpha=0.8, fillalpha=0.1\n", " )\n", " end\n", "end\n" ] } ], "metadata": { "@webio": { "lastCommId": null, "lastKernelId": null }, "kernelspec": { "display_name": "Julia 1.4.0", "language": "julia", "name": "julia-1.4" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.4.0" } }, "nbformat": 4, "nbformat_minor": 4 }