Learn R Programming

TFM (version 0.3.0)

SPC_TFM: Sparse Principal Component Analysis

Description

This function performs Sparse Principal Component Analysis (SPC) on the input data. It estimates factor loadings and uniquenesses while calculating mean squared errors and loss metrics for comparison with true values. Additionally, it computes the proportion of zero factor loadings.

Usage

SPC_TFM(data, A, D, m, p)

Value

A list containing:

As

Estimated factor loadings, a matrix of estimated factor loadings from the SPC analysis.

Ds

Estimated uniquenesses, a vector of estimated uniquenesses corresponding to each variable.

MSESigmaA

Mean squared error of the estimated factor loadings (As) compared to the true loadings (A).

MSESigmaD

Mean squared error of the estimated uniquenesses (Ds) compared to the true uniquenesses (D).

LSigmaA

Loss metric for the estimated factor loadings (As), indicating the relative error compared to the true loadings (A).

LSigmaD

Loss metric for the estimated uniquenesses (Ds), indicating the relative error compared to the true uniquenesses (D).

tau

Proportion of zero factor loadings in the estimated loadings matrix (As).

Arguments

data

The data used in the SPC analysis.

A

The true factor loadings matrix.

D

The true uniquenesses matrix.

m

The number of common factors.

p

The number of variables.

Examples

Run this code
library(MASS)
library(relliptical)
library(SOPC)

SPC_MSESigmaA <- c()
SPC_MSESigmaD <- c()
SPC_LSigmaA <- c()
SPC_LSigmaD <- c()
SPC_tau <- c()

p <- 10
m <- 5
n <- 2000

mu <- t(matrix(rep(runif(p, 0, 1000), n), p, n))
mu0 <- as.matrix(runif(m, 0))
sigma0 <- diag(runif(m, 1))
F <- matrix(mvrnorm(n, mu0, sigma0), nrow = n)
A <- matrix(runif(p * m, -1, 1), nrow = p)

lower <- c(rep(-0.5, p - 3), -5, -5, -Inf)
upper <- c(rep(0.5, p - 3), 5, 5, Inf)
Sigma <- diag(runif(p, 0, 1))
mut <- runif(p, 0, 10)

trnor <- rtelliptical(n, mut, Sigma, lower, upper, dist = "Normal")
epsilon <- matrix(trnor, nrow = n)
D <- Sigma

data <- mu + F %*% t(A) + epsilon

result <- SPC_TFM(data, A, D, m, p)

SPC_MSESigmaA <- c(SPC_MSESigmaA, result$MSESigmaA)
SPC_MSESigmaD <- c(SPC_MSESigmaD, result$MSESigmaD)
SPC_LSigmaA <- c(SPC_LSigmaA, result$LSigmaA)
SPC_LSigmaD <- c(SPC_LSigmaD, result$LSigmaD)
SPC_tau <- c(SPC_tau, result$tau)

data_G <- data.frame(n = n,
                     MSEA = SPC_MSESigmaA,
                     MSED = SPC_MSESigmaD,
                     LSA = SPC_LSigmaA,
                     LSD = SPC_LSigmaD,
                     tau = SPC_tau)

print(data_G)

Run the code above in your browser using DataLab