rmHDI | R Documentation |
For both the homoscedastic and heteroscedastic cases in one-way within-subjects (repeated-measures) designs, this function 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).
rmHDI( data = NULL, whichSubject = "Subject", whichLevel = "Level", whichResponse = "Response", data.wide = NULL, cred = 0.95, warmup = 200, iter = 2000, chains = 4, method = 1, var.equal = TRUE, design = c("within", "between"), treat = c("random", "fixed"), ht = ifelse(match.arg(treat) == "fixed", 0.5, 1), hb = 1, seed = sample.int(.Machine$integer.max, 1), diagnostics = FALSE, permuted = TRUE, ... )
data |
A long format matrix or data frame of the within-subjects data whose three columns are labeled in |
whichSubject |
A character string specifying the column name of subject variable in the long format data. |
whichLevel |
A character string specifying the column name of level variable in the long format data. |
whichResponse |
A character string specifying the column name of response variable in the long format data. |
data.wide |
Alternatively, a wide format matrix or data frame of the within-subjects data whose column indices are condition levels (see Examples).
If both |
cred |
A scalar |
warmup |
A positive integer specifying the number of warmup (burnin) iterations per chain. The default is 200. |
iter |
A positive integer specifying the number of iterations for each chain (excluding warmup). The default is 2000. |
chains |
A positive integer specifying the number of Markov chains. The default is 4. |
method |
A positive integer in |
var.equal |
A logical variable indicating whether to treat the variance of the response within each condition (level of the experimental manipulation) as being equal.
If |
design |
A character string specifying the experimental design.
If |
treat |
A character string specifying the type of condition effects when |
ht |
A positive real number specifying the prior scale for standardized condition effects when |
hb |
A positive real number specifying the prior scale for standardized subject-specific random effects when |
seed |
The seed for random number generation. |
diagnostics |
A logical variable indicating whether to return the MCMC summary statistics
when |
permuted |
A logical variable indicating whether to pre-process the input data.
No matter whether the input is long data or wide data, the function eventually converts it to wide data for calculation.
If |
... |
Additional arguments that pass to |
We consider three credible intervals: (1) the within-subjects Bayesian interval developed by Nathoo et al. (2018), whose derivation conditions on estimated random effects, (2) a modification of (1) based on a proposal by Heck (2019) to allow for shrinkage and account for estimation uncertainty, and (3) an alternative to option (2) based on the default priors used in Rouder, Morey, Speckman, and Province (2012). Markov chain Monte Carlo sampling is also used to obtain the standard highest-density interval (HDI) for each condition mean in a one-way between-subjects design.
When the homogeneity of variance holds, a linear mixed-effects model M_1 for the mean response in a one-way within-subjects design is
M_1: Y_{ij} = μ + σ_ε (t_i + b_j) + ε_{ij} versus M_0: Y_{ij} = μ + σ_ε b_j + ε_{ij}, ε_{ij} ~ N(0, σ_ε^2), i=1,…,a; j=1,…,n,
where Y_ij represents the mean response for the j-th subject under the i-th level of the experimental manipulation; μ is the overall mean, τ_i = σ_ε t_i is the i-th level of the experimental manipulation; μ_i = μ + τ_i, for the means model, is the i-th condition mean; b_j is the standardized subject-specific random effects; a is the number of levels; n is the number of subjects; ε_{ij} are independent and identically distributed. The effects t_i and b_j are both standardized relative to the standard deviation of the error σ_ε and become dimensionless (Rouder et al., 2012).
An assumption articulated in method=0
is the Jeffreys prior for the condition means μ_i and residual variance σ_ε^2 (Nathoo et al., 2018).
Priors used in method=1
are the Jeffreys prior for the overall mean μ and residual variance,
a g-prior structure for standardized effects (t_i ~ N(0, g_t), b_j ~ N(0, g_b)),
and independent scaled inverse-chi-square priors with one degree of freedom for
the scale hyperparameters of the g-priors (g_t ~ Scale-inv-χ^2(1, h_t^2), g_b ~ Scale-inv-χ^2(1, h_b^2)).
Priors used in method=2
are the Jeffreys prior for the overall mean and residual variance,
a normal distribution for (not standardized) effects (σ_ε t_i ~ N(0, g_t), σ_ε b_j ~ N(0, g_b)),
and the standard uniform distribution for
the square root of g parameter (sqrt(g_t) ~ Unif(0, 1), sqrt(g_b) ~ Unif(0, 1)).
Priors used in method=3
are the Jeffreys prior for the overall mean and residual variance,
a normal distribution for (not standardized) effects,
and the standard half-Cauchy distribution for the square root of g parameter
(sqrt(g_t) ~ Half-Cauchy(0, 1), sqrt(g_b) ~ Half-Cauchy(0, 1)).
Priors used in method=4
are the Jeffreys prior for the condition means and residual variance,
a g-prior structure for standardized subject-specific random effects, and independent scaled inverse-chi-square priors with one degree of freedom for the scale hyperparameters of the g-priors (Heck, 2019).
Priors used in method=5
are the Jeffreys prior for the condition means and residual variance,
a normal distribution for (not standardized) subject-specific random effects, and the standard uniform distribution for the square root of g parameter.
Priors used in method=6
are the Jeffreys prior for the condition means and residual variance,
a normal distribution for (not standardized) subject-specific random effects, and the standard half-Cauchy distribution for the square root of g parameter.
A list
with three components, if diagnostics=FALSE
:
HDI |
A matrix of HDI lower and upper bounds, whose row names are the condition levels. |
posterior means |
The posterior condition means when using |
arithmetic means |
Or, the arithmetic condition means when using |
width |
The HDI width, which is the half-length from the lower bound to the upper bound. |
A list
with four components including an additional object of S4 class representing the fitted results, if diagnostics=TRUE
.
Zhengxiao Wei (zhengxiao@uvic.ca), Farouk S. Nathoo (nathoo@uvic.ca), Michael E.J. Masson (mmasson@uvic.ca).
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
## Not run: data(recall.wide) # Example data, wide format rmHDI(data.wide = recall.wide, seed = 277) data(recall.long) # Example data, long format rmHDI(recall.long, seed = 277) colnames(recall.long) <- c("Participant", "Condition", "DV") rmHDI(recall.long, whichSubject = "Participant", whichLevel = "Condition", whichResponse = "DV", seed = 277) ## Nathoo et al. (2018) approach data(recall.long) rmHDI(recall.long, method = 0) rmHDI(recall.long, method = 0, var.equal = FALSE) ## Standard HDI rmHDI(recall.long, design = "between", seed = 277) ## MCMC diagnostics rmHDI(recall.long, seed = 277, diagnostics = TRUE)$diagnostics ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.