View source: R/calculate_errors.R
calculate_errors | R Documentation |
This function calculates the Mean Squared Error (MSE) and relative error for factor loadings and uniqueness estimates obtained from factor analysis.
calculate_errors(data, A, D)
data |
Matrix of SFM data. |
A |
Matrix of true factor loadings. |
D |
Matrix of true uniquenesses. |
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. |
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.