SlideShare a Scribd company logo
1 of 27
Download to read offline
Stanの事後処理
専修大学大学院文学研究科 M1 北條大樹
本スライドについて
•以下を某勉強会LT用に短縮・補足/加筆したものにな
ります
http://www.slideshare.net/daikihojo/stan-70425025
2
このスライドの目標
①Stan の結果から欲しいものを取り出す
Why▶Stanの結果はS4クラス・扱いづらい
②Stan (とJAGS)の結果を簡単に出力する
Why▶結果を出すのに余計な苦労はしない
3
(一部変態の方は除く)
S4クラスオブジェクトとは?
• The data contained in an object from an S4 class is defined by the slots in the class definition.
• Each slot in an object is a component of the object; like components (that is, elements) of a list,
these may be extracted and set, using the function slot() or more often the operator "@". However,
they differ from list components in important ways. First, slots can only be referred to by name, not
by position, and there is no partial matching of names as with list elements.
• All the objects from a particular class have the same set of slot names; specifically, the slot names
that are contained in the class definition. Each slot in each object always is an object of the class
specified for this slot in the definition of the current class. The word "is" corresponds to the R
function of the same name (is), meaning that the class of the object in the slot must be the same as
the class specified in the definition, or some class that extends the one in the definition (a subclass).
• A special slot name, .Data, stands for the ‘data part’ of the object. An object from a class with a data
part is defined by specifying that the class contains one of the R object types or one of the special
pseudo-classes, matrix or array, usually because the definition of the class, or of one of its
superclasses, has included the type or pseudo-class in its contains argument. A second special slot
name, .xData, is used to enable inheritance from abnormal types such as "environment" See the
section on inheriting from non-S4 classes for details on the representation and for the behavior of S3
methods with objects from these classes.
• Some slot names correspond to attributes used in old-style S3 objects and in R objects without an
explicit class, for example, the names attribute. If you define a class for which that attribute will be
set, such as a subclass of named vectors, you should include "names" as a slot. See the definition of
class "namedList" for an example. Using the names() assignment to set such names will generate a
warning if there is no names slot and an error if the object in question is not a vector type. A slot
called "names" can be used anywhere, but only if it is assigned as a slot, not via the default names()
assignment.
4
from https://stat.ethz.ch/R-manual/R devel/library/methods/html/Classes_Details.html
S4クラスオブジェクトとは?
• The data contained in an object from an S4 class is defined by the slots in the class definition.
• Each slot in an object is a component of the object; like components (that is, elements) of a list,
these may be extracted and set, using the function slot() or more often the operator "@". However,
they differ from list components in important ways. First, slots can only be referred to by name, not
by position, and there is no partial matching of names as with list elements.
• All the objects from a particular class have the same set of slot names; specifically, the slot names
that are contained in the class definition. Each slot in each object always is an object of the class
specified for this slot in the definition of the current class. The word "is" corresponds to the R
function of the same name (is), meaning that the class of the object in the slot must be the same as
the class specified in the definition, or some class that extends the one in the definition (a subclass).
• A special slot name, .Data, stands for the ‘data part’ of the object. An object from a class with a data
part is defined by specifying that the class contains one of the R object types or one of the special
pseudo-classes, matrix or array, usually because the definition of the class, or of one of its
superclasses, has included the type or pseudo-class in its contains argument. A second special slot
name, .xData, is used to enable inheritance from abnormal types such as "environment" See the
section on inheriting from non-S4 classes for details on the representation and for the behavior of S3
methods with objects from these classes.
• Some slot names correspond to attributes used in old-style S3 objects and in R objects without an
explicit class, for example, the names attribute. If you define a class for which that attribute will be
set, such as a subclass of named vectors, you should include "names" as a slot. See the definition of
class "namedList" for an example. Using the names() assignment to set such names will generate a
warning if there is no names slot and an error if the object in question is not a vector type. A slot
called "names" can be used anywhere, but only if it is assigned as a slot, not via the default names()
assignment.
5
要は
複雑なオブジェクト構造
S4クラスオブジェクトとは?
• The data contained in an object from an S4 class is defined by the slots in the class definition.
• Each slot in an object is a component of the object; like components (that is, elements) of a list,
these may be extracted and set, using the function slot() or more often the operator "@". However,
they differ from list components in important ways. First, slots can only be referred to by name, not
by position, and there is no partial matching of names as with list elements.
• All the objects from a particular class have the same set of slot names; specifically, the slot names
that are contained in the class definition. Each slot in each object always is an object of the class
specified for this slot in the definition of the current class. The word "is" corresponds to the R
function of the same name (is), meaning that the class of the object in the slot must be the same as
the class specified in the definition, or some class that extends the one in the definition (a subclass).
• A special slot name, .Data, stands for the ‘data part’ of the object. An object from a class with a data
part is defined by specifying that the class contains one of the R object types or one of the special
pseudo-classes, matrix or array, usually because the definition of the class, or of one of its
superclasses, has included the type or pseudo-class in its contains argument. A second special slot
name, .xData, is used to enable inheritance from abnormal types such as "environment" See the
section on inheriting from non-S4 classes for details on the representation and for the behavior of S3
methods with objects from these classes.
• Some slot names correspond to attributes used in old-style S3 objects and in R objects without an
explicit class, for example, the names attribute. If you define a class for which that attribute will be
set, such as a subclass of named vectors, you should include "names" as a slot. See the definition of
class "namedList" for an example. Using the names() assignment to set such names will generate a
warning if there is no names slot and an error if the object in question is not a vector type. A slot
called "names" can be used anywhere, but only if it is assigned as a slot, not via the default names()
assignment.
6
fit$
では取り出せない
要は
複雑なオブジェクト構造
S4クラスオブジェクトとは?
• The data contained in an object from an S4 class is defined by the slots in the class definition.
• Each slot in an object is a component of the object; like components (that is, elements) of a list,
these may be extracted and set, using the function slot() or more often the operator "@". However,
they differ from list components in important ways. First, slots can only be referred to by name, not
by position, and there is no partial matching of names as with list elements.
• All the objects from a particular class have the same set of slot names; specifically, the slot names
that are contained in the class definition. Each slot in each object always is an object of the class
specified for this slot in the definition of the current class. The word "is" corresponds to the R
function of the same name (is), meaning that the class of the object in the slot must be the same as
the class specified in the definition, or some class that extends the one in the definition (a subclass).
• A special slot name, .Data, stands for the ‘data part’ of the object. An object from a class with a data
part is defined by specifying that the class contains one of the R object types or one of the special
pseudo-classes, matrix or array, usually because the definition of the class, or of one of its
superclasses, has included the type or pseudo-class in its contains argument. A second special slot
name, .xData, is used to enable inheritance from abnormal types such as "environment" See the
section on inheriting from non-S4 classes for details on the representation and for the behavior of S3
methods with objects from these classes.
• Some slot names correspond to attributes used in old-style S3 objects and in R objects without an
explicit class, for example, the names attribute. If you define a class for which that attribute will be
set, such as a subclass of named vectors, you should include "names" as a slot. See the definition of
class "namedList" for an example. Using the names() assignment to set such names will generate a
warning if there is no names slot and an error if the object in question is not a vector type. A slot
called "names" can be used anywhere, but only if it is assigned as a slot, not via the default names()
assignment.
7
fit$
では取り出せない
fit@
で取り出す
要は
複雑なオブジェクト構造
いつもの
• 8schools.stan を実行
準備完了
8
library(rstan) #パッケージ読み込み
rstan_options(auto_write = TRUE) #並列処理(下と合わせて)
options(mc.cores = parallel::detectCores())
dat <- list(J = 8,
y = c(28, 8, -3, 7, -1, 1, 18, 12),
sigma = c(15, 10, 16, 11, 9, 11, 10, 18))
fit<-stan(file ="8schools.stan", data = dat, iter = 1000,chains = 4)
①Stan の結果から欲しいものを取り出す
• 事後分布の平均値(EAP)を取り出す
• 事後分布の中央値(MED)を取り出す
• 95%信用区間を確認する
• 実効サンプルサイズを確認する
• ෡𝑹を確認する
9
summary(fit)$summary[,"50%"]
summary(fit)$summary[,"mean"]
summary(fit)$summary[,c("2.5%", "97.5%")]
summary(fit)$summary[, "n_eff"]
summary(fit)$summary[, "Rhat"]
①Stan の結果から欲しいものを取り出す
• 事後分布の平均値(EAP)を取り出す
• 事後分布の中央値(MED)を取り出す
• 95%信用区間を確認する
• 実効サンプルサイズを確認する
• ෡𝑹を確認する
10
summary(fit)$summary[,"50%"]
summary(fit)$summary[,"mean"]
summary(fit)$summary[,c("2.5%", "97.5%")]
summary(fit)$summary[, "n_eff"]
summary(fit)$summary[, "Rhat"]
①Stan の結果から欲しいものを取り出す
• 事後分布の平均値(EAP)を取り出す
• 事後分布の中央値(MED)を取り出す
• 95%信用区間を確認する
• 実効サンプルサイズを確認する
• ෡𝑹を確認する
11
summary(fit)$summary[,"50%"]
summary(fit)$summary[,"mean"]
summary(fit)$summary[,c("2.5%", "97.5%")]
summary(fit)$summary[, "n_eff"]
summary(fit)$summary[, "Rhat"]
①Stan の結果から欲しいものを取り出す
• 事後分布の平均値(EAP)を取り出す
• 事後分布の中央値(MED)を取り出す
• 95%信用区間を確認する
• 実効サンプルサイズを確認する
• ෡𝑹を確認する
12
summary(fit)$summary[,"50%"]
summary(fit)$summary[,"mean"]
summary(fit)$summary[,c("2.5%", "97.5%")]
summary(fit)$summary[, "n_eff"]
summary(fit)$summary[, "Rhat"]
①Stan の結果から欲しいものを取り出す
• 事後分布の平均値(EAP)を取り出す
• 事後分布の中央値(MED)を取り出す
• 95%信用区間を確認する
• 実効サンプルサイズを確認する
• ෡𝑹を確認する
13
summary(fit)$summary[,"50%"]
summary(fit)$summary[,"mean"]
summary(fit)$summary[,c("2.5%", "97.5%")]
summary(fit)$summary[, "n_eff"]
summary(fit)$summary[, "Rhat"]
①Stan の結果から欲しいものを取り出す
• 事後分布の平均値(EAP)を取り出す
• 事後分布の中央値(MED)を取り出す
• 95%信用区間を確認する
• 実効サンプルサイズを確認する
• ෡𝑹を確認する
14
summary(fit)$summary[,"50%"]
summary(fit)$summary[,"mean"]
summary(fit)$summary[,c("2.5%", "97.5%")]
summary(fit)$summary[, "n_eff"]
summary(fit)$summary[, "Rhat"]
①Stan の結果から欲しいものを取り出す
• 95%信用区間が0をまたいでいるか確認
※0をまたいでいれば,積が負の値になることを利用
• 実効サンプルサイズを確認する
※10%以上でサンプリングに問題ないと判断する(BDA3)
• ෡𝑹を確認する
※1.10以下で収束していると判断する(Gelman, & Rubin, 1992; BDA3)
15
all(apply(summary(fit)$summary[,c("2.5%", "97.5%")],1,prod)>0, na.rm = T)
all(summary(fit)$summary[, "n_eff"] > 0.10, na.rm = T)
all(summary(fit)$summary[, “Rhat"] < 1.10, na.rm = T)
①Stan の結果から欲しいものを取り出す
• 95%信用区間が0をまたいでいるか確認
※0をまたいでいれば,積が負の値になることを利用
• 実効サンプルサイズを確認する
※10%以上でサンプリングに問題ないと判断する(BDA3)
• ෡𝑹を確認する
※1.10以下で収束していると判断する(Gelman, & Rubin, 1992; BDA3)
16
all(apply(summary(fit)$summary[,c("2.5%", "97.5%")],1,prod)>0, na.rm = T)
all(summary(fit)$summary[, "n_eff"] > 0.10, na.rm = T)
all(summary(fit)$summary[, “Rhat"] < 1.10, na.rm = T)
①Stan の結果から欲しいものを取り出す
• 95%信用区間が0をまたいでいるか確認
※0をまたいでいれば,積が負の値になることを利用
• 実効サンプルサイズを確認する
※10%以上でサンプリングに問題ないと判断する(BDA3)
• ෡𝑹を確認する
※1.10以下で収束していると判断する(Gelman, & Rubin, 1992; BDA3)
17
all(apply(summary(fit)$summary[,c("2.5%", "97.5%")],1,prod)>0, na.rm = T)
all(summary(fit)$summary[, "n_eff"] > 0.10, na.rm = T)
all(summary(fit)$summary[, “Rhat"] < 1.10, na.rm = T)
①Stan の結果から欲しいものを取り出す
• 95%信用区間が0をまたいでいるか確認
※0をまたいでいれば,積が負の値になることを利用
• 実効サンプルサイズを確認する
※10%以上でサンプリングに問題ないと判断する(BDA3)
• ෡𝑹を確認する
※1.10以下で収束していると判断する(Gelman, & Rubin, 1992; BDA3)
18
all(apply(summary(fit)$summary[,c("2.5%", "97.5%")],1,prod)>0, na.rm = T)
all(summary(fit)$summary[, "n_eff"] > 0.10, na.rm = T)
all(summary(fit)$summary[, “Rhat"] < 1.10, na.rm = T)
①Stan の結果から欲しいものを取り出す
• “mu”に関する情報を取り出す
• “mu”と“tau”に関する情報を取り出す
• “theta[1]”~“theta[8]”に関する情報を取り出す
19
summary(fit)$summary[c("mu", "tau"),]
summary(fit)$summary["mu",]
summary(fit)$summary[paste0("theta[",1:fit@par_dims$theta,"]"),]
①Stan の結果から欲しいものを取り出す
• “mu”に関する情報を取り出す
• “mu”と“tau”に関する情報を取り出す
• “theta[1]”~“theta[8]”に関する情報を取り出す
20
summary(fit)$summary[c("mu", "tau"),]
summary(fit)$summary["mu",]
summary(fit)$summary[paste0("theta[",1:fit@par_dims$theta,"]"),]
①Stan の結果から欲しいものを取り出す
• “mu”に関する情報を取り出す
• “mu”と“tau”に関する情報を取り出す
• “theta[1]”~“theta[8]”に関する情報を取り出す
21
summary(fit)$summary[c("mu", "tau"),]
summary(fit)$summary["mu",]
summary(fit)$summary[paste0("theta[",1:fit@par_dims$theta,"]"),]
①Stan の結果から欲しいものを取り出す
• “mu”に関する情報を取り出す
• “mu”と“tau”に関する情報を取り出す
• “theta[1]”~“theta[8]”に関する情報を取り出す
22
summary(fit)$summary[c("mu", "tau"),]
summary(fit)$summary["mu",]
summary(fit)$summary[paste0("theta[",1:fit@par_dims$theta,"]"),]
②Stan (とJAGS)の結果を簡単に出力する
Stan (とJAGS)の結果を簡単出力するには??
▶最近登場の MCMCvis パッケージ
23
②Stan (とJAGS)の結果を簡単に出力する
最大の特徴
▶StanとJAGSのどちらも同じように結果をはき出せる
▶推定結果の比較が容易
24
mean 2.5% 50% 97.5% Rhat
mu 7.77 -1.69 7.67 17.10 1.01
tau 6.58 0.36 5.24 20.01 1.02
eta[1] 0.42 -1.52 0.42 2.15 1.00
...
eta[8] 0.07 -1.76 0.07 1.92 1.00
theta[1] 11.55 -1.19 10.28 30.59 1.01
...
theta[8] 8.27 -6.25 8.08 23.59 1.00
lp__ -39.42 -45.09 -39.19 -34.83 1.01
>MCMCsummary(fit)
②Stan (とJAGS)の結果を簡単に出力する
• 信用区間が0を
またいでいるかどうか
判定してくれる
(任意の値に変更可)
25
>MCMCplot(fit)
②Stan (とJAGS)の結果を簡単に出力する
• 左にtrace
右に事後分布
を描いてくれる
(JAGSの出力と同じ)
26
>MCMCtrace(fit)
さらなる変態へ
• Stanのデフォルト関数で様々な図が描ける
▶http://www.slideshare.net/daikihojo/stan-70425025
• もっとggplot2を簡単に書く/体裁を整える
▶ggpubr パッケージで
▶ggThemeAssist パッケージで
▶http://www.slideshare.net/daikihojo/ggplot-72164183
(国里研 LT資料)
• 好きな色を指定する
▶colourpicker パッケージで
27
たかみ

More Related Content

What's hot

階層ベイズによるワンToワンマーケティング入門
階層ベイズによるワンToワンマーケティング入門階層ベイズによるワンToワンマーケティング入門
階層ベイズによるワンToワンマーケティング入門shima o
 
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)StanとRでベイズ統計モデリング読書会 導入編(1章~3章)
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)Hiroshi Shimizu
 
階層モデルの分散パラメータの事前分布について
階層モデルの分散パラメータの事前分布について階層モデルの分散パラメータの事前分布について
階層モデルの分散パラメータの事前分布についてhoxo_m
 
Rで階層ベイズモデル
Rで階層ベイズモデルRで階層ベイズモデル
Rで階層ベイズモデルYohei Sato
 
ベイズ統計学の概論的紹介
ベイズ統計学の概論的紹介ベイズ統計学の概論的紹介
ベイズ統計学の概論的紹介Naoki Hayashi
 
心理学者のためのGlmm・階層ベイズ
心理学者のためのGlmm・階層ベイズ心理学者のためのGlmm・階層ベイズ
心理学者のためのGlmm・階層ベイズHiroshi Shimizu
 
MCMCでマルチレベルモデル
MCMCでマルチレベルモデルMCMCでマルチレベルモデル
MCMCでマルチレベルモデルHiroshi Shimizu
 
rstanで簡単にGLMMができるglmmstan()を作ってみた
rstanで簡単にGLMMができるglmmstan()を作ってみたrstanで簡単にGLMMができるglmmstan()を作ってみた
rstanで簡単にGLMMができるglmmstan()を作ってみたHiroshi Shimizu
 
NIPS2015読み会: Ladder Networks
NIPS2015読み会: Ladder NetworksNIPS2015読み会: Ladder Networks
NIPS2015読み会: Ladder NetworksEiichi Matsumoto
 
これからの仮説検証・モデル評価
これからの仮説検証・モデル評価これからの仮説検証・モデル評価
これからの仮説検証・モデル評価daiki hojo
 
あなたの心にBridgeSampling
あなたの心にBridgeSamplingあなたの心にBridgeSampling
あなたの心にBridgeSamplingdaiki hojo
 
Imputation of Missing Values using Random Forest
Imputation of Missing Values using  Random ForestImputation of Missing Values using  Random Forest
Imputation of Missing Values using Random ForestSatoshi Kato
 
ブートストラップ法とその周辺とR
ブートストラップ法とその周辺とRブートストラップ法とその周辺とR
ブートストラップ法とその周辺とRDaisuke Yoneoka
 
Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説Hiroshi Shimizu
 
Rで因子分析 商用ソフトで実行できない因子分析のあれこれ
Rで因子分析 商用ソフトで実行できない因子分析のあれこれRで因子分析 商用ソフトで実行できない因子分析のあれこれ
Rで因子分析 商用ソフトで実行できない因子分析のあれこれHiroshi Shimizu
 
Stan勉強会資料(前編)
Stan勉強会資料(前編) Stan勉強会資料(前編)
Stan勉強会資料(前編) daiki hojo
 
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章nocchi_airport
 
StanとRでベイズ統計モデリング読書会Ch.9
StanとRでベイズ統計モデリング読書会Ch.9StanとRでベイズ統計モデリング読書会Ch.9
StanとRでベイズ統計モデリング読書会Ch.9考司 小杉
 

What's hot (20)

階層ベイズによるワンToワンマーケティング入門
階層ベイズによるワンToワンマーケティング入門階層ベイズによるワンToワンマーケティング入門
階層ベイズによるワンToワンマーケティング入門
 
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)StanとRでベイズ統計モデリング読書会 導入編(1章~3章)
StanとRでベイズ統計モデリング読書会 導入編(1章~3章)
 
階層モデルの分散パラメータの事前分布について
階層モデルの分散パラメータの事前分布について階層モデルの分散パラメータの事前分布について
階層モデルの分散パラメータの事前分布について
 
Rで階層ベイズモデル
Rで階層ベイズモデルRで階層ベイズモデル
Rで階層ベイズモデル
 
ベイズ統計学の概論的紹介
ベイズ統計学の概論的紹介ベイズ統計学の概論的紹介
ベイズ統計学の概論的紹介
 
心理学者のためのGlmm・階層ベイズ
心理学者のためのGlmm・階層ベイズ心理学者のためのGlmm・階層ベイズ
心理学者のためのGlmm・階層ベイズ
 
MCMCでマルチレベルモデル
MCMCでマルチレベルモデルMCMCでマルチレベルモデル
MCMCでマルチレベルモデル
 
rstanで簡単にGLMMができるglmmstan()を作ってみた
rstanで簡単にGLMMができるglmmstan()を作ってみたrstanで簡単にGLMMができるglmmstan()を作ってみた
rstanで簡単にGLMMができるglmmstan()を作ってみた
 
NIPS2015読み会: Ladder Networks
NIPS2015読み会: Ladder NetworksNIPS2015読み会: Ladder Networks
NIPS2015読み会: Ladder Networks
 
これからの仮説検証・モデル評価
これからの仮説検証・モデル評価これからの仮説検証・モデル評価
これからの仮説検証・モデル評価
 
あなたの心にBridgeSampling
あなたの心にBridgeSamplingあなたの心にBridgeSampling
あなたの心にBridgeSampling
 
Imputation of Missing Values using Random Forest
Imputation of Missing Values using  Random ForestImputation of Missing Values using  Random Forest
Imputation of Missing Values using Random Forest
 
ブートストラップ法とその周辺とR
ブートストラップ法とその周辺とRブートストラップ法とその周辺とR
ブートストラップ法とその周辺とR
 
2 3.GLMの基礎
2 3.GLMの基礎2 3.GLMの基礎
2 3.GLMの基礎
 
Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説Cmdstanr入門とreduce_sum()解説
Cmdstanr入門とreduce_sum()解説
 
Rで因子分析 商用ソフトで実行できない因子分析のあれこれ
Rで因子分析 商用ソフトで実行できない因子分析のあれこれRで因子分析 商用ソフトで実行できない因子分析のあれこれ
Rで因子分析 商用ソフトで実行できない因子分析のあれこれ
 
Stan勉強会資料(前編)
Stan勉強会資料(前編) Stan勉強会資料(前編)
Stan勉強会資料(前編)
 
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章
StanとRでベイズ統計モデリングに関する読書会(Osaka.stan) 第四章
 
StanとRでベイズ統計モデリング読書会Ch.9
StanとRでベイズ統計モデリング読書会Ch.9StanとRでベイズ統計モデリング読書会Ch.9
StanとRでベイズ統計モデリング読書会Ch.9
 
Jokyokai
JokyokaiJokyokai
Jokyokai
 

Viewers also liked

楽にggplotを描く・整える
楽にggplotを描く・整える楽にggplotを描く・整える
楽にggplotを描く・整えるdaiki hojo
 
Inference via Bayesian Synthetic Likelihoods for a Mixed-Effects SDE Model of...
Inference via Bayesian Synthetic Likelihoods for a Mixed-Effects SDE Model of...Inference via Bayesian Synthetic Likelihoods for a Mixed-Effects SDE Model of...
Inference via Bayesian Synthetic Likelihoods for a Mixed-Effects SDE Model of...Umberto Picchini
 
いいからベイズ推定してみる
いいからベイズ推定してみるいいからベイズ推定してみる
いいからベイズ推定してみるMakoto Hirakawa
 
glmmstanパッケージを作ってみた
glmmstanパッケージを作ってみたglmmstanパッケージを作ってみた
glmmstanパッケージを作ってみたHiroshi Shimizu
 
Rで項目反応理論、テキストマイニング、Rの研修やってますという三題噺(33rd #TokyoR)
Rで項目反応理論、テキストマイニング、Rの研修やってますという三題噺(33rd #TokyoR)Rで項目反応理論、テキストマイニング、Rの研修やってますという三題噺(33rd #TokyoR)
Rで項目反応理論、テキストマイニング、Rの研修やってますという三題噺(33rd #TokyoR)Kenta Tanaka
 
状態空間モデルの実行方法と実行環境の比較
状態空間モデルの実行方法と実行環境の比較状態空間モデルの実行方法と実行環境の比較
状態空間モデルの実行方法と実行環境の比較Hiroki Itô
 
エクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについてエクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについてHiroshi Shimizu
 

Viewers also liked (7)

楽にggplotを描く・整える
楽にggplotを描く・整える楽にggplotを描く・整える
楽にggplotを描く・整える
 
Inference via Bayesian Synthetic Likelihoods for a Mixed-Effects SDE Model of...
Inference via Bayesian Synthetic Likelihoods for a Mixed-Effects SDE Model of...Inference via Bayesian Synthetic Likelihoods for a Mixed-Effects SDE Model of...
Inference via Bayesian Synthetic Likelihoods for a Mixed-Effects SDE Model of...
 
いいからベイズ推定してみる
いいからベイズ推定してみるいいからベイズ推定してみる
いいからベイズ推定してみる
 
glmmstanパッケージを作ってみた
glmmstanパッケージを作ってみたglmmstanパッケージを作ってみた
glmmstanパッケージを作ってみた
 
Rで項目反応理論、テキストマイニング、Rの研修やってますという三題噺(33rd #TokyoR)
Rで項目反応理論、テキストマイニング、Rの研修やってますという三題噺(33rd #TokyoR)Rで項目反応理論、テキストマイニング、Rの研修やってますという三題噺(33rd #TokyoR)
Rで項目反応理論、テキストマイニング、Rの研修やってますという三題噺(33rd #TokyoR)
 
状態空間モデルの実行方法と実行環境の比較
状態空間モデルの実行方法と実行環境の比較状態空間モデルの実行方法と実行環境の比較
状態空間モデルの実行方法と実行環境の比較
 
エクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについてエクセルで統計分析 統計プログラムHADについて
エクセルで統計分析 統計プログラムHADについて
 

Similar to Stanの事後処理専修大学大学院

Similar to Stanの事後処理専修大学大学院 (20)

classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
LISP: Object Sytstem Lisp
LISP: Object Sytstem LispLISP: Object Sytstem Lisp
LISP: Object Sytstem Lisp
 
LISP:Object System Lisp
LISP:Object System LispLISP:Object System Lisp
LISP:Object System Lisp
 
Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2Object Oriented Programming_Lecture 2
Object Oriented Programming_Lecture 2
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Python - object oriented
Python - object orientedPython - object oriented
Python - object oriented
 
Object oriented programming tutorial
Object oriented programming tutorialObject oriented programming tutorial
Object oriented programming tutorial
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Oops
OopsOops
Oops
 
Object and Classes in Java
Object and Classes in JavaObject and Classes in Java
Object and Classes in Java
 
CLASS & OBJECT IN JAVA
CLASS & OBJECT  IN JAVACLASS & OBJECT  IN JAVA
CLASS & OBJECT IN JAVA
 
XML schemas
XML schemasXML schemas
XML schemas
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
 
Class-١.pptx vbdbbdndgngngndngnnfndfnngn
Class-١.pptx vbdbbdndgngngndngnnfndfnngnClass-١.pptx vbdbbdndgngngndngnnfndfnngn
Class-١.pptx vbdbbdndgngngndngnnfndfnngn
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 

Recently uploaded

专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhijennyeacort
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Cantervoginip
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsVICTOR MAESTRE RAMIREZ
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPTBoston Institute of Analytics
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxBoston Institute of Analytics
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our WorldEduminds Learning
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryJeremy Anderson
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in collegessuser7a7cd61
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理e4aez8ss
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 

Recently uploaded (20)

专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
 
ASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel CanterASML's Taxonomy Adventure by Daniel Canter
ASML's Taxonomy Adventure by Daniel Canter
 
Advanced Machine Learning for Business Professionals
Advanced Machine Learning for Business ProfessionalsAdvanced Machine Learning for Business Professionals
Advanced Machine Learning for Business Professionals
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
Learn How Data Science Changes Our World
Learn How Data Science Changes Our WorldLearn How Data Science Changes Our World
Learn How Data Science Changes Our World
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data Story
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in college
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 

Stanの事後処理専修大学大学院

  • 4. S4クラスオブジェクトとは? • The data contained in an object from an S4 class is defined by the slots in the class definition. • Each slot in an object is a component of the object; like components (that is, elements) of a list, these may be extracted and set, using the function slot() or more often the operator "@". However, they differ from list components in important ways. First, slots can only be referred to by name, not by position, and there is no partial matching of names as with list elements. • All the objects from a particular class have the same set of slot names; specifically, the slot names that are contained in the class definition. Each slot in each object always is an object of the class specified for this slot in the definition of the current class. The word "is" corresponds to the R function of the same name (is), meaning that the class of the object in the slot must be the same as the class specified in the definition, or some class that extends the one in the definition (a subclass). • A special slot name, .Data, stands for the ‘data part’ of the object. An object from a class with a data part is defined by specifying that the class contains one of the R object types or one of the special pseudo-classes, matrix or array, usually because the definition of the class, or of one of its superclasses, has included the type or pseudo-class in its contains argument. A second special slot name, .xData, is used to enable inheritance from abnormal types such as "environment" See the section on inheriting from non-S4 classes for details on the representation and for the behavior of S3 methods with objects from these classes. • Some slot names correspond to attributes used in old-style S3 objects and in R objects without an explicit class, for example, the names attribute. If you define a class for which that attribute will be set, such as a subclass of named vectors, you should include "names" as a slot. See the definition of class "namedList" for an example. Using the names() assignment to set such names will generate a warning if there is no names slot and an error if the object in question is not a vector type. A slot called "names" can be used anywhere, but only if it is assigned as a slot, not via the default names() assignment. 4 from https://stat.ethz.ch/R-manual/R devel/library/methods/html/Classes_Details.html
  • 5. S4クラスオブジェクトとは? • The data contained in an object from an S4 class is defined by the slots in the class definition. • Each slot in an object is a component of the object; like components (that is, elements) of a list, these may be extracted and set, using the function slot() or more often the operator "@". However, they differ from list components in important ways. First, slots can only be referred to by name, not by position, and there is no partial matching of names as with list elements. • All the objects from a particular class have the same set of slot names; specifically, the slot names that are contained in the class definition. Each slot in each object always is an object of the class specified for this slot in the definition of the current class. The word "is" corresponds to the R function of the same name (is), meaning that the class of the object in the slot must be the same as the class specified in the definition, or some class that extends the one in the definition (a subclass). • A special slot name, .Data, stands for the ‘data part’ of the object. An object from a class with a data part is defined by specifying that the class contains one of the R object types or one of the special pseudo-classes, matrix or array, usually because the definition of the class, or of one of its superclasses, has included the type or pseudo-class in its contains argument. A second special slot name, .xData, is used to enable inheritance from abnormal types such as "environment" See the section on inheriting from non-S4 classes for details on the representation and for the behavior of S3 methods with objects from these classes. • Some slot names correspond to attributes used in old-style S3 objects and in R objects without an explicit class, for example, the names attribute. If you define a class for which that attribute will be set, such as a subclass of named vectors, you should include "names" as a slot. See the definition of class "namedList" for an example. Using the names() assignment to set such names will generate a warning if there is no names slot and an error if the object in question is not a vector type. A slot called "names" can be used anywhere, but only if it is assigned as a slot, not via the default names() assignment. 5 要は 複雑なオブジェクト構造
  • 6. S4クラスオブジェクトとは? • The data contained in an object from an S4 class is defined by the slots in the class definition. • Each slot in an object is a component of the object; like components (that is, elements) of a list, these may be extracted and set, using the function slot() or more often the operator "@". However, they differ from list components in important ways. First, slots can only be referred to by name, not by position, and there is no partial matching of names as with list elements. • All the objects from a particular class have the same set of slot names; specifically, the slot names that are contained in the class definition. Each slot in each object always is an object of the class specified for this slot in the definition of the current class. The word "is" corresponds to the R function of the same name (is), meaning that the class of the object in the slot must be the same as the class specified in the definition, or some class that extends the one in the definition (a subclass). • A special slot name, .Data, stands for the ‘data part’ of the object. An object from a class with a data part is defined by specifying that the class contains one of the R object types or one of the special pseudo-classes, matrix or array, usually because the definition of the class, or of one of its superclasses, has included the type or pseudo-class in its contains argument. A second special slot name, .xData, is used to enable inheritance from abnormal types such as "environment" See the section on inheriting from non-S4 classes for details on the representation and for the behavior of S3 methods with objects from these classes. • Some slot names correspond to attributes used in old-style S3 objects and in R objects without an explicit class, for example, the names attribute. If you define a class for which that attribute will be set, such as a subclass of named vectors, you should include "names" as a slot. See the definition of class "namedList" for an example. Using the names() assignment to set such names will generate a warning if there is no names slot and an error if the object in question is not a vector type. A slot called "names" can be used anywhere, but only if it is assigned as a slot, not via the default names() assignment. 6 fit$ では取り出せない 要は 複雑なオブジェクト構造
  • 7. S4クラスオブジェクトとは? • The data contained in an object from an S4 class is defined by the slots in the class definition. • Each slot in an object is a component of the object; like components (that is, elements) of a list, these may be extracted and set, using the function slot() or more often the operator "@". However, they differ from list components in important ways. First, slots can only be referred to by name, not by position, and there is no partial matching of names as with list elements. • All the objects from a particular class have the same set of slot names; specifically, the slot names that are contained in the class definition. Each slot in each object always is an object of the class specified for this slot in the definition of the current class. The word "is" corresponds to the R function of the same name (is), meaning that the class of the object in the slot must be the same as the class specified in the definition, or some class that extends the one in the definition (a subclass). • A special slot name, .Data, stands for the ‘data part’ of the object. An object from a class with a data part is defined by specifying that the class contains one of the R object types or one of the special pseudo-classes, matrix or array, usually because the definition of the class, or of one of its superclasses, has included the type or pseudo-class in its contains argument. A second special slot name, .xData, is used to enable inheritance from abnormal types such as "environment" See the section on inheriting from non-S4 classes for details on the representation and for the behavior of S3 methods with objects from these classes. • Some slot names correspond to attributes used in old-style S3 objects and in R objects without an explicit class, for example, the names attribute. If you define a class for which that attribute will be set, such as a subclass of named vectors, you should include "names" as a slot. See the definition of class "namedList" for an example. Using the names() assignment to set such names will generate a warning if there is no names slot and an error if the object in question is not a vector type. A slot called "names" can be used anywhere, but only if it is assigned as a slot, not via the default names() assignment. 7 fit$ では取り出せない fit@ で取り出す 要は 複雑なオブジェクト構造
  • 8. いつもの • 8schools.stan を実行 準備完了 8 library(rstan) #パッケージ読み込み rstan_options(auto_write = TRUE) #並列処理(下と合わせて) options(mc.cores = parallel::detectCores()) dat <- list(J = 8, y = c(28, 8, -3, 7, -1, 1, 18, 12), sigma = c(15, 10, 16, 11, 9, 11, 10, 18)) fit<-stan(file ="8schools.stan", data = dat, iter = 1000,chains = 4)
  • 9. ①Stan の結果から欲しいものを取り出す • 事後分布の平均値(EAP)を取り出す • 事後分布の中央値(MED)を取り出す • 95%信用区間を確認する • 実効サンプルサイズを確認する • ෡𝑹を確認する 9 summary(fit)$summary[,"50%"] summary(fit)$summary[,"mean"] summary(fit)$summary[,c("2.5%", "97.5%")] summary(fit)$summary[, "n_eff"] summary(fit)$summary[, "Rhat"]
  • 10. ①Stan の結果から欲しいものを取り出す • 事後分布の平均値(EAP)を取り出す • 事後分布の中央値(MED)を取り出す • 95%信用区間を確認する • 実効サンプルサイズを確認する • ෡𝑹を確認する 10 summary(fit)$summary[,"50%"] summary(fit)$summary[,"mean"] summary(fit)$summary[,c("2.5%", "97.5%")] summary(fit)$summary[, "n_eff"] summary(fit)$summary[, "Rhat"]
  • 11. ①Stan の結果から欲しいものを取り出す • 事後分布の平均値(EAP)を取り出す • 事後分布の中央値(MED)を取り出す • 95%信用区間を確認する • 実効サンプルサイズを確認する • ෡𝑹を確認する 11 summary(fit)$summary[,"50%"] summary(fit)$summary[,"mean"] summary(fit)$summary[,c("2.5%", "97.5%")] summary(fit)$summary[, "n_eff"] summary(fit)$summary[, "Rhat"]
  • 12. ①Stan の結果から欲しいものを取り出す • 事後分布の平均値(EAP)を取り出す • 事後分布の中央値(MED)を取り出す • 95%信用区間を確認する • 実効サンプルサイズを確認する • ෡𝑹を確認する 12 summary(fit)$summary[,"50%"] summary(fit)$summary[,"mean"] summary(fit)$summary[,c("2.5%", "97.5%")] summary(fit)$summary[, "n_eff"] summary(fit)$summary[, "Rhat"]
  • 13. ①Stan の結果から欲しいものを取り出す • 事後分布の平均値(EAP)を取り出す • 事後分布の中央値(MED)を取り出す • 95%信用区間を確認する • 実効サンプルサイズを確認する • ෡𝑹を確認する 13 summary(fit)$summary[,"50%"] summary(fit)$summary[,"mean"] summary(fit)$summary[,c("2.5%", "97.5%")] summary(fit)$summary[, "n_eff"] summary(fit)$summary[, "Rhat"]
  • 14. ①Stan の結果から欲しいものを取り出す • 事後分布の平均値(EAP)を取り出す • 事後分布の中央値(MED)を取り出す • 95%信用区間を確認する • 実効サンプルサイズを確認する • ෡𝑹を確認する 14 summary(fit)$summary[,"50%"] summary(fit)$summary[,"mean"] summary(fit)$summary[,c("2.5%", "97.5%")] summary(fit)$summary[, "n_eff"] summary(fit)$summary[, "Rhat"]
  • 15. ①Stan の結果から欲しいものを取り出す • 95%信用区間が0をまたいでいるか確認 ※0をまたいでいれば,積が負の値になることを利用 • 実効サンプルサイズを確認する ※10%以上でサンプリングに問題ないと判断する(BDA3) • ෡𝑹を確認する ※1.10以下で収束していると判断する(Gelman, & Rubin, 1992; BDA3) 15 all(apply(summary(fit)$summary[,c("2.5%", "97.5%")],1,prod)>0, na.rm = T) all(summary(fit)$summary[, "n_eff"] > 0.10, na.rm = T) all(summary(fit)$summary[, “Rhat"] < 1.10, na.rm = T)
  • 16. ①Stan の結果から欲しいものを取り出す • 95%信用区間が0をまたいでいるか確認 ※0をまたいでいれば,積が負の値になることを利用 • 実効サンプルサイズを確認する ※10%以上でサンプリングに問題ないと判断する(BDA3) • ෡𝑹を確認する ※1.10以下で収束していると判断する(Gelman, & Rubin, 1992; BDA3) 16 all(apply(summary(fit)$summary[,c("2.5%", "97.5%")],1,prod)>0, na.rm = T) all(summary(fit)$summary[, "n_eff"] > 0.10, na.rm = T) all(summary(fit)$summary[, “Rhat"] < 1.10, na.rm = T)
  • 17. ①Stan の結果から欲しいものを取り出す • 95%信用区間が0をまたいでいるか確認 ※0をまたいでいれば,積が負の値になることを利用 • 実効サンプルサイズを確認する ※10%以上でサンプリングに問題ないと判断する(BDA3) • ෡𝑹を確認する ※1.10以下で収束していると判断する(Gelman, & Rubin, 1992; BDA3) 17 all(apply(summary(fit)$summary[,c("2.5%", "97.5%")],1,prod)>0, na.rm = T) all(summary(fit)$summary[, "n_eff"] > 0.10, na.rm = T) all(summary(fit)$summary[, “Rhat"] < 1.10, na.rm = T)
  • 18. ①Stan の結果から欲しいものを取り出す • 95%信用区間が0をまたいでいるか確認 ※0をまたいでいれば,積が負の値になることを利用 • 実効サンプルサイズを確認する ※10%以上でサンプリングに問題ないと判断する(BDA3) • ෡𝑹を確認する ※1.10以下で収束していると判断する(Gelman, & Rubin, 1992; BDA3) 18 all(apply(summary(fit)$summary[,c("2.5%", "97.5%")],1,prod)>0, na.rm = T) all(summary(fit)$summary[, "n_eff"] > 0.10, na.rm = T) all(summary(fit)$summary[, “Rhat"] < 1.10, na.rm = T)
  • 19. ①Stan の結果から欲しいものを取り出す • “mu”に関する情報を取り出す • “mu”と“tau”に関する情報を取り出す • “theta[1]”~“theta[8]”に関する情報を取り出す 19 summary(fit)$summary[c("mu", "tau"),] summary(fit)$summary["mu",] summary(fit)$summary[paste0("theta[",1:fit@par_dims$theta,"]"),]
  • 20. ①Stan の結果から欲しいものを取り出す • “mu”に関する情報を取り出す • “mu”と“tau”に関する情報を取り出す • “theta[1]”~“theta[8]”に関する情報を取り出す 20 summary(fit)$summary[c("mu", "tau"),] summary(fit)$summary["mu",] summary(fit)$summary[paste0("theta[",1:fit@par_dims$theta,"]"),]
  • 21. ①Stan の結果から欲しいものを取り出す • “mu”に関する情報を取り出す • “mu”と“tau”に関する情報を取り出す • “theta[1]”~“theta[8]”に関する情報を取り出す 21 summary(fit)$summary[c("mu", "tau"),] summary(fit)$summary["mu",] summary(fit)$summary[paste0("theta[",1:fit@par_dims$theta,"]"),]
  • 22. ①Stan の結果から欲しいものを取り出す • “mu”に関する情報を取り出す • “mu”と“tau”に関する情報を取り出す • “theta[1]”~“theta[8]”に関する情報を取り出す 22 summary(fit)$summary[c("mu", "tau"),] summary(fit)$summary["mu",] summary(fit)$summary[paste0("theta[",1:fit@par_dims$theta,"]"),]
  • 24. ②Stan (とJAGS)の結果を簡単に出力する 最大の特徴 ▶StanとJAGSのどちらも同じように結果をはき出せる ▶推定結果の比較が容易 24 mean 2.5% 50% 97.5% Rhat mu 7.77 -1.69 7.67 17.10 1.01 tau 6.58 0.36 5.24 20.01 1.02 eta[1] 0.42 -1.52 0.42 2.15 1.00 ... eta[8] 0.07 -1.76 0.07 1.92 1.00 theta[1] 11.55 -1.19 10.28 30.59 1.01 ... theta[8] 8.27 -6.25 8.08 23.59 1.00 lp__ -39.42 -45.09 -39.19 -34.83 1.01 >MCMCsummary(fit)
  • 27. さらなる変態へ • Stanのデフォルト関数で様々な図が描ける ▶http://www.slideshare.net/daikihojo/stan-70425025 • もっとggplot2を簡単に書く/体裁を整える ▶ggpubr パッケージで ▶ggThemeAssist パッケージで ▶http://www.slideshare.net/daikihojo/ggplot-72164183 (国里研 LT資料) • 好きな色を指定する ▶colourpicker パッケージで 27 たかみ