For both the homoscedastic and heteroscedastic cases in one-way within-subjects (repeated-measures) designs, this Stan-based R package provides multiple methods to construct the credible intervals for condition means, with each method based on different sets of priors. The emphasis is on the calculation of intervals that remove the between-subjects variability that is a nuisance in within-subjects designs, as proposed in Loftus and Masson (1994), the Bayesian analog proposed in Nathoo, Kilshaw, and Masson (2018), and the adaptation presented in Heck (2019).

Type | Source | Command |
---|---|---|

Release | CRAN | `install.packages("rmBayes")` |

Development | GitHub | `remotes::install_github("zhengxiaoUVic/rmBayes")` |

R 4.0.1 or later is recommended. Prior to installing the package, you need to configure your R installation to be able to compile C++ code. Follow the link below for your respective operating system for more instructions (Stan Development Team, 2020):

- Mac - Configuring C++ Toolchain
- Windows - Configuring C++ Toolchain
- Linux - Configuring C++ Toolchain

Installation time of the source package is about 11 minutes (Stan models need to be compiled). If you have R version 4.0.1 or later on Mac, Windows, or Ubuntu, you can find the binary packages HERE. Or, directly install the binary package by calling

```
install.packages("rstan")
install.packages("rmBayes", repos = "https://zhengxiaouvic.github.io/drat", type = "binary")
```

When the homogeneity of variance holds, a linear mixed-effects model

where

Nathoo et al. (2018) derived a Bayesian within-subject interval by conditioning on maximum likelihood estimates of the subject-specific random effects. An assumption articulated in Method 0 is the Jeffreys prior for the condition means

Method 0 constructs the highest-density interval (HDI) as

**Note**: The sample mean for the

The sample mean for the

The overall mean is

The within-group sum-of-squares (SS) is

The interaction SS is

Heck (2019) proposed modifying the conditional within-subjects Bayesian interval to account for uncertainty and shrinkage in the estimated random effects. He derived a modification by applying the HDI equation in Method 0 for the within-subjects Bayesian interval at each iteration of a Markov chain Monte Carlo (MCMC) sampling algorithm and then taking the average interval across posterior samples. Priors used in Method 4 are the Jeffreys prior for the condition means and residual variance, a

Method 4 constructs the HDI as

To assess the robustness of HDI results with respect to the choice of a prior distribution for the standard deviation of the subject-specific random effects in the within-subjects case, two additional priors are considered: uniform and half-Cauchy (

Methods 0 and 4-6 arbitrarily assume improper uniform priors for the condition means. In this work, we expanded the space of possible priors by appling the HDI equation in Method 0 to derive the newly proposed intervals from MCMC sampling, but assuming default

Similar to Methods 5 and 6, two additional priors are considered: uniform and half-Cauchy (

MCMC sampling of condition means

When modeling fixed effects, Rouder et al. (2012, p. 363) proposed default priors by projecting a set of

where

When the homogeneity of variance does not hold, the resulting HDI widths for conditions are unequal. Two approaches are currently provided for the heteroscedastic within-subjects data: Implementing the approach developed by Nathoo et al. (2018, p. 5);

Or, implementing the heteroscedastic standard HDI method on the subject-centering transformed data (subtracting from the original response the corresponding subject mean minus the overall mean). If a method option other than `0`

or `1`

is used with `var.equal=FALSE`

, a pooled estimate of variability will be used just as in the homoscedastic case, and a warning message will be returned.

Heck, D. W. (2019). Accounting for estimation uncertainty and shrinkage in Bayesian within-subject intervals: A comment on Nathoo, Kilshaw, and Masson (2018). *Journal of Mathematical Psychology*, *88*, 27–31.

Loftus, G. R., & Masson, M. E. J. (1994). Using confidence intervals in within-subject designs. *Psychonomic Bulletin & Review*, *1*, 476–490.

Nathoo, F. S., Kilshaw, R. E., & Masson, M. E. J. (2018). A better (Bayesian) interval estimate for within-subject designs. *Journal of Mathematical Psychology*, *86*, 1–9.

Rouder, J. N., Morey, R. D., Speckman, P. L., & Province, J. M. (2012). Default Bayes factors for ANOVA designs. *Journal of Mathematical Psychology*, *56*, 356–374.

Stan Development Team (2020). RStan: the R interface to Stan. R package version 2.21.2. https://mc-stan.org