mgm_error_metrics: MGM Error Metrics

View source: R/mgm_error_metrics.R

mgm_error_metricsR Documentation

MGM Error Metrics

Description

Fits a Mixed Graphical Model and extracts prediction error metrics.

Usage

mgm_error_metrics(data, type, level, k = 2)

Arguments

data

Data frame or matrix with the data.

type

Character vector of variable types ("g", "c", "p").

level

Integer vector of variable levels.

k

Order of interactions (default: 2).

Value

A list with the node predictability of the model: errorCon, a data frame with the RMSE and R2 of the continuous variables; errorCat, a data frame with the accuracy (CC) and normalized accuracy (nCC) of the categorical variables; and, when all variables are of the same kind, a named vector R2 or nCC ready to be used as the pie argument of qgraph.

Examples

set.seed(123)
n <- 300
f1 <- rnorm(n)
f2 <- 0.3 * f1 + rnorm(n)
items <- data.frame(
  sapply(1:4, function(i) 0.7 * f1 + rnorm(n, 0, 0.7)),
  sapply(1:4, function(i) 0.7 * f2 + rnorm(n, 0, 0.7))
)
names(items) <- c(paste0("A", 1:4), paste0("B", 1:4))

errors <- mgm_error_metrics(items, type = rep("g", 8), level = rep(1, 8))
errors$errorCon

InterconectaR documentation built on Oct. 16, 2026, 1:06 a.m.