# I need help with ODE in a probabilistic model

Using this data influ.csv (287 Bytes) I’m trying to fit a SIR model.

``````import pymc3 as pm
from pymc3.ode import DifferentialEquation
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
import arviz as az
import pandas as pd

import pandas as pd
df['in_bed']

def SIR(y, t, p):
S = y
I = y
R = y

beta = p
gamma = p

ds = -beta*I*S/N
di = beta*I*S/N-gamma*I
dr = gamma*I

return [ds, di, dr]

N = 763
i0 = 1
R0 = 0
y0 = [N - i0, i0, R0]
t0 = 0
ts = np.arange(1,15,1)

sir_model = DifferentialEquation(
func=SIR,
times=ts,
n_states=3,
n_theta=2,
t0=t0,
)

with pm.Model() as model:
y = pm.Data("y", df["in_bed"])

beta = pm.Bound(pm.Normal, lower=0.0)('beta', mu=2, sigma=1)
gamma = pm.Bound(pm.Normal, lower=0.0)('gamma', mu=0.4, sigma=0.5)
phi_inv = pm.Exponential("phi_inv", lam=5)

R0 = pm.Deterministic('R0', beta / gamma)
phi = pm.Deterministic('phi', 1. / phi_inv)

sir_curves = sir_model(y0=y0, theta=[beta, gamma])

Y = pm.NegativeBinomial('Y', mu=sir_curves[:,1], alpha=phi, observed=y)

with model:
trace = pm.sample(draws=1000, tune=500, step=pm.NUTS(), chains=2, cores=1)
``````

I get the following error message:

``````...\AppData\Roaming\Python\Python37\site-packages\scipy\integrate\odepack.py:247: ODEintWarning: Illegal input detected (internal error). Run with full_output = 1 to get quantitative information.
warnings.warn(warning_msg, ODEintWarning)
Sampling 1 chain for 6 tune and 0 draw iterations (6 + 0 draws total) took 24 seconds.``````