renewal model time series example for User's Guide
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
- issue の種類
- ドキュメント
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
まず User's Guide の構成と、issue に含まれている Stan モデルおよび CmdStanPy シミュレータを確認します。シミュレーションコードと引用されている Fraser および Steyn の参考文献を含む renewal model の例を追加し、その後、例がガイドの適切なセクションに配置され、リンクとコードが使用可能であることを確認します。
索引モデルが issue の本文から書いたものです。
説明
We should include a renewal model---they're popular for tracking infectious diseases. Here's the basic model with Stan code and CmdStanPy simulation.
functions {
real random_walk_lpdf(vector y, real sigma, real mu0, real sigma0) {
int N = rows(y);
return normal_lpdf(y[1] | mu0, sigma0)
+ normal_lpdf(y[2:N] | y[1:N - 1], sigma);
}
}
data {
int<lower=0> T, U;
simplex[U] omega;
array[T] int<lower=0> C;
real mu0;
real<lower=0> sigma0;
}
transformed data {
row_vector<lower=0>[T] Cv = to_row_vector(C);
}
parameters {
vector<lower=0>[T] R;
real<lower=0> sigma;
}
model {
// C[1] not modeled
for (t in 2:U) {
// shorten history with renormalized simplex
C[t] ~ poisson(R[t] * (Cv[1:t-1] * omega[1:t-1]) / sum(omega[1:t-1]));
}
for (t in U + 1:T) {
C[t] ~ poisson(R[t] * (Cv[t-U:t-1] * omega));
}
sigma ~ lognormal(0, 0.25);
R ~ random_walk(sigma, mu0, sigma0);
}
And here's the simulator.
import numpy as np
import cmdstanpy as csp
def simulate_renewal_data(
T: int = 150,
U: int = 5,
seed: int = 2020,
):
rng = np.random.default_rng(seed)
alpha = np.arange(U, 0, -1, dtype=float)
omega = alpha / sum(alpha)
mu0 = 1.0
sigma0 = 0.05
sigma = 0.025
R = np.empty(T)
R[0] = abs(rng.normal(mu0, sigma0))
for t in range(1, T):
R[t] = abs(rng.normal(R[t - 1], sigma))
C = np.zeros(T, dtype=int)
C[0] = 1000
for t in range(1, U):
lam = R[t] * np.dot(C[0:t], omega[0:t] / sum(omega[0:t]))
C[t] = rng.poisson(lam)
for t in range(U, T):
lam = R[t] * np.dot(C[t-U:t], omega)
C[t] = rng.poisson(lam)
return {
"T": T,
"U": U,
"omega": omega,
"C": C,
"R": R,
"sigma": sigma,
"mu0": mu0,
"sigma0": sigma0,
"alpha": alpha,
}
sim = simulate_renewal_data()
print("alpha: ")
print(np.round(sim["alpha"], 3))
print("\nomega: ")
print(np.round(sim["omega"], 3))
print("\nsigma: ", sim["sigma"])
print("\nR: ")
print(np.round(sim["R"], 3))
print("\nC: ")
print(sim["C"])
model = csp.CmdStanModel(stan_file="poisson.stan")
fit = model.sample(data=sim)
print(fit.summary())
The model is taken from Steyn et al. (2025), Model 1 (section 6.1), which also introduces overdispersed alternatives (negative binomial instead of Poisson), latent infectiousness states, day-of-week effects, etc. They cite Fraser (2007) as the source of the basic model.
@article{steyn2025primer,
title={A primer on inference and prediction with epidemic renewal models and sequential {M}onte {C}arlo},
author={Steyn, Nicholas and Parag, Kris V and Thompson, Robin N and Donnelly, Christl A},
journal={Statistics in Medicine},
volume={44},
number={18-19},
pages={e70204},
year={2025}
}
@article{fraser2007estimating,
title={Estimating individual and household reproduction numbers in an emerging epidemic},
author={Fraser, Christophe},
journal={PloS one},
volume={2},
number={8},
pages={e758},
year={2007}
}
Here are links to the papers:
- 主要言語
- TeX
- スター
- 43
- フォーク
- 133
- 平均マージ
- 11時間 32分
- マージ済み PR(30日)
- 4
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
stan-dev/docs のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
bug
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
inu-appcenter/memorIN-frontend#106 ·
メンテナーはふだん 1 日以内に返信
-
workflow: a tick's dispatch counts as 'only this step', and no review self-grants a round unattendedオープンworkflow
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
kristofdegrave/homeassistant-smart-charging#1505 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
openfoodfacts/score-my-recipe#80 ·
メンテナーはふだん 2 日以内に返信
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
githubnext/gh-aw-workshop#3968 ·
メンテナーはふだん 1 日以内に返信