Title: | Performing Bayesian Inference for Repeated-Measures Designs |
---|---|
Description: | A Bayesian credible interval is interpreted with respect to posterior probability, and this interpretation is far more intuitive than that of a frequentist confidence interval. However, standard highest-density intervals can be wide due to between-subjects variability and tends to hide within-subject effects, rendering its relationship with the Bayes factor less clear in within-subject (repeated-measures) designs. This urgent issue can be addressed by using within-subject intervals in within-subject designs, which integrate four methods including the Wei-Nathoo-Masson (2023) <doi:10.3758/s13423-023-02295-1>, the Loftus-Masson (1994) <doi:10.3758/BF03210951>, the Nathoo-Kilshaw-Masson (2018) <doi:10.1016/j.jmp.2018.07.005>, and the Heck (2019) <doi:10.31234/osf.io/whp8t> interval estimates. |
Authors: | Zhengxiao Wei [aut, cre] , Farouk S. Nathoo [aut] , Michael E. J. Masson [aut] |
Maintainer: | Zhengxiao Wei <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.16 |
Built: | 2024-10-26 05:27:58 UTC |
Source: | https://github.com/zhengxiaouvic/rmbayes |
A data frame that is in the long format. A hypothetical experiment is designed to measure effects of study time in a free-recall paradigm. In this hypothetical experiment, to-be-recalled 20-word lists are presented at a rate of 1, 2, or 5 sec per word. Of interest is the relation between study time and number of recalled list words. Suppose that the experiment is run as a within-subject (repeated-measures) design, including a total of 10 subjects, each of whom participated in all three study-time conditions.
recall.long
recall.long
A data frame with 30 rows and 3 variables:
The factor containing 10 levels of subjects, "s1"
to "s10"
.
The factor containing three levels of the experimental manipulation, "Level1"
, "Level2"
, and "Level3"
.
The number of words recalled out of 20 for each of 10 subjects in each of three conditions.
Loftus, G. R., & Masson, M. E. J. (1994). Using confidence intervals in within-subject designs. Psychonomic Bulletin & Review, 1, 476–490.
A data frame that is in the wide format. A hypothetical experiment is designed to measure effects of study time in a free-recall paradigm. In this hypothetical experiment, to-be-recalled 20-word lists are presented at a rate of 1, 2, or 5 sec per word. Of interest is the relation between study time and number of recalled list words. Suppose that the experiment is run as a within-subject (repeated-measures) design, including a total of 10 subjects, each of whom participated in all three study-time conditions.
recall.wide
recall.wide
A data frame with 10 rows (each row corresponds to a subject) and 3 variables:
The number of words recalled under the first level of the experimental manipulation - 1 second exposure duration per word.
The number of words recalled under the second level of the experimental manipulation - 2 seconds exposure duration per word.
The number of words recalled under the third level of the experimental manipulation - 5 seconds exposure duration per word.
Loftus, G. R., & Masson, M. E. J. (1994). Using confidence intervals in within-subject designs. Psychonomic Bulletin & Review, 1, 476–490.
For both the homoscedastic and heteroscedastic cases in one-way within-subject (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-subject 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, ... )
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-subject 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-subject 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 on the variability of standardized condition effects when |
hb |
A positive real number specifying the prior scale on the variability of 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 |
Wei, Nathoo, and Masson (2023) consider three credible intervals: (1) the within-subject 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 for the mean response in a one-way within-subject design is
where represents the mean response for the
-th
subject under the
-th level of the experimental manipulation;
is the overall mean,
is the
-th level of the experimental manipulation;
, for the means model, is the
-th condition mean;
is the standardized subject-specific random effects;
is the number of levels;
is the number of subjects;
are independent and identically distributed.
The effects
and
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 and residual variance
(Nathoo et al., 2018).
Priors used in method=1
are the Jeffreys prior for the overall mean and residual variance,
a
-prior structure for standardized effects (
,
),
and independent scaled inverse-chi-square priors with one degree of freedom for
the scale hyperparameters of the
-priors (
,
).
Priors used in method=2
are the Jeffreys prior for the overall mean and residual variance,
a normal distribution for (not standardized) effects (,
),
and the standard uniform distribution for
the square root of
parameter (
,
).
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 parameter
(
,
).
Priors used in method=4
are the Jeffreys prior for the condition means and residual variance,
a -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
-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 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 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 ([email protected]), Farouk S. Nathoo ([email protected]), Michael E. J. Masson ([email protected]).
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 (2024). RStan: the R interface to Stan. R package version 2.32.5 https://mc-stan.org
Wei, Z., Nathoo, F. S., & Masson, M. E. J. (2023). Investigating the relationship between the Bayes factor and the separation of credible intervals. Psychonomic Bulletin & Review, 30, 1759–1781.
## 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)
## 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)