Estimates configural invariance using `bootEGA`

on all data (across groups) first. After configural variance is established,
then metric invariance is tested using the community structure that established
configural invariance (see **Details** for more information on this process)

## Usage

```
invariance(
data,
groups,
structure = NULL,
iter = 500,
configural.threshold = 0.7,
configural.type = c("parametric", "resampling"),
corr = c("auto", "cor_auto", "pearson", "spearman"),
na.data = c("pairwise", "listwise"),
model = c("BGGM", "glasso", "TMFG"),
algorithm = c("leiden", "louvain", "walktrap"),
uni.method = c("expand", "LE", "louvain"),
ncores,
seed = NULL,
verbose = TRUE,
...
)
```

## Arguments

- data
Matrix or data frame. Should consist only of variables to be used in the analysis

- groups
Numeric or character vector (length =

`ncol(data)`

). Group membership corresponding to each case in data- structure
Numeric or character vector (length =

`ncol(data)`

). A vector representing the structure (numbers or labels for each item). Can be theoretical factors or the structure detected by`EGA`

. If supplied, then configural invariance check is skipped (i.e., configural invariance is assumed based on the given structure)- iter
Numeric (length = 1). Number of iterations to perform for the permutation. Defaults to

`500`

(recommended)- configural.threshold
Numeric (length = 1). Value to use a threshold in

`itemStability`

to determine which items should be removed during configural invariance (see**Details**for more information). Defaults to`0.70`

(recommended)- configural.type
Character (length = 1). Type of bootstrap to use for configural invariance in

`bootEGA`

. Defaults to`"parametric"`

- corr
Character (length = 1). Method to compute correlations. Defaults to

`"auto"`

. Available options:`"auto"`

--- Automatically computes appropriate correlations for the data using Pearson's for continuous, polychoric for ordinal, tetrachoric for binary, and polyserial/biserial for ordinal/binary with continuous. To change the number of categories that are considered ordinal, use`ordinal.categories`

(see`polychoric.matrix`

for more details)`"cor_auto"`

--- Uses`cor_auto`

to compute correlations. Arguments can be passed along to the function`"pearson"`

--- Pearson's correlation is computed for all variables regardless of categories`"spearman"`

--- Spearman's rank-order correlation is computed for all variables regardless of categories

For other similarity measures, compute them first and input them into

`data`

with the sample size (`n`

)- na.data
Character (length = 1). How should missing data be handled? Defaults to

`"pairwise"`

. Available options:`"pairwise"`

--- Computes correlation for all available cases between two variables`"listwise"`

--- Computes correlation for all complete cases in the dataset

- model
Character (length = 1). Defaults to

`"glasso"`

. Available options:`"BGGM"`

--- Computes the Bayesian Gaussian Graphical Model. Set argument`ordinal.categories`

to determine levels allowed for a variable to be considered ordinal. See`?BGGM::estimate`

for more details`"glasso"`

--- Computes the GLASSO with EBIC model selection. See`EBICglasso.qgraph`

for more details`"TMFG"`

--- Computes the TMFG method. See`TMFG`

for more details

- algorithm
Character or

`igraph`

`cluster_*`

function (length = 1). Defaults to`"walktrap"`

. Three options are listed below but all are available (see`community.detection`

for other options):`"leiden"`

--- See`cluster_leiden`

for more details`"louvain"`

--- By default,`"louvain"`

will implement the Louvain algorithm using the consensus clustering method (see`community.consensus`

for more information). This function will implement`consensus.method = "most_common"`

and`consensus.iter = 1000`

unless specified otherwise`"walktrap"`

--- See`cluster_walktrap`

for more details

- uni.method
Character (length = 1). What unidimensionality method should be used? Defaults to

`"louvain"`

. Available options:`"expand"`

--- Expands the correlation matrix with four variables correlated 0.50. If number of dimension returns 2 or less in check, then the data are unidimensional; otherwise, regular EGA with no matrix expansion is used. This method was used in the Golino et al.'s (2020)*Psychological Methods*simulation`"LE"`

--- Applies the Leading Eigenvector algorithm (`cluster_leading_eigen`

) on the empirical correlation matrix. If the number of dimensions is 1, then the Leading Eigenvector solution is used; otherwise, regular EGA is used. This method was used in the Christensen et al.'s (2023)*Behavior Research Methods*simulation`"louvain"`

--- Applies the Louvain algorithm (`cluster_louvain`

) on the empirical correlation matrix. If the number of dimensions is 1, then the Louvain solution is used; otherwise, regular EGA is used. This method was validated Christensen's (2022)*PsyArXiv*simulation. Consensus clustering can be used by specifying either`"consensus.method"`

or`"consensus.iter"`

- ncores
Numeric (length = 1). Number of cores to use in computing results. Defaults to

`ceiling(parallel::detectCores() / 2)`

or half of your computer's processing power. Set to`1`

to not use parallel computingIf you're unsure how many cores your computer has, then type:

`parallel::detectCores()`

- seed
Numeric (length = 1). Defaults to

`NULL`

or random results. Set for reproducible results. See Reproducibility and PRNG for more details on random number generation in`EGAnet`

- verbose
Boolean (length = 1). Should progress be displayed? Defaults to

`TRUE`

. Set to`FALSE`

to not display progress- ...
Additional arguments that can be passed on to

`auto.correlate`

,`network.estimation`

,`community.detection`

,`community.consensus`

,`EGA`

,`bootEGA`

, and`net.loads`

## Value

Returns a list containing:

- configural.results
`bootEGA`

results from the final run that produced configural invariance. This output will be output on the final run of unsuccessful configural invariance runs- memberships
Original memberships provided in

`structure`

or from`EGA`

if`structure = NULL`

- EGA
Original

`EGA`

results for the full sample- groups
A list containing:

- permutation
A list containing:

`groups`

--- Permutated groups acorss iterations`loadings`

--- Network loadings (`net.loads`

) for each group for each permutation`loadingsDifference`

--- Difference between the dominant loadings of each group for each permutation

- results
Data frame of the results (which are printed)

## Details

In traditional psychometrics, measurement invariance is performed in sequential testing from more flexible (more free parameters) to more rigid (fewer free parameters) structures. Measurement invariance in network psychometrics is no different.

**Configural Invariance**

To establish configural invariance, the data are collapsed across groups
and a common sample structure is identified used `bootEGA`

and `itemStability`

. If some variables have a replication
less than 0.70 in their assigned dimension, then they are considered unstable
and therefore not invariant. These variables are removed and this process
is repeated until all items are considered stable (replication values greater
than 0.70) or there are no variables left. If configural invariance cannot be
established, then the last run of results are returned and metric invariance
is not tested (because configural invariance is not met). Importantly, if any
variables *are* removed, then configural invariance is not met for the
original structure. Any removal would suggest only partial configural invariance
is met.

**Metric Invariance**

The variables that remain after configural invariance are submitted to metric
invariance. First, each group estimates a network and then network loadings
(`net.loads`

) are computed using the assigned
community memberships (determined during configural invariance). Then,
the difference between the assigned loadings of the groups is computed. This
difference represents the empirical values. Second, the group memberships
are permutated and networks are estimated based on the these permutated
groups for `iter`

times. Then, network loadings are computed and
the difference between the assigned loadings of the group is computed, resulting
in a null distribution. The empirical difference is then compared against
the null distribution using a two-tailed *p*-value based on the number
of null distribution differences that are greater and less than the empirical
differences for each variable. Both uncorrected and false discovery rate
corrected *p*-values are returned in the results. Uncorrected *p*-values
are flagged for significance along with the direction of group differences.

**Three or More Groups**

At this time, only two groups are supported. There is a method proposed to test three or more groups in Jamison, Golino, and Christensen (2023) but this approach has not been thoroughly vetted and validated. Future versions of the package will provide support for three or more groups once there is an established consensus for best practice.

For more details, see Jamison, Golino, and Christensen (2023)

## References

**Original implementation**

Jamison, L., Golino, H., & Christensen, A. P. (2023).
Metric invariance in exploratory graph analysis via permutation testing.
*PsyArXiv*.

## See also

`plot.EGAnet`

for plot usage in `EGAnet`

## Author

Laura Jamison <lj5yn@virginia.edu>, Hudson F. Golino <hfg9s at virginia.edu>, and Alexander P. Christensen <alexpaulchristensen@gmail.com>,

## Examples

```
# Load data
wmt <- wmt2[-1,7:24]
# Groups
groups <- rep(1:2, each = nrow(wmt) / 2)
if (FALSE) {
# Measurement invariance
results <- invariance(wmt, groups, ncores = 2)
# Plot with uncorrected alpha = 0.05
plot(results, p_type = "p", p_value = 0.05)
# Plot with BH-corrected alpha = 0.10
plot(results, p_type = "p_BH", p_value = 0.10)}
```