Package 'LFM'

Title: Laplace Factor Model Analysis and Evaluation
Description: Enables the generation of Laplace factor models across diverse Laplace distributions and facilitates the application of Sparse Online Principal Component (SOPC), Incremental Principal Component (IPC), Parallel Principal Component (PPC), Sparse Approximate Principal Component (SAPC), Standard Principal Component (SPC), and Farm Test methods to these models. Evaluates the efficacy of these methods within the context of Laplace factor models by scrutinizing parameter estimation accuracy, mean square error, and the degree of sparsity.
Authors: Guangbao Guo [aut, cre], Siqi Liu [aut]
Maintainer: Guangbao Guo <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-11-20 05:25:55 UTC
Source: https://github.com/cran/LFM

Help Index


Apply the Farmtest method to the Laplace factor model

Description

This function simulates data from a Lapalce factor model and applies the FarmTest for multiple hypothesis testing. It calculates the false discovery rate (FDR) and power of the test.

Usage

Ftest_LFM(data, p1)

Arguments

data

A matrix or data frame of simulated or observed data from a Laplace factor model.

p1

The proportion of non-zero hypotheses.

Value

A list containing the following elements:

FDR

The false discovery rate, which is the proportion of false positives among all discoveries (rejected hypotheses).

Power

The statistical power of the test, which is the probability of correctly rejecting a false null hypothesis.

PValues

A vector of p-values associated with each hypothesis test.

RejectedHypotheses

The total number of hypotheses that were rejected by the FarmTest.

Examples

library(LaplacesDemon)
library(MASS)
n=1000
p=10
m=5
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)
lanor <- rlaplace(n*p,0,1)
epsilon=matrix(lanor,nrow=n)
D=diag(t(epsilon)%*%epsilon)
data=mu+F%*%t(A)+epsilon
p1=40
results <- Ftest_LFM(data, p1)
print(results$FDR)
print(results$Power)

Apply the IPC method to the Laplace factor model

Description

This function performs Incremental Principal Component Analysis (IPC) on the provided data. It updates the estimated factor loadings and uniquenesses as new data points are processed, calculating mean squared errors and loss metrics for comparison with true values.

Usage

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

Arguments

data

The data used in the IPC analysis.

m

The number of common factors.

A

The true factor loadings matrix.

D

The true uniquenesses matrix.

p

The number of variables.

Value

A list of metrics including:

Ai

Estimated factor loadings updated during the IPC analysis, a matrix of estimated factor loadings.

Di

Estimated uniquenesses updated during the IPC analysis, a vector of estimated uniquenesses corresponding to each variable.

MSESigmaA

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

MSESigmaD

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

LSigmaA

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

LSigmaD

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

Examples

library(SOPC)
library(LaplacesDemon)
library(MASS)
n=1000
p=10
m=5
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)
lanor <- rlaplace(n*p,0,1)
epsilon=matrix(lanor,nrow=n)
D=diag(t(epsilon)%*%epsilon)
data=mu+F%*%t(A)+epsilon
results <- IPC_LFM(data, m, A, D, p)
print(results)

Generate Laplace factor models

Description

The function is to generate Laplace factor model data. The function supports various distribution types for generating the data, including: - 'truncated_laplace': Truncated Laplace distribution - 'log_laplace': Univariate Symmetric Log-Laplace distribution - 'Asymmetric Log_Laplace': Log-Laplace distribution - 'Skew-Laplace': Skew-Laplace distribution

Usage

LFM(n, p, m, distribution_type)

Arguments

n

An integer specifying the sample size.

p

An integer specifying the sample dimensionality or the number of variables.

m

An integer specifying the number of factors in the model.

distribution_type

A character string indicating the type of distribution to use for generating the data.

Value

A list containing the following elements:

data

A numeric matrix of the generated data.

A

A numeric matrix representing the factor loadings.

D

A numeric matrix representing the uniquenesses, which is a diagonal matrix.

Examples

library(MASS)
library(matrixcalc)
library(relliptical)
n <- 1000
p <- 10
m <- 5
sigma1 <- 1
sigma2 <- matrix(c(1,0.7,0.7,1), 2, 2)
distribution_type <- "truncated_laplace"
results <- LFM(n, p, m, distribution_type)
print(results)

Apply the PPC method to the Laplace factor model

Description

This function computes Projected Principal Component Analysis (PPC) for the provided input data, estimating factor loadings and uniquenesses. It calculates mean squared errors and loss metrics for the estimated values compared to true values.

Usage

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

Arguments

data

A matrix of input data.

m

The number of principal components.

A

The true factor loadings matrix.

D

The true uniquenesses matrix.

p

The number of variables.

Value

A list containing:

Ap

Estimated factor loadings.

Dp

Estimated uniquenesses.

MSESigmaA

Mean squared error for factor loadings.

MSESigmaD

Mean squared error for uniquenesses.

LSigmaA

Loss metric for factor loadings.

LSigmaD

Loss metric for uniquenesses.

Examples

library(SOPC)
library(LaplacesDemon)
library(MASS)
n=1000
p=10
m=5
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)
lanor <- rlaplace(n*p,0,1)
epsilon=matrix(lanor,nrow=n)
D=diag(t(epsilon)%*%epsilon)
data=mu+F%*%t(A)+epsilon
results <- PPC_LFM(data, m, A, D, p)
print(results)

Apply the SAPC method to the Laplace factor model

Description

This function calculates several metrics for the SAPC method, including the estimated factor loadings and uniquenesses, and various error metrics comparing the estimated matrices with the true matrices.

Usage

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

Arguments

data

The data used in the SAPC analysis.

m

The number of common factors.

A

The true factor loadings matrix.

D

The true uniquenesses matrix.

p

The number of variables.

Value

A list of metrics including:

Asa

Estimated factor loadings matrix obtained from the SAPC analysis.

Dsa

Estimated uniquenesses vector obtained from the SAPC analysis.

MSESigmaA

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

MSESigmaD

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

LSigmaA

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

LSigmaD

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

Examples

library(SOPC)
library(LaplacesDemon)
library(MASS)
n=1000
p=10
m=5
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)
lanor <- rlaplace(n*p,0,1)
epsilon=matrix(lanor,nrow=n)
D=diag(t(epsilon)%*%epsilon)
data=mu+F%*%t(A)+epsilon
results <- SAPC_LFM(data, m, A, D, p)
print(results)

Apply the SOPC method to the Laplace factor model

Description

This function calculates various metrics for the SOPC analysis on the Laplace factor model. It estimates the factor loadings and uniquenesses, and computes metrics such as mean squared error, loss metrics, and sparsity.

Usage

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

Arguments

data

A numeric matrix containing the data used in the SOPC analysis.

m

An integer specifying the number of subsets or common factors.

p

An integer specifying the number of variables in the data.

A

A numeric matrix representing the true factor loadings.

D

A numeric matrix representing the true uniquenesses.

Value

A list containing the following metrics:

Aso

Estimated factor loadings matrix.

Dso

Estimated uniquenesses matrix.

MSEA

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

MSED

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

LSA

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

LSD

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

tauA

Proportion of zero factor loadings in the estimated loadings matrix (Aso), representing the sparsity.

Examples

library(MASS)
library(SOPC)
library(matrixcalc)
library(LaplacesDemon)
n=1000
p=10
m=5
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)
lanor <- rlaplace(n*p,0,1)
epsilon=matrix(lanor,nrow=n)
D=diag(t(epsilon)%*%epsilon)
data=mu+F%*%t(A)+epsilon
results <- SOPC_LFM(data, m, p, A, D)
print(results)

Apply the SPC method to the Laplace factor model

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.

Usage

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

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.

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).

Examples

library(SOPC)
library(LaplacesDemon)
library(MASS)
n=1000
p=10
m=5
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)
lanor <- rlaplace(n*p,0,1)
epsilon=matrix(lanor,nrow=n)
D=diag(t(epsilon)%*%epsilon)
data=mu+F%*%t(A)+epsilon
results <- SPC_LFM(data, A, D, m, p)
print(results)