class: center, middle, inverse, title-slide .title[ # Bayesian Linear Models ] .subtitle[ ## 05 - Diagnostics ] .author[ ### Stefano Coretta ] .institute[ ### University of Edinburgh ] .date[ ### 2023/07/07 ] --- layout: true # MCMC chains diagnostics --- ```r library(bayesplot) as.array(rt_bm_4) %>% mcmc_trace("b_Intercept", np = nuts_params(rt_bm_4)) ``` <img src="index_files/figure-html/rt-bm-4-chain-1-1.png" height="400" style="display: block; margin: auto;" /> --- ```r as.array(rt_bm_4) %>% mcmc_trace("b_IsWordFALSE:PhonLev", np = nuts_params(rt_bm_4)) ``` <img src="index_files/figure-html/rt-bm-4-chain-2-1.png" height="400" style="display: block; margin: auto;" /> --- An example of bad MCMC chain mixing. .center[ ![:scale 60%](../../img/trace_c.png) ] ??? Picture from <https://www.rdatagen.net/post/diagnosing-and-dealing-with-estimation-issues-in-the-bayesian-meta-analysis/>. --- ** `\(\hat{R}\)` and Effective Sample Size** .medium[ ```r rt_bm_4 ``` ``` ## Family: gaussian ## Links: mu = identity; sigma = identity ## Formula: RT ~ IsWord + PhonLev + IsWord:PhonLev ## Data: mald (Number of observations: 3000) ## Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1; ## total post-warmup draws = 4000 ## ## Population-Level Effects: ## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS ## Intercept 756.94 47.75 663.50 849.69 1.00 2008 2259 ## IsWordFALSE 229.58 68.39 97.23 368.09 1.00 1590 1633 ## PhonLev 31.75 6.65 18.93 44.62 1.00 1965 2330 ## IsWordFALSE:PhonLev -13.85 9.48 -32.78 4.28 1.00 1614 1700 ## ## Family Specific Parameters: ## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS ## sigma 339.49 4.49 330.79 348.14 1.00 3106 2214 ## ## Draws were sampled using sample(hmc). For each parameter, Bulk_ESS ## and Tail_ESS are effective sample size measures, and Rhat is the potential ## scale reduction factor on split chains (at convergence, Rhat = 1). ``` ] --- layout: false # Posterior predictive checks ```r pp_check(rt_bm_4, ndraws = 100) ``` <img src="index_files/figure-html/rt-bm-4-pp-1.png" height="400" style="display: block; margin: auto;" />