Aladins Bayes Factor in R
Stefan Wiens
10.17045/sthlmuni.4981154.v3
https://su.figshare.com/articles/dataset/Aladins_Bayes_Factor_in_R/4981154
<div><div>Contains R scripts (created with https://www.r-project.org/) to calculate the Bayes Factor "<b>a la Dienes</b>". It also produces plots (inspired by JASP, https://jasp-stats.org/).</div><div><br></div><div>Information and tutorial:</div><div>https://prezi.com/view/ZRDBpcbMgBrjcZbDWyH8/<br></div><div><br></div><div>Zoltan Dienes has several excellent papers on the use of Bayes Factor with informed priors. He distinguishes between uniform, half-normal, and normal priors. These can be used in the context of t tests with his online calculator (see below). This tool is simple to use and helpful, but it does not produce illustrations of the results. Also, to increase reproducibility in open science, it would be beneficial to have scripted analyses. With scripts, it would also be easier to check the robustness of the results by comparing effects of different priors, as suggested by Dienes. Although some R scripts have already been provided earlier (e.g., Baguley & Kaye, 2010, see Dienes' website), the present scripts are a humble attempt to improve these scripts.</div><div><br></div><div>http://www.lifesci.sussex.ac.uk/home/Zoltan_Dienes/inference/Bayes.htm<br></div><div>http://www.lifesci.sussex.ac.uk/home/Zoltan_Dienes/inference/bayes_factor.swf</div><div><div>https://doi.org/10.3758/s13423-017-1266-z<br></div></div><div><br></div><div>The present scripts are called "Aladins Bayes Factor in R". If you read "Aladins" out loud, it sounds like "a la Dienes", to give credit to Zoltan Dienes and his work. The script also fulfills my little wish to have a visualization of the BF (see JASP for beautiful figures, https://jasp-stats.org/ ).</div><div><br></div><div>BF_t.R and BF_U.R</div><div>The guide shows how to use these functions.</div><div><br></div><div><div>Phrase everything on the same, unstandardized units. That is, mean and SEM of the data, and the prediction of the H1 must all be in the same units. If you want to use standardized units, see Dienes' website on how to convert the scores. Alternatively, use JASP or the BayesFactor package in R (see links).</div><div><br></div><div>When defining your H1, phrase it so that you would mainly expect a positive effect. This makes more sense intuitively. (Another reason is that if you want to test one-tailed with tail = 1, the script assumes that you mean that the effect cannot be negative and cuts off the negative tail.)<br></div><div><br></div><div>If your data are opposite (i.e., negative) to the predicted direction (which is positive), enter a negative mean difference.</div></div><div><br></div><div>Example (with many more in the user guide): </div><div><b>BF_t(10, 5, 10000, -3, 8, 119)</b></div><div>The BF10 = 0.35 and BF01 = 2.86. The data tend to support the null hypothesis.</div><div>In the calculation, the H1 is modeled as a t distribution centered at 10 (and an SEM of 5); however, because the df = 10000, the t distribution is close enough to a normal distribution centered at 10 with an SD = 5.</div><div>The actual data had a mean effect of -3 (i.e., opposite to the prediction), SEM = 8, and df = 119. </div><div>BF_t(10, 5, 10000, -3, 8, 119) is identical to BF_t(10, 5, 10000, -3, 8, 119, tail = 2). Thus, H1 allows for both positive and negative effects.<br></div><div><br></div><div>Use BF_t.R to run Dienes' half-normal or normal prior. The script is already designed to run according to Dienes & Mclatchie (2017)--that is, with a t distribution rather than a normal distribution--but if you want a normal distribution, simply defines the degrees of freedom (dftheory and/or dfobtained) as 10000. With this setting, the t distribution is like a normal distribution.</div><div><br></div><div>Use BF_U.R to run Dienes' uniform prior.</div><div><br></div><div>If you do not like the resulting figures, just open the scripts and change them. To facilitate this process, I have marked some sections. It should be easy to:</div><div>> change the title (which is maybe too informative now)</div><div>> plot without the pie chart</div><div>> plot the legend ("prior" etc.) on the left rather than right</div></div><div><br></div><div>If the scripts are helpful, please cite them with reference to this deposit.</div><div><br></div><div>P.S. The present scripts follow up on my tutorial on how to transition from null hypothesis significance testing to Bayesian analyses.</div><div><br></div><div><div><div>Wiens, S., & Nilsson, M. E. (2016). Performing contrast analysis in factorial designs: From NHST to confidence intervals and beyond. Educational and Psychological Measurement, in press. doi: 10.1177/0013164416668950</div><div>https://doi.org/10.1177/0013164416668950</div><div><br></div><div>Wiens, Stefan (2017): Supplement for Performing contrast analysis in factorial designs: From NHST to confidence intervals and beyond. Educational and Psychological Measurement. figshare. </div><div>https://doi.org/10.17045/sthlmuni.4801627.v2</div></div></div><div><br></div>
2017-06-05 09:15:26
Bayes factors
null hypothesis significance testing
open science