Package 'vICC'

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

Help Index


Change Group ID

Description

Change the group ID to be consequetive numbers, starting at 1, which is required for model fitting.

Usage

change_group(group)

Arguments

group

Numeric Vector. The grouping variable (e.g., subjects).

Value

Updated group ID.

Examples

# congruent trials
dat <- subset(flanker,  id %in% c(39, 23, 2))
change_group(dat$id)

Extract the Group-Specific Coefficients

Description

Extract the group-specific coefficients (fixed effect + random effect).

Usage

## S3 method for class 'vicc'
coef(object, cred = 0.9, ...)

Arguments

object

An object of class vicc

cred

Numeric. Credible interval width (defaults to 0.90).

...

Currently ignored.

Value

An array with the summarized parameters

Examples

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)

Extract Fixed Effects

Description

Summarize the fixed effects.

Usage

## S3 method for class 'vicc'
fixef(object, cred = 0.9, ...)

Arguments

object

An object of class vicc.

cred

Numeric. Credible interval width (defaults to 0.90)

...

Currently ignored.

Value

Summarized fixed effects

Examples

# 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: Flanker Task data from Hedge et al. (2018).

Description

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)

Usage

data("flanker")

Format

A dataframe 33660 rows and 7 columns.

Note

Reaction times less than 0.20 and greater than 2 seconds were removed.

References

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.


Posterior Inclusion Probabilities

Description

Extract the posterior inclusion probabilities (PIP) for either the random intercepts for sigma or the random effects standard deviation for sigma.

Usage

pip(object, ...)

Arguments

object

Ab object of class vicc.

...

Currently ignored.

Value

A data frame.

Note

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.

Examples

# 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)

Plot pip Objects

Description

Bar plot for the posterior inclusion probabilities, which corresponds to the probability that each group differs from the average within-group variance.

Usage

## S3 method for class 'pip'
plot(x, fill = "black", width = 0.5, ...)

Arguments

x

An object of class pip.

fill

Character string. Which color for the bars (defaults to black)?

width

Numeric. The width for the bars (defaults to 0.5).

...

Currently ignored

Value

A ggplot object.

Examples

# 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)

Plot vicc Objects

Description

Plot the group-specific coefficients or the random effects.

Usage

## S3 method for class 'vicc'
plot(x, type = "coef", ...)

Arguments

x

An object of class vicc.

type

Character string. Which parameters should be plotted? The options are ranef and coef (the default).

...

Currently ignored.

Value

A ggplot object.

Examples

# 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

Description

Extract posterior samples for vicc objects

Usage

posterior_samples(object)

Arguments

object

An object of class vicc

Value

An object of class data.frame

Examples

# 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)

Print pip Objects

Description

Print pip Objects

Usage

## S3 method for class 'pip'
print(x, ...)

Arguments

x

An object of class pip.

...

Currently ignored.


Print vicc Objects

Description

Print vicc Objects

Usage

## S3 method for class 'vicc'
print(x, cred = 0.95, ...)

Arguments

x

An object of class vicc.

cred

Numeric. Credible interval width (defaults to 0.90).

...

Currently ignored


Extract the Random Effects

Description

Extract the group-specific parameter estimates.

Usage

## S3 method for class 'vicc'
ranef(object, cred = 0.9, ...)

Arguments

object

An object of class vicc

cred

Numeric. Credible interval width (defaults to 0.90).

...

Currently ignored.

Value

An array with the summarized parameters.

Examples

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)

Varying Intraclass Correlation Coefficients

Description

Compute varying intraclass correlation coefficients with the method introduced in Williams et al. (2019).

Usage

vicc(
  y,
  group,
  type = "pick_group",
  iter = 5000,
  chains = 2,
  burnin = 500,
  prior_scale = 1,
  prior_prob = 0.5
)

Arguments

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 change_group.

type

Character string. Which model should be fitted (defaults to pick_group)? The options are described in Details.

iter

Numeric. The number of posterior samples per chain (excluding burnin).

chains

Numeric. The number of chains (defaults to 2).

burnin

Numeric. The number of burnin samples, which are discarded (defaults to 500).

prior_scale

Numeric. The prior distribution scale parameter (defaults to 1). Note the prior is a half student-t distribution with 10 degrees of freedom.

prior_prob

Numeric. The prior inclusion probability (defaults to 0.5). This is used for type = "pick_tau" or type = "pick_group" and ignored otherwise.

Value

An object of class vicc.

References

Williams DR, Martin SR, Rast P (2019). “Putting the Individual into Reliability: Bayesian Testing of Homogeneous Within-Person Variance in Hierarchical Models.” PsyArXiv.

Examples

# 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")