Learn R Programming

SFM (version 0.2.1)

calculate_errors: calculate_errors Function

Description

This function calculates the Mean Squared Error (MSE) and relative error for factor loadings and uniqueness estimates obtained from factor analysis.

Usage

calculate_errors(data, A, D)

Value

A named vector containing:

MSEA

Mean Squared Error for factor loadings.

MSED

Mean Squared Error for uniqueness estimates.

LSA

Relative error for factor loadings.

LSD

Relative error for uniqueness estimates.

Arguments

data

Matrix of SFM data.

A

Matrix of true factor loadings.

D

Matrix of true uniquenesses.

Examples

Run this code
set.seed(123) # For reproducibility
# Define dimensions
n <- 10  # Number of samples
p <- 5   # Number of factors

# Generate matrices with compatible dimensions
A <- matrix(runif(p * p, -1, 1), nrow = p)  # Factor loadings matrix (p x p)
D <- diag(runif(p, 1, 2))  # Uniquenesses matrix (p x p)
data <- matrix(runif(n * p), nrow = n)  # Data matrix (n x p)

# Calculate errors
errors <- calculate_errors(data, A, D)
print(errors)

Run the code above in your browser using DataLab