Title: | Varying Intraclass Correlation Coefficients |
---|---|
Description: | Compute group-specific intraclass correlation coefficients, Bayesian testing of homogenous within-group variance, and spike-and-slab model selection to determine which groups share a common within-group variance in a one-way random effects model <10.31234/osf.io/hpq7w>. |
Authors: | Donald Williams [aut, cre] |
Maintainer: | Donald Williams <[email protected]> |
License: | GPL-2 |
Version: | 1.0.0 |
Built: | 2024-10-30 06:50:09 UTC |
Source: | CRAN |
Change the group ID to be consequetive numbers, starting at 1, which is required for model fitting.
change_group(group)
change_group(group)
group |
Numeric Vector. The grouping variable (e.g., subjects). |
Updated group ID.
# congruent trials dat <- subset(flanker, id %in% c(39, 23, 2)) change_group(dat$id)
# congruent trials dat <- subset(flanker, id %in% c(39, 23, 2)) change_group(dat$id)
Extract the group-specific coefficients (fixed effect + random effect).
## S3 method for class 'vicc' coef(object, cred = 0.9, ...)
## S3 method for class 'vicc' coef(object, cred = 0.9, ...)
object |
An object of class |
cred |
Numeric. Credible interval width (defaults to |
... |
Currently ignored. |
An array with the summarized parameters
Y <- flanker # congruent trials congruent <- subset(Y, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "customary") coef(fit)
Y <- flanker # congruent trials congruent <- subset(Y, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "customary") coef(fit)
Summarize the fixed effects.
## S3 method for class 'vicc' fixef(object, cred = 0.9, ...)
## S3 method for class 'vicc' fixef(object, cred = 0.9, ...)
object |
An object of class |
cred |
Numeric. Credible interval width (defaults to |
... |
Currently ignored. |
Summarized fixed effects
# data Y <- flanker # congruent trials congruent <- subset(Y, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] fit <- vicc( y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "pick_none" ) fixef(fit)
# data Y <- flanker # congruent trials congruent <- subset(Y, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] fit <- vicc( y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "pick_none" ) fixef(fit)
A dataset containing 33660 rows and 7 columns.
Block
Trial number
Arrow direction (1=left, 2=right)
Condition (0 = congruent, 1=neutral, 2=incongruent)
Correct (1) or incorrect (0)
Reaction time (seconds)
data("flanker")
data("flanker")
A dataframe 33660 rows and 7 columns.
Reaction times less than 0.20 and greater than 2 seconds were removed.
Hedge C, Powell G, Sumner P (2018). “The reliability paradox: Why robust cognitive tasks do not produce reliable individual differences.” Behavior Research Methods, 50(3), 1166–1186.
Extract the posterior inclusion probabilities (PIP) for either the random intercepts for sigma or the random effects standard deviation for sigma.
pip(object, ...)
pip(object, ...)
object |
Ab object of class |
... |
Currently ignored. |
A data frame.
The PIPs indicate whether the groups differ from the fixed effect, or average,
within-group variance. If the PIP is large, this indicates there is high probability
that group differs from the common variance. A marginal Bayes factor can be computed
as PIP / (1 - PIP), assuming that prior_prob = 0.5
.
# congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "pick_group") pip(fit)
# congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "pick_group") pip(fit)
pip
ObjectsBar plot for the posterior inclusion probabilities, which corresponds to the probability that each group differs from the average within-group variance.
## S3 method for class 'pip' plot(x, fill = "black", width = 0.5, ...)
## S3 method for class 'pip' plot(x, fill = "black", width = 0.5, ...)
x |
An object of class |
fill |
Character string. Which color for the bars
(defaults to |
width |
Numeric. The width for the bars (defaults to |
... |
Currently ignored |
A ggplot
object.
# congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] fit <- vicc( y = dat$rt, group = dat$id, iter = 500, burnin = 10, type = "pick_group" ) pips <- pip(fit) plot(pips)
# congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] fit <- vicc( y = dat$rt, group = dat$id, iter = 500, burnin = 10, type = "pick_group" ) pips <- pip(fit) plot(pips)
vicc
ObjectsPlot the group-specific coefficients or the random effects.
## S3 method for class 'vicc' plot(x, type = "coef", ...)
## S3 method for class 'vicc' plot(x, type = "coef", ...)
x |
An object of class |
type |
Character string. Which parameters should be plotted? The options are
|
... |
Currently ignored. |
A ggplot
object.
# congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "customary") plts <- plot(fit)
# congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "customary") plts <- plot(fit)
Extract posterior samples for vicc
objects
posterior_samples(object)
posterior_samples(object)
object |
An object of class |
An object of class data.frame
# congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "customary") samps <- posterior_samples(fit)
# congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "customary") samps <- posterior_samples(fit)
pip
ObjectsPrint pip
Objects
## S3 method for class 'pip' print(x, ...)
## S3 method for class 'pip' print(x, ...)
x |
An object of class |
... |
Currently ignored. |
vicc
ObjectsPrint vicc
Objects
## S3 method for class 'vicc' print(x, cred = 0.95, ...)
## S3 method for class 'vicc' print(x, cred = 0.95, ...)
x |
An object of class |
cred |
Numeric. Credible interval width (defaults to |
... |
Currently ignored |
Extract the group-specific parameter estimates.
## S3 method for class 'vicc' ranef(object, cred = 0.9, ...)
## S3 method for class 'vicc' ranef(object, cred = 0.9, ...)
object |
An object of class |
cred |
Numeric. Credible interval width (defaults to |
... |
Currently ignored. |
An array with the summarized parameters.
flanker <- vICC::flanker # congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "customary") ranef(fit)
flanker <- vICC::flanker # congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "customary") ranef(fit)
Compute varying intraclass correlation coefficients with the method introduced in Williams et al. (2019).
vicc( y, group, type = "pick_group", iter = 5000, chains = 2, burnin = 500, prior_scale = 1, prior_prob = 0.5 )
vicc( y, group, type = "pick_group", iter = 5000, chains = 2, burnin = 500, prior_scale = 1, prior_prob = 0.5 )
y |
Numeric vector. The outcome variable. |
group |
Numeric vector. The grouping variable (e.g., subjects). Note that the groups
must be numbered from 1 to the total number of groups.
See |
type |
Character string. Which model should be fitted
(defaults to |
iter |
Numeric. The number of posterior samples per chain (excluding |
chains |
Numeric. The number of chains (defaults to |
burnin |
Numeric. The number of burnin samples, which are discarded
(defaults to |
prior_scale |
Numeric. The prior distribution scale parameter
(defaults to |
prior_prob |
Numeric. The prior inclusion probability (defaults to |
An object of class vicc
.
Williams DR, Martin SR, Rast P (2019). “Putting the Individual into Reliability: Bayesian Testing of Homogeneous Within-Person Variance in Hierarchical Models.” PsyArXiv.
# congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "customary")
# congruent trials congruent <- subset(flanker, cond == 0) # subset 25 from each group dat <- congruent[unlist(tapply(1:nrow(congruent), congruent$id, head, 25)), ] # fit model fit <- vicc(y = dat$rt, group = dat$id, iter = 250, burnin = 10, type = "customary")