Part 3
Open MarathonData.RData
Estimate Model3 with
an intercept
the effects of km4week_z
and sp4week_z
and Age40
on MarathonTimeM
What do we learn?
Different ways to summarize our results:
visually
credible intervals (eti & hdi)
rope + hdi rule
hypothesis tests
bayesplot
packagemcmc_areas()
function
mcmc_areas_ridges()
function
mcmc_intervals()
function
mcmc_areas()
functionGives a posterior distribution including a certain credible interval that you can set manually with the prob
argument:
mcmc_areas()
functionmcmc_areas_ridges()
functionAlmost similar to the previous, only the horizontal spacing changes a bit…
Meanwhile, see how you can easily change the color scheme for bayesplot
graphs
mcmc_areas_ridges()
functionmcmc_intervals()
functionSummarizes the posterior as a horizontal bar with identifiers for two CI.
Here we set one for a 50% and one for a 89% CI
mcmc_intervals()
functionPowercombo: as_draws_df()
+ ggplot2
+ ggdist
What does as_draws_df()
do?
# A draws_df: 6 iterations, 1 chains, and 7 variables
b_Intercept b_km4week_z b_sp4week_z b_Age40 sigma lprior lp__
1 203 -13.0 -12.6 -7.97 15 -8.1 -333
2 196 -11.7 -9.7 3.88 13 -8.0 -333
3 201 -13.4 -13.5 -7.10 14 -8.0 -333
4 200 -12.0 -13.4 -3.44 13 -8.0 -331
5 199 -11.7 -9.9 0.42 14 -8.1 -331
6 200 -9.7 -10.8 -1.18 14 -8.1 -332
# ... hidden reserved variables {'.chain', '.iteration', '.draw'}
ggdist
geomsggdist
package has a set of functions to visualize a distribution
Before we start, set our own plot theme (not so necessary)
We use posterior_PD
as a starting point (our draws)
Change the CI’s to 50% and 89%
Let’s make a dotplot… (research shows this is best interpreted) with 100 dots
We use pivot_longer(everything())
to stack information on multiple parameters
Our example: 2 groups according to Age40
How to visualize the posterior probability of averages for both groups?
posterior_PD %>%
select(
b_Intercept, b_Age40
) %>%
mutate(
Mean_age_40above = b_Intercept,
Mean_age_min40 = b_Intercept + b_Age40
) %>%
select(
Mean_age_min40, Mean_age_40above
) %>%
pivot_longer(everything()) %>%
ggplot(
aes(x = value, color = name, fill = name)
) +
stat_halfeye(
.width = c(.50,.89),
alpha = .40
) +
scale_y_continuous(name = "", breaks = NULL)
Code: see separate script called HOP_script.R
on Dropbox
ROPE: Region Of Practical Equivalence
Set a region of parameter values that can be considered equivalent to having no effect
in standard effect sizes the advised default is a range of -0.1 to 0.1
this equals 1/2 of a small effect size (Cohen, 1988)
all parameter values in that range are set equal to no effect
ROPE + HDI rule
95% of HDI out of ROPE \(\rightarrow\) \(H_0\) rejected
95% of HDI all in ROPE \(\rightarrow\) \(H_0\) not rejected
95% of HDI partially out of ROPE \(\rightarrow\) undecided
bayestestR
packageWe can use the equivalence_test()
function of the bayestestR
package
# Test for Practical Equivalence
ROPE: [-2.28 2.28]
Parameter | H0 | inside ROPE | 95% HDI
-----------------------------------------------------
Intercept | Rejected | 0.00 % | [194.83 203.73]
km4week_z | Rejected | 0.00 % | [-14.59 -8.68]
sp4week_z | Rejected | 0.00 % | [-14.84 -8.76]
Age40 | Undecided | 53.50 % | [ -7.44 4.87]
We visualize the equivalence_test()
by adding plot( )
parameters
packagelibrary(parameters)
model_parameters(
MarathonTimes_Mod3,
ci_method = "hdi",
rope_range = c(-2.262,2.262), #sd MarathonTimeM = 22.62 so 22.62*0.1
test = c("rope", "pd")
)
# Fixed Effects
Parameter | Median | 95% CI | pd | % in ROPE | Rhat | ESS
------------------------------------------------------------------------------
(Intercept) | 199.29 | [195.12, 203.93] | 100% | 0% | 1.000 | 4441.00
km4week_z | -11.73 | [-14.60, -8.68] | 100% | 0% | 1.000 | 4421.00
sp4week_z | -11.80 | [-14.93, -8.88] | 100% | 0% | 1.000 | 4612.00
Age40 | -1.29 | [ -7.01, 5.24] | 67.12% | 53.16% | 1.000 | 4741.00
# Sigma
Parameter | Median | 95% CI | pd | % in ROPE | Rhat | ESS
------------------------------------------------------------------------
sigma | 13.73 | [11.66, 15.92] | 100% | 0% | 1.000 | 4064.00
https://www.bayesrulesbook.com/
In Nature Reviews
If you like running - like I do - this could be a great companion on your run!
There are many blogs and websites that you can consult if you want to find out more about making graphs.
One that I often fall back to is:
Do not hesitate to contact me!