SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
Dealing with latent
discrete parameters in
Stan
ITÔ, Hiroki
2016-06-04
Tokyo.Stan
Michael Betancourt’s Stan Lecture
About me
• An end user of statistical
software
• Researcher of forest
ecology
• Species composition of
forests
• Forest dynamics
Contents
1. Introduction
• Population Ecology
2. Examples
1. Capture-recapture data and data augmentation
2. Multistate model
Bayesian Population Analysis
using WinBUGS (BPA)
• My colleagues and I translated “Bayesian Population
Analysis using WinBUGS” by M. Kéry and M. Schaub into
Japanese.
• Many practical examples for population ecology
Stan translation of BPA models
https://github.com/stan-dev/example-models/tree/master/BPA
Population ecology
• A subfield of ecology
• Studies of population
• Changes in size (number of individuals) of
animals, plants and other organisms
• Estimation of population size, growth rate,
extinction probability, etc.
Population ecology
• Latent discrete parameters are often used.
• Unobserved status
• Present or absent
• Dead or alive
• But Stan does not support discrete parameters.
• Marginalizing out is required to deal with discrete
parameters.
Example 1
Capture-recapture data and data augmentation
(in Chapter 6 of BPA)
Capture-recapture data
Capture
Release
Recapture
🐞
①
🐞
②
🐞
③
🐞
④
🐞
⑤
🐞
⑥
🐞
⑦
🐞
⑧
🐞
⑨
🐞
①
🐞
③
🐞
④
🐞
⑧
🐞
⑩
🐞
⑪
🐞
⑫
🐞
⑬
Assume closed population: fixed size, no recruitment,
no death, no immigration nor emigration
Data
[,1] [,2] [,3]
[1,] 0 0 1
[2,] 1 1 1
[3,] 1 0 0
[4,] 1 0 1
[5,] 1 0 1
[6,] 1 0 1
:
[85,] 0 1 0
[86,] 0 1 1
[87,] 1 1 0
Individuals
Survey occasions
Estimation
• Population size (total number of individuals
including unobserved)
• Detection (capture) probability
Data augmentation
[,1] [,2] [,3]
[1,] 0 0 1
[2,] 1 1 1
[3,] 1 0 0
[4,] 1 0 1
:
[87,] 1 1 0
[88,] 0 0 0
:
[236,] 0 0 0
[237,] 0 0 0
Add 150
dummy records
Model
BUGS
model {
# Priors
omega ~ dunif(0, 1) # Inclusion probability
p ~ dunif(0, 1) # Detection probability
# Likelihood
for (i in 1:M){
z[i] ~ dbern(omega) # Inclusion indicators
for (j in 1:T) {
y[i, j] ~ dbern(p.eff[i, j])
p.eff[i, j] <- z[i] * p
}
}
# Derived quantities
N <- sum(z[])
}
Stan
data {
int<lower=0> M; // Size of augmented data set
int<lower=0> T; // Number of sampling occasions
int<lower=0,upper=1> y[M, T]; // Capture-history matrix
}
transformed data {
int<lower=0> s[M]; // Totals in each row
int<lower=0> C; // Size of observed data set
C <- 0;
for (i in 1:M) {
s[i] <- sum(y[i]);
if (s[i] > 0)
C <- C + 1;
}
}
parameters {
real<lower=0,upper=1> omega; // Inclusion probability
real<lower=0,upper=1> p; // Detection probability
}
model {
for (i in 1:M) {
real lp[2];
if (s[i] > 0) {
// Included
increment_log_prob(bernoulli_log(1, omega)
+ binomial_log(s[i], T, p));
} else {
// Included
lp[1] <- bernoulli_log(1, omega)
+ binomial_log(0, T, p);
// Not included
lp[2] <- bernoulli_log(0, omega);
increment_log_prob(log_sum_exp(lp));
}
}
}
generated quantities {
int<lower=C> N;
N <- C + binomial_rng(M, omega * pow(1 - p, T));
}
Results
Computing times
OpenBUGS Stan
Number of chains 3 4
Burn-in or warmup +
iterations / chain
500 + 1000 500 + 1000
Computing time (sec) 5.9 5.8
Effective sample size
of p
320 1867
Eff. sample size /
time (sec-1)
54.6 319.5
Environment: 2.8 GHz Xeon W3530, Ubuntu 14.04, No parallell computing.
Compilation time is not included in Stan.
Times were measured using system.time(). The values are mean of 3 measurements.
Data augmentation
Example 2
Multistate model
(in chapter 9 of BPA)
Multistate model
🐞
①
🐞
②
🐞
③
🐞
④
🐞
⑤
🐞⑥
🐞⑦
🐞⑧
🐞⑨
Site A
Site B
Capture
Release
Recapture
🐞①
🐞
②
🐞
⑤
🐞
⑥
🐞⑦
🐞⑫
🐞⑪
Site A
Site B
🐞
⑩
Data
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 3 3 2 3 1
[2,] 1 1 1 1 1 2
[3,] 1 1 1 1 3 3
[4,] 1 3 3 3 3 3
[5,] 1 3 3 3 3 3
[6,] 1 1 2 3 3 3
:
[798,] 3 3 3 3 2 3
[799,] 3 3 3 3 2 3
[800,] 3 3 3 3 2 3
Individuals
Survey occasion
Values
1: seen (captured) at site A, 2: seen (captured) at site B,
3: not seen (not captured)
Estimation
• Survival probability (at site A and B)
• Movement probability (from site A to B and B to A)
• Detection (capture) probability (at site A and B)
State transition
State at time t+1
Site A Site B Dead
Site A φA(1-ψAB) φAψAB 1-φA
State at
time t
Site B φBψBA φB(1-ψBA) 1-φB
Dead 0 0 1
φA: survival probability at site A, φB: survival probability at site B,
ψAB: movement probability from A to B,
ψBA: movement probability from B to A
Observation
Observation at time t
Site A Site B Not seen
Site A pA 0 1-pA
State at
time t
Site B 0 pB 1-pB
Dead 0 0 1
pA: detection probability at site A,
pB: detection probability at site B
Model
BUGS
model {
:
# Define probabilities of state S(t+1) given S(t)
ps[1, 1] <- phiA * (1 - psiAB)
ps[1, 2] <- phiA * psiAB
ps[1, 3] <- 1 - phiA
ps[2, 1] <- phiB * psiBA
ps[2, 2] <- phiB * (1 - psiBA)
ps[2, 3] <- 1 - phiB
ps[3, 1] <- 0
ps[3, 2] <- 0
ps[3, 3] <- 1
# Define probabilities of O(t) given S(t)
po[1, 1] <- pA
po[1, 2] <- 0
po[1, 3] <- 1 - pA
po[2, 1] <- 0
po[2, 2] <- pB
po[2, 3] <- 1 - pB
po[3, 1] <- 0
po[3, 2] <- 0
po[3, 3] <- 1
:
for (i in 1:nind) {
# Define latent state at first capture
z[i, f[i]] <- y[i, f[i]]
for (t in (f[i] + 1):n.occasions) {
# State process
z[i, t] ~ dcat(ps[z[i, t - 1], ])
# Observation process
y[i, t] ~ dcat(po[z[i, t], ])
}
}
f[]: array containing first capture occasion
ps[,]: state transition matrix
po[,]: observation matrix
Stan
Treating as a Hidden Markov model
Site B Site B Site A DeadSite A
Hidden Markov model
State
Observation
Seen at
site A
Dead
Not seen
Seen at
site B
Seen at
site A
Not seen Not seen
model {
real acc[3];
vector[3] gamma[n_occasions];
// See Stan Modeling Language User's Guide and Reference Manual
for (i in 1:nind) {
if (f[i] > 0) {
for (k in 1:3)
gamma[f[i], k] <- (k == y[i, f[i]]);
for (t in (f[i] + 1):n_occasions) {
for (k in 1:3) {
for (j in 1:3)
acc[j] <- gamma[t - 1, j] * ps[j, k]
* po[k, y[i, t]];
gamma[t, k] <- sum(acc);
}
}
increment_log_prob(log(sum(gamma[n_occasions])));
}
}
}
Results
Computing times
OpenBUGS Stan
Number of chains 3 4
Burn-in or warmup +
iterations / chain
500 + 2000 500 + 1000
Computing time (sec) 327.9 193.5
Effective sample size
of pA
140 649
Eff. sample size /
time (sec-1)
0.4 3.4
Environment: 2.8 GHz Xeon W3530, Ubuntu 14.04, No parallell computing.
Compilation time is not included in Stan.
Times were measured using system.time(). The values are mean of 3 measurements.
Binomial-mixture model
(in Chapter 12 of BPA)
Stan code
data {
int<lower=0> R; // Number of sites
int<lower=0> T; // Number of temporal replications
int<lower=0> y[R, T]; // Counts
int<lower=0> K; // Upper bounds of population size
}
model {
:
// Likelihood
for (i in 1:R) {
vector[K+1] lp;
for (n in max_y[i]:K) {
lp[n + 1] <- binomial_log(y[i], n, p)
+ poisson_log(n, lambda);
}
increment_log_prob(log_sum_exp(lp[(max_y[i] + 1):(K + 1)]));
}
:
}
Computing times
OpenBUGS
Stan
(K=100)
Number of chains 3 4
Burn-in or warmup +
iterations / chain
200 + 1000 500 + 1000
Computing time (sec) 25.4 1007.8
Effective sample size
of λ
3000 401
Eff. sample size /
time (sec-1)
118.3 0.4
Environment: 2.8 GHz Xeon W3530, Ubuntu 14.04, No parallell computing.
Compilation time is not included in Stan.
Times were measured using system.time(). The values are mean of 3 measurements.
Summary
• Stan can deal with models including discrete
parameters by marginalizing.
• Divide and sum up every cases
• However, the formulation used are less
straightforward.

Más contenido relacionado

La actualidad más candente

Prml3.5 エビデンス近似〜
Prml3.5 エビデンス近似〜Prml3.5 エビデンス近似〜
Prml3.5 エビデンス近似〜Yuki Matsubara
 
Rによるprincomp関数を使わない主成分分析
Rによるprincomp関数を使わない主成分分析Rによるprincomp関数を使わない主成分分析
Rによるprincomp関数を使わない主成分分析wada, kazumi
 
最近のRのランダムフォレストパッケージ -ranger/Rborist-
最近のRのランダムフォレストパッケージ -ranger/Rborist-最近のRのランダムフォレストパッケージ -ranger/Rborist-
最近のRのランダムフォレストパッケージ -ranger/Rborist-Shintaro Fukushima
 
PRML読書会1スライド(公開用)
PRML読書会1スライド(公開用)PRML読書会1スライド(公開用)
PRML読書会1スライド(公開用)tetsuro ito
 
PRML読み会第一章
PRML読み会第一章PRML読み会第一章
PRML読み会第一章Takushi Miki
 
ゼロから作るDeepLearning 2~3章 輪読
ゼロから作るDeepLearning 2~3章 輪読ゼロから作るDeepLearning 2~3章 輪読
ゼロから作るDeepLearning 2~3章 輪読KCS Keio Computer Society
 
グラフィカル Lasso を用いた異常検知
グラフィカル Lasso を用いた異常検知グラフィカル Lasso を用いた異常検知
グラフィカル Lasso を用いた異常検知Yuya Takashina
 
Risk based portfolio with large dynamic covariance matrices
Risk based portfolio with large dynamic covariance matricesRisk based portfolio with large dynamic covariance matrices
Risk based portfolio with large dynamic covariance matricesKei Nakagawa
 
Sparse Codingをなるべく数式を使わず理解する(PCAやICAとの関係)
Sparse Codingをなるべく数式を使わず理解する(PCAやICAとの関係)Sparse Codingをなるべく数式を使わず理解する(PCAやICAとの関係)
Sparse Codingをなるべく数式を使わず理解する(PCAやICAとの関係)Teppei Kurita
 
研究室内PRML勉強会 11章2-4節
研究室内PRML勉強会 11章2-4節研究室内PRML勉強会 11章2-4節
研究室内PRML勉強会 11章2-4節Koji Matsuda
 
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章nocchi_airport
 
負の二項分布について
負の二項分布について負の二項分布について
負の二項分布についてHiroshi Shimizu
 
Stanとdlmによる状態空間モデル
Stanとdlmによる状態空間モデルStanとdlmによる状態空間モデル
Stanとdlmによる状態空間モデルHiroki Itô
 
PCAの最終形態GPLVMの解説
PCAの最終形態GPLVMの解説PCAの最終形態GPLVMの解説
PCAの最終形態GPLVMの解説弘毅 露崎
 
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう 「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう Junpei Tsuji
 
数式をnumpyに落としこむコツ
数式をnumpyに落としこむコツ数式をnumpyに落としこむコツ
数式をnumpyに落としこむコツShuyo Nakatani
 
MCMCでマルチレベルモデル
MCMCでマルチレベルモデルMCMCでマルチレベルモデル
MCMCでマルチレベルモデルHiroshi Shimizu
 
ベイズ統計入門
ベイズ統計入門ベイズ統計入門
ベイズ統計入門Miyoshi Yuya
 
20160311 基礎からのベイズ統計学輪読会第6章 公開ver
20160311 基礎からのベイズ統計学輪読会第6章 公開ver20160311 基礎からのベイズ統計学輪読会第6章 公開ver
20160311 基礎からのベイズ統計学輪読会第6章 公開verTakashi Kitano
 

La actualidad más candente (20)

Prml3.5 エビデンス近似〜
Prml3.5 エビデンス近似〜Prml3.5 エビデンス近似〜
Prml3.5 エビデンス近似〜
 
Rによるprincomp関数を使わない主成分分析
Rによるprincomp関数を使わない主成分分析Rによるprincomp関数を使わない主成分分析
Rによるprincomp関数を使わない主成分分析
 
最近のRのランダムフォレストパッケージ -ranger/Rborist-
最近のRのランダムフォレストパッケージ -ranger/Rborist-最近のRのランダムフォレストパッケージ -ranger/Rborist-
最近のRのランダムフォレストパッケージ -ranger/Rborist-
 
PRML読書会1スライド(公開用)
PRML読書会1スライド(公開用)PRML読書会1スライド(公開用)
PRML読書会1スライド(公開用)
 
PRML読み会第一章
PRML読み会第一章PRML読み会第一章
PRML読み会第一章
 
ゼロから作るDeepLearning 2~3章 輪読
ゼロから作るDeepLearning 2~3章 輪読ゼロから作るDeepLearning 2~3章 輪読
ゼロから作るDeepLearning 2~3章 輪読
 
階層ベイズとWAIC
階層ベイズとWAIC階層ベイズとWAIC
階層ベイズとWAIC
 
グラフィカル Lasso を用いた異常検知
グラフィカル Lasso を用いた異常検知グラフィカル Lasso を用いた異常検知
グラフィカル Lasso を用いた異常検知
 
Risk based portfolio with large dynamic covariance matrices
Risk based portfolio with large dynamic covariance matricesRisk based portfolio with large dynamic covariance matrices
Risk based portfolio with large dynamic covariance matrices
 
Sparse Codingをなるべく数式を使わず理解する(PCAやICAとの関係)
Sparse Codingをなるべく数式を使わず理解する(PCAやICAとの関係)Sparse Codingをなるべく数式を使わず理解する(PCAやICAとの関係)
Sparse Codingをなるべく数式を使わず理解する(PCAやICAとの関係)
 
研究室内PRML勉強会 11章2-4節
研究室内PRML勉強会 11章2-4節研究室内PRML勉強会 11章2-4節
研究室内PRML勉強会 11章2-4節
 
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章
 
負の二項分布について
負の二項分布について負の二項分布について
負の二項分布について
 
Stanとdlmによる状態空間モデル
Stanとdlmによる状態空間モデルStanとdlmによる状態空間モデル
Stanとdlmによる状態空間モデル
 
PCAの最終形態GPLVMの解説
PCAの最終形態GPLVMの解説PCAの最終形態GPLVMの解説
PCAの最終形態GPLVMの解説
 
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう 「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
 
数式をnumpyに落としこむコツ
数式をnumpyに落としこむコツ数式をnumpyに落としこむコツ
数式をnumpyに落としこむコツ
 
MCMCでマルチレベルモデル
MCMCでマルチレベルモデルMCMCでマルチレベルモデル
MCMCでマルチレベルモデル
 
ベイズ統計入門
ベイズ統計入門ベイズ統計入門
ベイズ統計入門
 
20160311 基礎からのベイズ統計学輪読会第6章 公開ver
20160311 基礎からのベイズ統計学輪読会第6章 公開ver20160311 基礎からのベイズ統計学輪読会第6章 公開ver
20160311 基礎からのベイズ統計学輪読会第6章 公開ver
 

Destacado

Replica exchange MCMC
Replica exchange MCMCReplica exchange MCMC
Replica exchange MCMC. .
 
RStanとShinyStanによるベイズ統計モデリング入門
RStanとShinyStanによるベイズ統計モデリング入門RStanとShinyStanによるベイズ統計モデリング入門
RStanとShinyStanによるベイズ統計モデリング入門Masaki Tsuda
 
階層ベイズモデルで割安mobile PCを探す
階層ベイズモデルで割安mobile PCを探す階層ベイズモデルで割安mobile PCを探す
階層ベイズモデルで割安mobile PCを探す. .
 
Satoyama woodland management
Satoyama woodland managementSatoyama woodland management
Satoyama woodland managementHiroki Itô
 
MLPI Lecture 3: Advanced Sampling Techniques
MLPI Lecture 3: Advanced Sampling TechniquesMLPI Lecture 3: Advanced Sampling Techniques
MLPI Lecture 3: Advanced Sampling TechniquesDahua Lin
 
データ解析で割安賃貸物件を探せ!(山手線沿線編) LT
データ解析で割安賃貸物件を探せ!(山手線沿線編) LTデータ解析で割安賃貸物件を探せ!(山手線沿線編) LT
データ解析で割安賃貸物件を探せ!(山手線沿線編) LT. .
 
分布から見た線形モデル・GLM・GLMM
分布から見た線形モデル・GLM・GLMM分布から見た線形モデル・GLM・GLMM
分布から見た線形モデル・GLM・GLMM. .
 
100人のための統計解析 和食レストラン編
100人のための統計解析   和食レストラン編100人のための統計解析   和食レストラン編
100人のための統計解析 和食レストラン編. .
 
順序データでもベイズモデリング
順序データでもベイズモデリング順序データでもベイズモデリング
順序データでもベイズモデリング. .
 
状態空間モデルの実行方法と実行環境の比較
状態空間モデルの実行方法と実行環境の比較状態空間モデルの実行方法と実行環境の比較
状態空間モデルの実行方法と実行環境の比較Hiroki Itô
 
変分推論法(変分ベイズ法)(PRML第10章)
変分推論法(変分ベイズ法)(PRML第10章)変分推論法(変分ベイズ法)(PRML第10章)
変分推論法(変分ベイズ法)(PRML第10章)Takao Yamanaka
 
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)StanとRでベイズ統計モデリング読書会 導入編(1章~3章)
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)Hiroshi Shimizu
 
変分ベイズ法の説明
変分ベイズ法の説明変分ベイズ法の説明
変分ベイズ法の説明Haruka Ozaki
 
PyMCがあれば,ベイズ推定でもう泣いたりなんかしない
PyMCがあれば,ベイズ推定でもう泣いたりなんかしないPyMCがあれば,ベイズ推定でもう泣いたりなんかしない
PyMCがあれば,ベイズ推定でもう泣いたりなんかしないToshihiro Kamishima
 
RとStanでクラウドセットアップ時間を分析してみたら #TokyoR
RとStanでクラウドセットアップ時間を分析してみたら #TokyoRRとStanでクラウドセットアップ時間を分析してみたら #TokyoR
RとStanでクラウドセットアップ時間を分析してみたら #TokyoRShuyo Nakatani
 
Stanコードの書き方 中級編
Stanコードの書き方 中級編Stanコードの書き方 中級編
Stanコードの書き方 中級編Hiroshi Shimizu
 
エクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについてエクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについてHiroshi Shimizu
 
Pythonによる機械学習入門 ~Deep Learningに挑戦~
Pythonによる機械学習入門 ~Deep Learningに挑戦~Pythonによる機械学習入門 ~Deep Learningに挑戦~
Pythonによる機械学習入門 ~Deep Learningに挑戦~Yasutomo Kawanishi
 

Destacado (18)

Replica exchange MCMC
Replica exchange MCMCReplica exchange MCMC
Replica exchange MCMC
 
RStanとShinyStanによるベイズ統計モデリング入門
RStanとShinyStanによるベイズ統計モデリング入門RStanとShinyStanによるベイズ統計モデリング入門
RStanとShinyStanによるベイズ統計モデリング入門
 
階層ベイズモデルで割安mobile PCを探す
階層ベイズモデルで割安mobile PCを探す階層ベイズモデルで割安mobile PCを探す
階層ベイズモデルで割安mobile PCを探す
 
Satoyama woodland management
Satoyama woodland managementSatoyama woodland management
Satoyama woodland management
 
MLPI Lecture 3: Advanced Sampling Techniques
MLPI Lecture 3: Advanced Sampling TechniquesMLPI Lecture 3: Advanced Sampling Techniques
MLPI Lecture 3: Advanced Sampling Techniques
 
データ解析で割安賃貸物件を探せ!(山手線沿線編) LT
データ解析で割安賃貸物件を探せ!(山手線沿線編) LTデータ解析で割安賃貸物件を探せ!(山手線沿線編) LT
データ解析で割安賃貸物件を探せ!(山手線沿線編) LT
 
分布から見た線形モデル・GLM・GLMM
分布から見た線形モデル・GLM・GLMM分布から見た線形モデル・GLM・GLMM
分布から見た線形モデル・GLM・GLMM
 
100人のための統計解析 和食レストラン編
100人のための統計解析   和食レストラン編100人のための統計解析   和食レストラン編
100人のための統計解析 和食レストラン編
 
順序データでもベイズモデリング
順序データでもベイズモデリング順序データでもベイズモデリング
順序データでもベイズモデリング
 
状態空間モデルの実行方法と実行環境の比較
状態空間モデルの実行方法と実行環境の比較状態空間モデルの実行方法と実行環境の比較
状態空間モデルの実行方法と実行環境の比較
 
変分推論法(変分ベイズ法)(PRML第10章)
変分推論法(変分ベイズ法)(PRML第10章)変分推論法(変分ベイズ法)(PRML第10章)
変分推論法(変分ベイズ法)(PRML第10章)
 
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)StanとRでベイズ統計モデリング読書会 導入編(1章~3章)
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)
 
変分ベイズ法の説明
変分ベイズ法の説明変分ベイズ法の説明
変分ベイズ法の説明
 
PyMCがあれば,ベイズ推定でもう泣いたりなんかしない
PyMCがあれば,ベイズ推定でもう泣いたりなんかしないPyMCがあれば,ベイズ推定でもう泣いたりなんかしない
PyMCがあれば,ベイズ推定でもう泣いたりなんかしない
 
RとStanでクラウドセットアップ時間を分析してみたら #TokyoR
RとStanでクラウドセットアップ時間を分析してみたら #TokyoRRとStanでクラウドセットアップ時間を分析してみたら #TokyoR
RとStanでクラウドセットアップ時間を分析してみたら #TokyoR
 
Stanコードの書き方 中級編
Stanコードの書き方 中級編Stanコードの書き方 中級編
Stanコードの書き方 中級編
 
エクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについてエクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについて
 
Pythonによる機械学習入門 ~Deep Learningに挑戦~
Pythonによる機械学習入門 ~Deep Learningに挑戦~Pythonによる機械学習入門 ~Deep Learningに挑戦~
Pythonによる機械学習入門 ~Deep Learningに挑戦~
 

Similar a Dealing with latent discrete parameters in Stan

Applied machine learning for search engine relevance 3
Applied machine learning for search engine relevance 3Applied machine learning for search engine relevance 3
Applied machine learning for search engine relevance 3Charles Martin
 
Actors for Behavioural Simulation
Actors for Behavioural SimulationActors for Behavioural Simulation
Actors for Behavioural SimulationClarkTony
 
Simple representations for learning: factorizations and similarities
Simple representations for learning: factorizations and similarities Simple representations for learning: factorizations and similarities
Simple representations for learning: factorizations and similarities Gael Varoquaux
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..KarthikeyaLanka1
 
Exploring temporal graph data with Python: 
a study on tensor decomposition o...
Exploring temporal graph data with Python: 
a study on tensor decomposition o...Exploring temporal graph data with Python: 
a study on tensor decomposition o...
Exploring temporal graph data with Python: 
a study on tensor decomposition o...André Panisson
 
Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...Toshiyuki Shimono
 
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward
 
Gradient Boosted Regression Trees in scikit-learn
Gradient Boosted Regression Trees in scikit-learnGradient Boosted Regression Trees in scikit-learn
Gradient Boosted Regression Trees in scikit-learnDataRobot
 
Efficient Process Model Discovery Using Maximal Pattern Mining
Efficient Process Model Discovery Using Maximal Pattern MiningEfficient Process Model Discovery Using Maximal Pattern Mining
Efficient Process Model Discovery Using Maximal Pattern MiningDr. Sira Yongchareon
 
Vu_HPSC2012_02.pptx
Vu_HPSC2012_02.pptxVu_HPSC2012_02.pptx
Vu_HPSC2012_02.pptxQucngV
 
Bayesian Experimental Design for Stochastic Kinetic Models
Bayesian Experimental Design for Stochastic Kinetic ModelsBayesian Experimental Design for Stochastic Kinetic Models
Bayesian Experimental Design for Stochastic Kinetic ModelsColin Gillespie
 
Monitoring nonlinear profiles with {R}: an application to quality control
Monitoring nonlinear profiles with {R}: an application to quality controlMonitoring nonlinear profiles with {R}: an application to quality control
Monitoring nonlinear profiles with {R}: an application to quality controlEmilio L. Cano
 
Dual-time Modeling and Forecasting in Consumer Banking (2016)
Dual-time Modeling and Forecasting in Consumer Banking (2016)Dual-time Modeling and Forecasting in Consumer Banking (2016)
Dual-time Modeling and Forecasting in Consumer Banking (2016)Aijun Zhang
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptxmohitesoham12
 
Introduction to computing Processing and performance.pdf
Introduction to computing Processing and performance.pdfIntroduction to computing Processing and performance.pdf
Introduction to computing Processing and performance.pdfTulasiramKandula1
 
RSC: Mining and Modeling Temporal Activity in Social Media
RSC: Mining and Modeling Temporal Activity in Social MediaRSC: Mining and Modeling Temporal Activity in Social Media
RSC: Mining and Modeling Temporal Activity in Social MediaAlceu Ferraz Costa
 
Computing the Nucleon Spin from Lattice QCD
Computing the Nucleon Spin from Lattice QCDComputing the Nucleon Spin from Lattice QCD
Computing the Nucleon Spin from Lattice QCDChristos Kallidonis
 

Similar a Dealing with latent discrete parameters in Stan (20)

Applied machine learning for search engine relevance 3
Applied machine learning for search engine relevance 3Applied machine learning for search engine relevance 3
Applied machine learning for search engine relevance 3
 
Actors for Behavioural Simulation
Actors for Behavioural SimulationActors for Behavioural Simulation
Actors for Behavioural Simulation
 
MUMS Undergraduate Workshop - Parameter Selection and Model Calibration for a...
MUMS Undergraduate Workshop - Parameter Selection and Model Calibration for a...MUMS Undergraduate Workshop - Parameter Selection and Model Calibration for a...
MUMS Undergraduate Workshop - Parameter Selection and Model Calibration for a...
 
Simple representations for learning: factorizations and similarities
Simple representations for learning: factorizations and similarities Simple representations for learning: factorizations and similarities
Simple representations for learning: factorizations and similarities
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
 
Exploring temporal graph data with Python: 
a study on tensor decomposition o...
Exploring temporal graph data with Python: 
a study on tensor decomposition o...Exploring temporal graph data with Python: 
a study on tensor decomposition o...
Exploring temporal graph data with Python: 
a study on tensor decomposition o...
 
MSSISS riBART 20160321
MSSISS riBART 20160321MSSISS riBART 20160321
MSSISS riBART 20160321
 
Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...Theory to consider an inaccurate testing and how to determine the prior proba...
Theory to consider an inaccurate testing and how to determine the prior proba...
 
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
 
PS
PSPS
PS
 
Gradient Boosted Regression Trees in scikit-learn
Gradient Boosted Regression Trees in scikit-learnGradient Boosted Regression Trees in scikit-learn
Gradient Boosted Regression Trees in scikit-learn
 
Efficient Process Model Discovery Using Maximal Pattern Mining
Efficient Process Model Discovery Using Maximal Pattern MiningEfficient Process Model Discovery Using Maximal Pattern Mining
Efficient Process Model Discovery Using Maximal Pattern Mining
 
Vu_HPSC2012_02.pptx
Vu_HPSC2012_02.pptxVu_HPSC2012_02.pptx
Vu_HPSC2012_02.pptx
 
Bayesian Experimental Design for Stochastic Kinetic Models
Bayesian Experimental Design for Stochastic Kinetic ModelsBayesian Experimental Design for Stochastic Kinetic Models
Bayesian Experimental Design for Stochastic Kinetic Models
 
Monitoring nonlinear profiles with {R}: an application to quality control
Monitoring nonlinear profiles with {R}: an application to quality controlMonitoring nonlinear profiles with {R}: an application to quality control
Monitoring nonlinear profiles with {R}: an application to quality control
 
Dual-time Modeling and Forecasting in Consumer Banking (2016)
Dual-time Modeling and Forecasting in Consumer Banking (2016)Dual-time Modeling and Forecasting in Consumer Banking (2016)
Dual-time Modeling and Forecasting in Consumer Banking (2016)
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptx
 
Introduction to computing Processing and performance.pdf
Introduction to computing Processing and performance.pdfIntroduction to computing Processing and performance.pdf
Introduction to computing Processing and performance.pdf
 
RSC: Mining and Modeling Temporal Activity in Social Media
RSC: Mining and Modeling Temporal Activity in Social MediaRSC: Mining and Modeling Temporal Activity in Social Media
RSC: Mining and Modeling Temporal Activity in Social Media
 
Computing the Nucleon Spin from Lattice QCD
Computing the Nucleon Spin from Lattice QCDComputing the Nucleon Spin from Lattice QCD
Computing the Nucleon Spin from Lattice QCD
 

Último

Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...amitlee9823
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...amitlee9823
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
hybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptxhybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptx9to5mart
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...amitlee9823
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramMoniSankarHazra
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...only4webmaster01
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Pooja Nehwal
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...SUHANI PANDEY
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 

Último (20)

Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
hybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptxhybrid Seed Production In Chilli & Capsicum.pptx
hybrid Seed Production In Chilli & Capsicum.pptx
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 

Dealing with latent discrete parameters in Stan

  • 1. Dealing with latent discrete parameters in Stan ITÔ, Hiroki 2016-06-04 Tokyo.Stan Michael Betancourt’s Stan Lecture
  • 2. About me • An end user of statistical software • Researcher of forest ecology • Species composition of forests • Forest dynamics
  • 3. Contents 1. Introduction • Population Ecology 2. Examples 1. Capture-recapture data and data augmentation 2. Multistate model
  • 4. Bayesian Population Analysis using WinBUGS (BPA) • My colleagues and I translated “Bayesian Population Analysis using WinBUGS” by M. Kéry and M. Schaub into Japanese. • Many practical examples for population ecology
  • 5. Stan translation of BPA models https://github.com/stan-dev/example-models/tree/master/BPA
  • 6. Population ecology • A subfield of ecology • Studies of population • Changes in size (number of individuals) of animals, plants and other organisms • Estimation of population size, growth rate, extinction probability, etc.
  • 7. Population ecology • Latent discrete parameters are often used. • Unobserved status • Present or absent • Dead or alive • But Stan does not support discrete parameters. • Marginalizing out is required to deal with discrete parameters.
  • 8. Example 1 Capture-recapture data and data augmentation (in Chapter 6 of BPA)
  • 10. Data [,1] [,2] [,3] [1,] 0 0 1 [2,] 1 1 1 [3,] 1 0 0 [4,] 1 0 1 [5,] 1 0 1 [6,] 1 0 1 : [85,] 0 1 0 [86,] 0 1 1 [87,] 1 1 0 Individuals Survey occasions
  • 11. Estimation • Population size (total number of individuals including unobserved) • Detection (capture) probability
  • 12. Data augmentation [,1] [,2] [,3] [1,] 0 0 1 [2,] 1 1 1 [3,] 1 0 0 [4,] 1 0 1 : [87,] 1 1 0 [88,] 0 0 0 : [236,] 0 0 0 [237,] 0 0 0 Add 150 dummy records
  • 13. Model
  • 14. BUGS model { # Priors omega ~ dunif(0, 1) # Inclusion probability p ~ dunif(0, 1) # Detection probability # Likelihood for (i in 1:M){ z[i] ~ dbern(omega) # Inclusion indicators for (j in 1:T) { y[i, j] ~ dbern(p.eff[i, j]) p.eff[i, j] <- z[i] * p } } # Derived quantities N <- sum(z[]) }
  • 15. Stan
  • 16. data { int<lower=0> M; // Size of augmented data set int<lower=0> T; // Number of sampling occasions int<lower=0,upper=1> y[M, T]; // Capture-history matrix } transformed data { int<lower=0> s[M]; // Totals in each row int<lower=0> C; // Size of observed data set C <- 0; for (i in 1:M) { s[i] <- sum(y[i]); if (s[i] > 0) C <- C + 1; } } parameters { real<lower=0,upper=1> omega; // Inclusion probability real<lower=0,upper=1> p; // Detection probability }
  • 17. model { for (i in 1:M) { real lp[2]; if (s[i] > 0) { // Included increment_log_prob(bernoulli_log(1, omega) + binomial_log(s[i], T, p)); } else { // Included lp[1] <- bernoulli_log(1, omega) + binomial_log(0, T, p); // Not included lp[2] <- bernoulli_log(0, omega); increment_log_prob(log_sum_exp(lp)); } } }
  • 18. generated quantities { int<lower=C> N; N <- C + binomial_rng(M, omega * pow(1 - p, T)); }
  • 20. Computing times OpenBUGS Stan Number of chains 3 4 Burn-in or warmup + iterations / chain 500 + 1000 500 + 1000 Computing time (sec) 5.9 5.8 Effective sample size of p 320 1867 Eff. sample size / time (sec-1) 54.6 319.5 Environment: 2.8 GHz Xeon W3530, Ubuntu 14.04, No parallell computing. Compilation time is not included in Stan. Times were measured using system.time(). The values are mean of 3 measurements.
  • 22. Example 2 Multistate model (in chapter 9 of BPA)
  • 23. Multistate model 🐞 ① 🐞 ② 🐞 ③ 🐞 ④ 🐞 ⑤ 🐞⑥ 🐞⑦ 🐞⑧ 🐞⑨ Site A Site B Capture Release Recapture 🐞① 🐞 ② 🐞 ⑤ 🐞 ⑥ 🐞⑦ 🐞⑫ 🐞⑪ Site A Site B 🐞 ⑩
  • 24. Data [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 3 3 2 3 1 [2,] 1 1 1 1 1 2 [3,] 1 1 1 1 3 3 [4,] 1 3 3 3 3 3 [5,] 1 3 3 3 3 3 [6,] 1 1 2 3 3 3 : [798,] 3 3 3 3 2 3 [799,] 3 3 3 3 2 3 [800,] 3 3 3 3 2 3 Individuals Survey occasion Values 1: seen (captured) at site A, 2: seen (captured) at site B, 3: not seen (not captured)
  • 25. Estimation • Survival probability (at site A and B) • Movement probability (from site A to B and B to A) • Detection (capture) probability (at site A and B)
  • 26. State transition State at time t+1 Site A Site B Dead Site A φA(1-ψAB) φAψAB 1-φA State at time t Site B φBψBA φB(1-ψBA) 1-φB Dead 0 0 1 φA: survival probability at site A, φB: survival probability at site B, ψAB: movement probability from A to B, ψBA: movement probability from B to A
  • 27. Observation Observation at time t Site A Site B Not seen Site A pA 0 1-pA State at time t Site B 0 pB 1-pB Dead 0 0 1 pA: detection probability at site A, pB: detection probability at site B
  • 28. Model
  • 29. BUGS
  • 30. model { : # Define probabilities of state S(t+1) given S(t) ps[1, 1] <- phiA * (1 - psiAB) ps[1, 2] <- phiA * psiAB ps[1, 3] <- 1 - phiA ps[2, 1] <- phiB * psiBA ps[2, 2] <- phiB * (1 - psiBA) ps[2, 3] <- 1 - phiB ps[3, 1] <- 0 ps[3, 2] <- 0 ps[3, 3] <- 1 # Define probabilities of O(t) given S(t) po[1, 1] <- pA po[1, 2] <- 0 po[1, 3] <- 1 - pA po[2, 1] <- 0 po[2, 2] <- pB po[2, 3] <- 1 - pB po[3, 1] <- 0 po[3, 2] <- 0 po[3, 3] <- 1 :
  • 31. for (i in 1:nind) { # Define latent state at first capture z[i, f[i]] <- y[i, f[i]] for (t in (f[i] + 1):n.occasions) { # State process z[i, t] ~ dcat(ps[z[i, t - 1], ]) # Observation process y[i, t] ~ dcat(po[z[i, t], ]) } } f[]: array containing first capture occasion ps[,]: state transition matrix po[,]: observation matrix
  • 32. Stan Treating as a Hidden Markov model
  • 33. Site B Site B Site A DeadSite A Hidden Markov model State Observation Seen at site A Dead Not seen Seen at site B Seen at site A Not seen Not seen
  • 34. model { real acc[3]; vector[3] gamma[n_occasions]; // See Stan Modeling Language User's Guide and Reference Manual for (i in 1:nind) { if (f[i] > 0) { for (k in 1:3) gamma[f[i], k] <- (k == y[i, f[i]]); for (t in (f[i] + 1):n_occasions) { for (k in 1:3) { for (j in 1:3) acc[j] <- gamma[t - 1, j] * ps[j, k] * po[k, y[i, t]]; gamma[t, k] <- sum(acc); } } increment_log_prob(log(sum(gamma[n_occasions]))); } } }
  • 36. Computing times OpenBUGS Stan Number of chains 3 4 Burn-in or warmup + iterations / chain 500 + 2000 500 + 1000 Computing time (sec) 327.9 193.5 Effective sample size of pA 140 649 Eff. sample size / time (sec-1) 0.4 3.4 Environment: 2.8 GHz Xeon W3530, Ubuntu 14.04, No parallell computing. Compilation time is not included in Stan. Times were measured using system.time(). The values are mean of 3 measurements.
  • 38. Stan code data { int<lower=0> R; // Number of sites int<lower=0> T; // Number of temporal replications int<lower=0> y[R, T]; // Counts int<lower=0> K; // Upper bounds of population size } model { : // Likelihood for (i in 1:R) { vector[K+1] lp; for (n in max_y[i]:K) { lp[n + 1] <- binomial_log(y[i], n, p) + poisson_log(n, lambda); } increment_log_prob(log_sum_exp(lp[(max_y[i] + 1):(K + 1)])); } : }
  • 39. Computing times OpenBUGS Stan (K=100) Number of chains 3 4 Burn-in or warmup + iterations / chain 200 + 1000 500 + 1000 Computing time (sec) 25.4 1007.8 Effective sample size of λ 3000 401 Eff. sample size / time (sec-1) 118.3 0.4 Environment: 2.8 GHz Xeon W3530, Ubuntu 14.04, No parallell computing. Compilation time is not included in Stan. Times were measured using system.time(). The values are mean of 3 measurements.
  • 40. Summary • Stan can deal with models including discrete parameters by marginalizing. • Divide and sum up every cases • However, the formulation used are less straightforward.