Skip to content

Commit 73a9ff2

Browse files
authored
Merge pull request #263 from avehtari/lecture_11a
Lecture 11a
2 parents 581e571 + 95ccdc2 commit 73a9ff2

File tree

9 files changed

+18505
-0
lines changed

9 files changed

+18505
-0
lines changed

slides/BDA_lecture_11a.pdf

509 KB
Binary file not shown.

slides/BDA_lecture_11a.tex

Lines changed: 386 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,386 @@
1+
\documentclass[t]{beamer}
2+
%\documentclass[finnish,english,handout]{beamer}
3+
4+
\usepackage{tikz}
5+
\usepackage{bm}
6+
\usepackage[T1]{fontenc}
7+
\usepackage{booktabs}
8+
\usepackage[utf8]{inputenc}
9+
\usepackage{newtxtext} % times
10+
%\usepackage[scaled=.95]{cabin} % sans serif
11+
\usepackage{amsmath}
12+
\usepackage[varqu,varl]{inconsolata} % typewriter
13+
\usepackage[varg]{newtxmath}
14+
\usefonttheme[onlymath]{serif} % beamer font theme
15+
\usepackage{microtype}
16+
\usepackage{afterpage}
17+
\usepackage{url}
18+
\urlstyle{same}
19+
% \usepackage{amsbsy}
20+
% \usepackage{eucal}
21+
\usepackage{rotating}
22+
\usepackage{listings}
23+
\usepackage{lstbayes}
24+
\usepackage[all,poly,ps,color]{xy}
25+
\usepackage{eurosym}
26+
27+
\usepackage{natbib}
28+
\bibliographystyle{apalike}
29+
30+
\mode<presentation>
31+
{
32+
\setbeamercovered{invisible}
33+
\setbeamertemplate{itemize items}[circle]
34+
\setbeamercolor{frametitle}{bg=white,fg=navyblue}
35+
\setbeamertemplate{navigation symbols}{}
36+
\setbeamertemplate{headline}[default]{}
37+
\setbeamertemplate{footline}[split]
38+
% \setbeamertemplate{headline}[text line]{\insertsection}
39+
\setbeamertemplate{footline}[frame number]
40+
}
41+
42+
\pdfinfo{
43+
/Title (BDA, Lecture 11a)
44+
/Author (Aki Vehtari) %
45+
/Keywords (Bayesian data analysis)
46+
}
47+
48+
\definecolor{forestgreen}{rgb}{0.1333,0.5451,0.1333}
49+
\definecolor{navyblue}{rgb}{0,0,0.5}
50+
\definecolor{list1}{rgb}{0,0.2549,0.6784}
51+
\renewcommand{\emph}[1]{\textcolor{navyblue}{#1}}
52+
\definecolor{set11}{HTML}{E41A1C}
53+
\definecolor{set12}{HTML}{377EB8}
54+
\definecolor{set13}{HTML}{4DAF4A}
55+
\definecolor{prior}{RGB}{102,194,165}
56+
\definecolor{likelihood}{RGB}{252,141,98}
57+
58+
\graphicspath{{./figs/}}
59+
60+
61+
\parindent=0pt
62+
\parskip=8pt
63+
\tolerance=9000
64+
\abovedisplayshortskip=0pt
65+
66+
%\renewcommand{\itemsep}{0pt}
67+
% Lists
68+
\newenvironment{list1}{
69+
\begin{list}{$\color{list1}\bullet$}{\itemsep=6pt}}{
70+
\end{list}}
71+
\newenvironment{list1s}{
72+
\begin{list}{$\includegraphics[width=5pt]{logo.eps}$}{\itemsep=6pt}}{
73+
\end{list}}
74+
\newenvironment{list2}{
75+
\begin{list}{-}{\baselineskip=12pt\itemsep=2pt}}{
76+
\end{list}}
77+
\newenvironment{list3}{
78+
\begin{list}{$\cdot$}{\baselineskip=15pt}}{
79+
\end{list}}
80+
81+
\def\o{{\mathbf o}}
82+
\def\t{{\mathbf \theta}}
83+
\def\w{{\mathbf w}}
84+
\def\x{{\mathbf x}}
85+
\def\y{{\mathbf y}}
86+
\def\z{{\mathbf z}}
87+
88+
\def\peff{p_{\mathrm{eff}}}
89+
\def\eff{\mathrm{eff}}
90+
91+
\DeclareMathOperator{\E}{E}
92+
\DeclareMathOperator{\Var}{Var}
93+
\DeclareMathOperator{\var}{var}
94+
\DeclareMathOperator{\Sd}{Sd}
95+
\DeclareMathOperator{\sd}{sd}
96+
\DeclareMathOperator{\Gammad}{Gamma}
97+
\DeclareMathOperator{\Invgamma}{Inv-gamma}
98+
\DeclareMathOperator{\Bin}{Bin}
99+
\DeclareMathOperator{\Negbin}{Neg-bin}
100+
\DeclareMathOperator{\normal}{normal}
101+
\DeclareMathOperator{\gammadist}{gamma}
102+
\DeclareMathOperator{\expdist}{exponential}
103+
\DeclareMathOperator{\Poisson}{Poisson}
104+
\DeclareMathOperator{\betadist}{Beta}
105+
\DeclareMathOperator{\logit}{logit}
106+
\DeclareMathOperator{\N}{N}
107+
\DeclareMathOperator{\U}{U}
108+
\DeclareMathOperator{\BF}{BF}
109+
\DeclareMathOperator{\Invchi2}{Inv-\chi^2}
110+
\DeclareMathOperator{\NInvchi2}{N-Inv-\chi^2}
111+
\DeclareMathOperator{\InvWishart}{Inv-Wishart}
112+
\DeclareMathOperator{\tr}{tr}
113+
% \DeclareMathOperator{\Pr}{Pr}
114+
\def\euro{{\footnotesize \EUR\, }}
115+
\DeclareMathOperator{\rep}{\mathrm{rep}}
116+
117+
% \def\dashxy(#1){%
118+
% /xydash{[#1] 0 setdash}def}
119+
% \def\grayxy(#1){%
120+
% /xycolor{#1 setgray}def}
121+
% \newgraphescape{D}[1]{!{\ar @*{[!\dashxy(2 2)]} "#1"}}
122+
% \newgraphescape{P}[1]{!{\ar "#1"}}
123+
% \newgraphescape{F}[1]{!{*+=<2em>[F=]{#1}="#1"}}
124+
% \newgraphescape{O}[1]{!{*+=<2em>[F]{#1}="#1"}}
125+
% \newgraphescape{V}[1]{!{*+=<2em>[o][F]{#1}="#1"}}
126+
% \newgraphescape{B}[3]{!{{ "#1"*+#3\frm{} }.{ "#2"*+#3\frm{} } *+[F:!\grayxy(0.75)]\frm{}}}
127+
128+
129+
\title[]{Bayesian data analysis}
130+
\subtitle{}
131+
132+
\author{Noa Kallioinen}
133+
134+
\institute[Aalto]{}
135+
136+
\date[]{}
137+
138+
%\beamerdefaultoverlayspecification{<+->}
139+
140+
\begin{document}
141+
142+
%\maketitle
143+
144+
\begin{frame}{Prior and likelihood sensitivity checks with priorsense}
145+
146+
\begin{itemize}[<+->]
147+
\item sensible prior specification is important, as otherwise priors can strongly and unintentionally influence results
148+
\item we recommend checking prior and likelihood sensitivity using priorsense (Kallioinen et al., 2023)
149+
\end{itemize}
150+
151+
\begin{minipage}{0.2\textwidth}
152+
\onslide<2->{\begin{figure}
153+
\includegraphics[width=\textwidth]{logo.png}
154+
\end{figure}}
155+
\end{minipage}
156+
\hspace{0.05\textwidth}
157+
\begin{minipage}{0.65\textwidth}
158+
\begin{itemize}[<+->]
159+
\item efficient prior and likelihood sensitivity checks
160+
\item provides numerical and graphical diagnostics
161+
\item compatible with \texttt{brms} and applicable to any model (excluding flat priors)
162+
\item no need to refit
163+
\end{itemize}
164+
165+
\end{minipage}
166+
167+
\end{frame}
168+
169+
\begin{frame}{How it works}
170+
\begin{minipage}{0.2\textwidth}
171+
\begin{figure}
172+
\includegraphics[width=\linewidth]{logo.png}
173+
\end{figure}
174+
\end{minipage}
175+
\hspace{0.05\textwidth}
176+
\begin{minipage}{0.65\textwidth}
177+
\begin{itemize}[<+->]
178+
\item modifies the posterior by power-scaling the \textcolor{prior}{\textbf{prior}} or \textcolor{likelihood}{\textbf{likelihood}} slightly
179+
\item original posterior: \(p(\theta\mid y) \propto p(\theta)p(y\mid \theta)\)
180+
\item modified posterior: \(\bm{{\color{prior}{p(\theta)^{\alpha}}}} p(y\mid \theta)\) or \(p(\theta)
181+
\bm{{\color{likelihood}{p(y\mid \theta)^{\alpha}}}}\)
182+
\item uses Pareto-smoothed importance sampling to estimate modified posterior from original posterior draws \(\theta^{(s)}\)
183+
184+
\end{itemize}
185+
\end{minipage}
186+
\end{frame}
187+
188+
\begin{frame}{Power-scaling}
189+
\begin{figure}
190+
\centering
191+
\input{tikz/example_dists}
192+
\caption{Example power-scaled distributions}
193+
\label{fig:placeholder}
194+
\end{figure}
195+
196+
\end{frame}
197+
198+
\begin{frame}{Interpretation}
199+
\begin{figure}
200+
\centering
201+
\input{tikz/conflict-example}
202+
\caption{Prior-likelihood conflict}
203+
\label{fig:placeholder}
204+
\end{figure}
205+
206+
\end{frame}
207+
208+
\begin{frame}{Computation}
209+
\begin{itemize}
210+
\onslide<1->{\item[] For prior power-scaling:
211+
\item[] \(w_{pri}^{(s)} = \dfrac{\bm{{\color{prior}{p(\theta^{(s)})^{\alpha}}}}p(\theta^{(s)} \mid y)}{p(\theta^{(s)})p(\theta^{(s)} \mid y)} = \dfrac{\bm{{\color{prior}{p(\theta^{(s)})^{\alpha}}}}}{p(\theta^{(s)})} = p(\theta^{(s)})^{(\alpha - 1)}\)
212+
\item[]
213+
\item[]
214+
}
215+
\onslide<2>{\item[] For likelihood power-scaling:
216+
\item[] \(w_{lik}^{(s)} = \dfrac{p(\theta^{(s)})\bm{{\color{likelihood}{p(\theta^{(s)} \mid y)^{\alpha}}}}}{p(\theta^{(s)})p(\theta^{(s)} \mid y)} = \dfrac{\bm{{\color{likelihood}{p(\theta^{(s)} \mid y)^{\alpha}}}}}{p(y \mid \theta^{(s)})} = p(y \mid \theta^{(s)})^{(\alpha - 1)}\)}
217+
\end{itemize}
218+
\end{frame}
219+
220+
221+
\begin{frame}{Example}
222+
223+
\begin{itemize}
224+
\item Dataset: \texttt{npk}
225+
\item Goal: Model effect of Nitrogen, Phosphate and Potassium on pea crop yield
226+
\item Data: 24 observations of crop yield (3 observations of each combination)
227+
228+
\end{itemize}
229+
230+
\begin{figure}
231+
\centering
232+
\includegraphics[width=0.75\linewidth]{npk.png}
233+
\caption{Mean yield per combination}
234+
\label{fig:placeholder}
235+
\end{figure}
236+
237+
\end{frame}
238+
239+
\begin{frame}{Example}
240+
241+
Model:
242+
\begin{align*}
243+
\onslide<1->{y_i &\sim \N(\mu_i, \sigma^2)} \\[0.5em]
244+
\onslide<2->{\mu_i =& \beta_{\text{Intercept}}} \\
245+
\onslide<3->{ \quad +& \beta_{\text{N}} N_i && \text{(main effects)} \\
246+
\quad +& \beta_{\text{P}} P_i \\
247+
\quad +& \beta_{\text{K}} K_i
248+
} \\
249+
\onslide<4->{ \quad +& \beta_{\text{N} \times \text{K}} N_i K_i
250+
&& \text{(2-way interactions)}} \\
251+
\onslide<4->{ \quad +& \beta_{\text{N} \times \text{P}} N_i P_i} \\
252+
\onslide<4->{ \quad +& \beta_{\text{K} \times \text{P}} K_i P_i} \\
253+
% \onslide<5->{ &\quad + \beta_{\text{N} \times \text{P} \times \text{K}}
254+
% N_i P_i K_i
255+
% && \text{(3-way interaction)}} \\
256+
\end{align*}
257+
258+
\end{frame}
259+
260+
\begin{frame}{Example: Initial model}
261+
262+
\onslide<1->{
263+
Main effects only
264+
265+
\texttt{brms} formula:
266+
\texttt{yield} \sim \texttt{N + P + K }
267+
}
268+
269+
\onslide<2->{
270+
\texttt{prior(normal(0, 2.5), coef = "b\_N1", \textcolor{blue}{tag = "main"})}
271+
\texttt{prior(normal(0, 2.5), coef = "b\_K1", \textcolor{blue}{tag = "main"})}
272+
\texttt{prior(normal(0, 2.5), coef = "b\_P1", \textcolor{blue}{tag = "main"})}
273+
274+
\textcolor{blue}{tagging} a group of priors allows for selective power-scaling
275+
}
276+
\end{frame}
277+
278+
\begin{frame}{Example: Initial model checks}
279+
280+
281+
\only<1-2>{
282+
\texttt{powerscale\_plot\_dens(fit, \textcolor{blue}{prior\_selection = "main"})}
283+
}
284+
285+
\only<2>{
286+
\begin{figure}
287+
\centering
288+
\includegraphics[width=\linewidth]{npk_model1.png}
289+
\end{figure}
290+
291+
}
292+
293+
\only<3-4>{
294+
\texttt{powerscale\_sensitivity(fit, \textcolor{blue}{prior\_selection = "main"}})
295+
}
296+
297+
\only<4>{
298+
\begin{table}[]
299+
\centering
300+
\begin{tabular}{llll}
301+
variable & prior sens. & likelihood sens. & diagnosis \\
302+
\midrule
303+
b\_N1 & 0.15 & 0.18 & potential prior-data conflict \\
304+
b\_P1 & 0.06 & 0.07 & potential prior-data conflict \\
305+
b\_K1 & 0.11 & 0.14 & potential prior-data conflict
306+
\end{tabular}
307+
\caption{Sensitivity diagnostics}
308+
\label{tab:placeholder}
309+
\end{table}
310+
}
311+
312+
313+
\end{frame}
314+
315+
\begin{frame}{Example: Adjusted prior}
316+
317+
\texttt{prior(normal(0, \textcolor{blue}{25}), coef = "b\_N1", tag = "main")}
318+
\texttt{prior(normal(0, \textcolor{blue}{25}), coef = "b\_K1", tag = "main")}
319+
\texttt{prior(normal(0, \textcolor{blue}{25}), coef = "b\_P1", tag = "main")}
320+
321+
\end{frame}
322+
323+
\begin{frame}{Example: Adjusted prior checks}
324+
325+
\only<1>{
326+
\begin{figure}
327+
\centering
328+
\includegraphics[width=1\linewidth]{npk_model1adj.png}
329+
\end{figure}
330+
}
331+
332+
\only<2>{
333+
\begin{table}[]
334+
\centering
335+
\begin{tabular}{llll}
336+
variable & prior sens. & likelihood sens. & diagnosis \\
337+
\midrule
338+
b\_N1 & 0.00 & 0.10 & - \\
339+
b\_P1 & 0.00 & 0.09 & - \\
340+
b\_K1 & 0.00 & 0.10 & -
341+
\end{tabular}
342+
\end{table}
343+
344+
}
345+
\end{frame}
346+
347+
\begin{frame}{Example: Second model}
348+
349+
\onslide<1->{
350+
Main effects and two-way interactions
351+
352+
\texttt{brms} formula:
353+
354+
\texttt{yield} \sim \texttt{(N + P + K)\^{}2}
355+
}
356+
357+
\onslide<2->{
358+
\texttt{prior(normal(0, 25), coef = "b$\_$N1:P1", \textcolor{blue}{tag = "twoway"})}
359+
\texttt{prior(normal(0, 25), coef = "b$\_$N1:K1", \textcolor{blue}{tag = "twoway"})}
360+
\texttt{prior(normal(0, 25), coef = "b$\_$P1:K1", \textcolor{blue}{tag = "twoway"})}
361+
}
362+
\end{frame}
363+
364+
\begin{frame}{Example: Second model checks}
365+
366+
\begin{figure}
367+
\centering
368+
\includegraphics[width=1\linewidth]{npk_model2.png}
369+
\end{figure}
370+
371+
\end{frame}
372+
373+
\begin{frame}{Summary}
374+
375+
\begin{itemize}[<+->]
376+
\item priors can be challenging to specify without domain knowledge
377+
\item prior and likelihood sensitivity checking is recommended
378+
\item \texttt{priorsense} can make sensitivity checking faster
379+
\item with many parameters, use tags to select priors and look at predictions or model fit measures
380+
\item if checks indicate strong prior sensitivity, prior-data conflict, or weak likelihood, further thought should be put into the prior
381+
\item see more at \url{n-kall.github.io/priorsense}
382+
\end{itemize}
383+
384+
\end{frame}
385+
386+
\end{document}

slides/figs/logo.png

67.8 KB
Loading

slides/figs/npk.png

8.68 KB
Loading

slides/figs/npk_model1.png

54.6 KB
Loading

slides/figs/npk_model1adj.png

42.9 KB
Loading

slides/figs/npk_model2.png

46.7 KB
Loading

0 commit comments

Comments
 (0)