# How to calibrate age-structured SIR model on mono-dimensional data?

**URL:** <https://discourse.julialang.org/t/how-to-calibrate-age-structured-sir-model-on-mono-dimensional-data/49532>\
**Category:** Modelling & Simulations\
**Tags:** question, diffeq, bayesian-inference\
**Created:** [November 3, 2020, 3:11pm UTC](https://discourse.julialang.org/t/how-to-calibrate-age-structured-sir-model-on-mono-dimensional-data/49532 "2020-11-03T15:11:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PietroMonticone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pietromonticone/32/44881_2.png) [@PietroMonticone](https://discourse.julialang.org/u/PietroMonticone)\
**Post date:** [November 3, 2020, 3:11pm UTC](https://discourse.julialang.org/t/how-to-calibrate-age-structured-sir-model-on-mono-dimensional-data/49532/1 "2020-11-03T15:11:30Z")

</div>

Consider the following age-structured SIR model I’ve written in the DifferentialEquations.jl framework:

```julia
# Import 
using DifferentialEquations, DiffEqBayes

# Model parameters
β = [0.1, 0.2, 0.3]
γ = 0.15
𝒫 = vcat([β, γ]...)

# Initial conditions
S₀ = [0.99,0.99,0.99]
I₀ = [0.01,0.01,0.01]
R₀ = [0.0,0.0,0.0]
ℬ = [S₀ I₀ R₀] 

# Time 
𝒯 = (0.0,100);    

# Model
function Φ!(du,u,p,t)
    m = size(u,1)
    β = @view p[1:m]
    γ = p[m+1]
    
    S = @view u[:,1]
    I = @view u[:,2]
    R = @view u[:,3]
    
    dS = @view du[:,1]
    dI = @view du[:,2]
    dR = @view du[:,3]
    
    @. dS = -β*S*I
    @. dI = β*S*I-γ*I
    @. dR = γ*I
end

# Problem Definition
problem = ODEProblem(Φ!, ℬ, 𝒯, 𝒫)

# Problem Solution
solution = solve(problem);

```

I need to calibrate the model with age-aggregated data for the recovered compartment using the ABC rejection method via the interface provided by the `DiffEqBayes.jl` package. I was thinking about something along the lines of

```julia
# Observation times
t = collect(1.:100.)   

# Priors array
priors = [Normal(1.5, 1),Normal(1.5, 1),Normal(1.5, 1),Normal(1.5, 1)]
results= abc_inference(problem, Tsit5(), t, R_real_data, priors)

```

How can I run the ABC method on only one of the dimensions of solution object (i.p. distance between simulated age-aggregated R data vs. real age-aggregated R data)?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 3, 2020, 6:56pm UTC](https://discourse.julialang.org/t/how-to-calibrate-age-structured-sir-model-on-mono-dimensional-data/49532/2 "2020-11-03T18:56:59Z")

</div>

> [@PietroMonticone](#):
>
> How can I run the ABC method on only one of the dimensions of solution object (i.p. distance between simulated age-aggregated R data vs. real age-aggregated R data)?

Use `save_idxs` on the ODE integrator so that it only saves that values you want to compare. For example:

```julia
results= abc_inference(problem, Tsit5(), t, R_real_data, priors,save_idxs=[1,2])

```

will pass that down to the integrator and thus it will only output a timeseries of the first two states of the ODE, and thus only use those to compare to the underlying data.
