Learn R Programming

psychonetrics (version 0.17.8)

transmod: Transform between model types

Description

This function allows to transform a model variance--covariance structure from one type to another. Its main uses are to (1) use a Cholesky decomposition to estimate a saturated covariance matrix or GGM, and (2) to transform between conditional (ggm) and marginal associations (cov).

Usage

transmod(x, ..., verbose, keep_computed = FALSE, log = TRUE,
         identify = TRUE)

Value

An object of the class psychonetrics (psychonetrics-class) with the requested variance--covariance structure(s).

Arguments

x

A psychonetrics model

...

Named arguments with the new types to use (e.g., between = "ggm" or y = "cov")

verbose

Logical, should messages be printed?

keep_computed

Logical: keep the model marked as computed after the transformation? Defaults to FALSE (the model must be re-run, although the transformed estimates are already at the ML solution). Cannot be TRUE with identification = 'variance'.

log

Logical, should a logbook entry be made?

identify

Logical, should the model be identified after transforming?

Author

Sacha Epskamp

Details

Transformations are only possible if the model is diagonal (e.g., no partial correlations) or saturated (e.g., all covariances included).

Examples

Run this code
# Load bfi data from psych package:
library("psychTools")
data(bfi)

# Also load dplyr for the pipe operator:
library("dplyr")

# Let's take the agreeableness items, and gender:
ConsData <- bfi %>% 
  select(A1:A5, gender) %>% 
  na.omit # Let's remove missingness (otherwise use Estimator = "FIML)

# Define variables:
vars <- names(ConsData)[1:5]

# Model with Cholesky decompositon:
mod <- varcov(ConsData, vars = vars, type = "chol")

# Run model:
mod <- mod %>% runmodel

# Transform to GGM:
mod_trans <- transmod(mod, type = "ggm") %>% runmodel
# Note: runmodel often not needed

# Obtain thresholded GGM:
getmatrix(mod_trans, "omega", threshold = TRUE)

Run the code above in your browser using DataLab