Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 408: ARMA and ARIMA models #438

Merged
merged 54 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d4172aa
draft MA method
seabbs Jul 29, 2024
d0fd36d
draft MA methd
seabbs Jul 29, 2024
34b743f
use IDD for epsilon in all models
seabbs Aug 2, 2024
e8c4cbb
add MA benchmark
seabbs Aug 16, 2024
7c1828a
Add docs and tests for IDD
seabbs Aug 16, 2024
24ebd74
make episilon_t a arg of the latent model constructors
seabbs Aug 16, 2024
6a9905f
improve MA correctness
seabbs Aug 16, 2024
150fddb
fully import EpiAwareUtils
seabbs Aug 16, 2024
6a5c2aa
add a test for IDD
seabbs Aug 16, 2024
5cba2fa
add tests for MA.jl
seabbs Aug 16, 2024
c7812c1
add doc tests and unit tests + start on helper fn
seabbs Aug 16, 2024
db2a5cf
more updatres to AR appraoc
seabbs Oct 10, 2024
0c49fd0
chase down partial arg changes
seabbs Oct 11, 2024
9f09ace
clean up AR
seabbs Oct 11, 2024
07dd19f
clean up and add arma and arima helpers
seabbs Oct 11, 2024
d442dd5
Merge branch 'main' into issue408
seabbs Oct 24, 2024
54693fc
Merge branch 'main' into issue408
seabbs Oct 24, 2024
6facd62
Contributions towards Arma/Arima models (#531)
SamuelBrand1 Dec 5, 2024
4a83ba7
Merge branch 'main' into issue408
seabbs Dec 5, 2024
0b5f73e
revert define_ namming
seabbs Dec 5, 2024
8d5988a
clean out repeated utils from merge
seabbs Dec 6, 2024
f83ee0a
fix MA tests
seabbs Dec 6, 2024
18f90e9
fix RW tests - feel made about RandomWalk vs AR naming
seabbs Dec 6, 2024
7cb92ba
fix remaining unit tests that aren't doctests
seabbs Dec 6, 2024
9817d30
update latent recovery test
seabbs Dec 6, 2024
2c5e02f
try and fix doctests automatically
seabbs Dec 9, 2024
96a3862
Merge branch 'main' into issue408
seabbs Dec 9, 2024
6168013
update all doctests to output nothing - this is awful
seabbs Dec 9, 2024
4b4e7e6
add doctests for arima and arma
seabbs Dec 9, 2024
3b9653b
fix doctest
seabbs Dec 9, 2024
4e48992
clean up deps
seabbs Dec 9, 2024
c2f65d6
update replication studies
seabbs Dec 9, 2024
836522c
add interface tests for combination functions and add benchmarks
seabbs Dec 9, 2024
d1c780a
add some basic theoretical properties tests
seabbs Dec 9, 2024
82b7aab
Merge branch 'main' into issue408
seabbs Dec 9, 2024
9559c59
name change IDD -> IID benchmarks
seabbs Dec 9, 2024
bf4f53f
moving all the constructors because this PR is too contained
seabbs Dec 9, 2024
6c457e7
catch missing using
seabbs Dec 9, 2024
993c136
update iid benchmark:
seabbs Dec 9, 2024
c749cd4
update extraction
seabbs Dec 9, 2024
42622f3
remove old param namme from case study
seabbs Dec 9, 2024
0d5eed6
Merge branch 'main' into issue408
seabbs Dec 9, 2024
cd5c161
get the dot
seabbs Dec 10, 2024
fd0101f
get the dot
seabbs Dec 10, 2024
6d91f79
fix initial guess point for MAP opt
SamuelBrand1 Dec 10, 2024
4b97615
Update index.jl
seabbs Dec 10, 2024
3d4d8f9
add a compile time branch for HN
seabbs Dec 10, 2024
2de9584
add a compile time branch for HN
seabbs Dec 10, 2024
2be792b
update test
seabbs Dec 10, 2024
d4023db
add a new constructor to get old default behaviour
seabbs Dec 10, 2024
fdecd83
update docs
seabbs Dec 10, 2024
c6b3e98
update docs - using the structs for priors is very brittle
seabbs Dec 10, 2024
651bd02
reorder prior plots
SamuelBrand1 Dec 10, 2024
bb2b774
Merge branch 'issue408' of https://github.com/CDCgov/Rt-without-renew…
SamuelBrand1 Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions EpiAware/docs/src/showcase/replications/chatzilena-2019/index.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### A Pluto.jl notebook ###
# v0.20.0
# v0.20.3

using Markdown
using InteractiveUtils
Expand Down Expand Up @@ -428,8 +428,8 @@ We define the AR(1) process by matching means of `HalfNormal` prior distribution
# ╔═╡ 71a26408-1c26-46cf-bc72-c6ba528dfadd
ar = AR(
damp_priors = [HalfNormal(mean(sampled_AR_damps))],
std_prior = HalfNormal(mean(sampled_AR_stds)),
init_priors = [Normal(0, 0.001)]
init_priors = [Normal(0, 0.001)],
ϵ_t = HierarchicalNormal(std_prior = HalfNormal(mean(sampled_AR_stds)))
)

# ╔═╡ e1ffdaf6-ca2e-405d-8355-0d8848d005b0
Expand Down Expand Up @@ -578,9 +578,10 @@ rand(stochastic_mdl)
initial_guess = [[mean(chn[:β]),
mean(chn[:γ]),
mean(chn[:S₀]),
mean(ar.std_prior),
mean(ar.init_prior)[1],
mean(ar.damp_prior)[1]]
mean(ar.damp_prior)[1],
mean(ar.ϵ_t.std_prior)
]
zeros(13)]

# ╔═╡ 685221ea-f268-4ddc-937f-e7620d065c28
Expand Down Expand Up @@ -611,7 +612,7 @@ chn2 = sample(
describe(chn2)

# ╔═╡ 37a016d8-8384-41c9-abdd-23e88b1f988d
pairplot(chn2[[:β, :γ, :S₀, Symbol(mdl_prefix * ".σ_AR"),
pairplot(chn2[[:β, :γ, :S₀, Symbol(mdl_prefix * ".std"),
Symbol(mdl_prefix * ".ar_init[1]"), Symbol(mdl_prefix * ".damp_AR[1]")]])

# ╔═╡ 7df5d669-d3a2-4a66-83c3-f8618e39bec6
Expand Down
20 changes: 10 additions & 10 deletions EpiAware/docs/src/showcase/replications/mishra-2020/index.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### A Pluto.jl notebook ###
# v0.20.0
# v0.20.3

using Markdown
using InteractiveUtils
Expand Down Expand Up @@ -114,10 +114,10 @@ In _Mishra et al_ the standard deviation of the _stationary distribution_ of $Z_

# ╔═╡ c88bbbd6-0101-4c04-97c9-c5887ef23999
ar = AR(
damp_priors = reverse([truncated(Normal(0.8, 0.05), 0, 1),
truncated(Normal(0.1, 0.05), 0, 1)]),
std_prior = HalfNormal(0.5),
init_priors = [Normal(-1.0, 0.1), Normal(-1.0, 0.5)]
damp_priors = [truncated(Normal(0.1, 0.05), 0, 1),
truncated(Normal(0.8, 0.05), 0, 1)],
init_priors = [Normal(-1.0, 0.1), Normal(-1.0, 0.5)],
ϵ_t = HierarchicalNormal(std_prior = HalfNormal(0.5))
)

# ╔═╡ 31ee2757-0409-45df-b193-60c552797a3d
Expand Down Expand Up @@ -561,11 +561,11 @@ let
sub_chn = inference_results.samples[inference_results.samples.name_map.parameters[[1:5;
end]]]
fig = pairplot(sub_chn)
lines!(fig[1, 1], ar.std_prior, label = "Prior")
lines!(fig[2, 2], ar.init_prior.v[1], label = "Prior")
lines!(fig[3, 3], ar.init_prior.v[2], label = "Prior")
lines!(fig[4, 4], ar.damp_prior.v[1], label = "Prior")
lines!(fig[5, 5], ar.damp_prior.v[2], label = "Prior")
lines!(fig[1, 1], ar.init_prior.v[1], label = "Prior")
lines!(fig[2, 2], ar.init_prior.v[2], label = "Prior")
lines!(fig[3, 3], ar.damp_prior.v[1], label = "Prior")
lines!(fig[4, 4], ar.damp_prior.v[2], label = "Prior")
lines!(fig[5, 5], ar.ϵ_t.std_prior, label = "Prior")
lines!(fig[6, 6], epi.initialisation_prior, label = "Prior")

fig
Expand Down
43 changes: 28 additions & 15 deletions EpiAware/src/EpiAwareUtils/HalfNormal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,62 @@ Create a half-normal prior distribution with the specified mean.

# Examples:

```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
using EpiAware, Distributions

hn = HalfNormal(1.0)
nothing

# output
EpiAware.EpiAwareUtils.HalfNormal{Float64}(μ=1.0)

```

# filter out all the values that are less than 0
```jldoctest HalfNormal; filter = r\"\b\d+(\.\d+)?\b\" => \"*\"
```jldoctest HalfNormal; output = false
rand(hn)
nothing

# output
0.4508533245229199

```

```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
cdf(hn, 2)
nothing

# output
0.8894596502772643

```

```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
quantile(hn, 0.5)
nothing

# output
0.8453475393951495

```

```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
logpdf(hn, 2)
nothing

# output
-3.1111166111445083

```

```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
mean(hn)
nothing

# output
1.0

```

```jldoctest HalfNormal
```jldoctest HalfNormal; output = false
var(hn)
nothing

# output
0.5707963267948966

```
"
struct HalfNormal{T <: Real} <: ContinuousUnivariateDistribution
Expand Down
30 changes: 20 additions & 10 deletions EpiAware/src/EpiAwareUtils/SafeNegativeBinomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ parameterisation is useful for specifying the distribution in a way that is easi

# Examples:

```jldoctest SafeNegativeBinomial
```jldoctest SafeNegativeBinomial; output = false
using EpiAware, Distributions

bigμ = exp(48.0) #Large value of μ
Expand All @@ -37,32 +37,42 @@ bigμ = exp(48.0) #Large value of μ
p = bigμ / σ²
r = bigμ * p / (1 - p)
d = SafeNegativeBinomial(r, p)
nothing

# output
EpiAware.EpiAwareUtils.SafeNegativeBinomial{Float64}(r=20.0, p=2.85032816548187e-20)

```

```jldoctest SafeNegativeBinomial
```jldoctest SafeNegativeBinomial; output = false
cdf(d, 100)
nothing

# output
0.0

```

```jldoctest SafeNegativeBinomial
```jldoctest SafeNegativeBinomial; output = false
logpdf(d, 100)
nothing

# output
-850.1397180331871

```

```jldoctest SafeNegativeBinomial
```jldoctest SafeNegativeBinomial; output = false
mean(d)
nothing

# output
7.016735912097631e20

```

```jldoctest SafeNegativeBinomial
```jldoctest SafeNegativeBinomial; output = false
var(d)
nothing

# output
2.4617291430060293e40

```
"
struct SafeNegativeBinomial{T <: Real} <: SafeDiscreteUnivariateDistribution
Expand Down
30 changes: 20 additions & 10 deletions EpiAware/src/EpiAwareUtils/SafePoisson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,47 @@ when the mean is too large.

# Examples:

```jldoctest SafePoisson
```jldoctest SafePoisson; output = false
using EpiAware, Distributions

bigλ = exp(48.0) #Large value of λ
d = SafePoisson(bigλ)
nothing

# output
EpiAware.EpiAwareUtils.SafePoisson{Float64}(λ=7.016735912097631e20)

```

```jldoctest SafePoisson
```jldoctest SafePoisson; output = false
cdf(d, 2)
nothing

# output
0.0

```

```jldoctest SafePoisson
```jldoctest SafePoisson; output = false
logpdf(d, 100)
nothing

# output
-7.016735912097631e20

```

```jldoctest SafePoisson
```jldoctest SafePoisson; output = false
mean(d)
nothing

# output
7.016735912097631e20

```

```jldoctest SafePoisson
```jldoctest SafePoisson; output = false
var(d)
nothing

# output
7.016735912097631e20

```
"
struct SafePoisson{T <: Real} <: SafeDiscreteUnivariateDistribution
Expand Down
55 changes: 12 additions & 43 deletions EpiAware/src/EpiAwareUtils/censored_pmf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,17 @@ Raises:

# Examples

```jldoctest filter
```jldoctest; output = false
using Distributions
using EpiAware.EpiAwareUtils

dist = Exponential(1.0)

censored_pmf(dist, Val(:single_censored); D = 10) |>
p -> round.(p, digits=3)
censored_pmf(dist, Val(:single_censored); D = 10)
nothing

# output
10-element Vector{Float64}:
0.393
0.383
0.141
0.052
0.019
0.007
0.003
0.001
0.0
0.0

```
"
function censored_pmf(dist::Distribution,
Expand Down Expand Up @@ -122,28 +112,17 @@ to nearest multiple of `Δd`.

# Examples

```jldoctest filter
```jldoctest filter; output = false
using Distributions
using EpiAware.EpiAwareUtils

dist = Exponential(1.0)

censored_cdf(dist; D = 10) |>
p -> round.(p, digits=3)
censored_cdf(dist; D = 10)
nothing

# output
11-element Vector{Float64}:
0.0
0.368
0.767
0.914
0.969
0.988
0.996
0.998
0.999
1.0
1.0

```
"
function censored_cdf(dist::Distribution; Δd = 1.0, D = nothing, upper = 0.999)
Expand Down Expand Up @@ -184,27 +163,17 @@ to nearest multiple of `Δd`.

# Examples

```jldoctest filter
```jldoctest filter; output = false
using Distributions
using EpiAware.EpiAwareUtils

dist = Exponential(1.0)

censored_pmf(dist; D = 10) |>
p -> round.(p, digits=3)
censored_pmf(dist; D = 10)
nothing

# output
10-element Vector{Float64}:
0.368
0.4
0.147
0.054
0.02
0.007
0.003
0.001
0.0
0.0

```
"
function censored_pmf(dist::Distribution; Δd = 1.0, D = nothing, upper = 0.99)
Expand Down
Loading
Loading