Nothing
#' @name FanPC.CoFM
#' @title FanPC estimation for the Copula Factor Model
#' @description Perform FanPC (eigen-structure thresholding) on CoFM data to estimate loadings (AF), uniquenesses (DF) and their errors.
#' @param data n×p data matrix (generated by \code{CoFM}).
#' @param m Number of latent factors.
#' @param A True p×m loading matrix (for error evaluation).
#' @param D True p×p uniqueness matrix (for error evaluation).
#' @param p Number of variables.
#' @return List with components
#' \item{AF}{Estimated loadings.}
#' \item{DF}{Estimated uniquenesses.}
#' \item{MSESigmaA, MSESigmaD, LSigmaA, LSigmaD}{Error metrics (same definition as FanPC.SFM).}
#' @examples
#' \donttest{
#' library(copula); library(MASS)
#' X <- CoFM(n=1000, p=10, m=5, theta=2, distribution_type="Clayton")
#' res <- FanPC.CoFM(X$data, m=5, X$A, diag(diag(X$D)), p=10)
#' print(res)
#' }
#' @export
#' @importFrom matrixcalc frobenius.norm
#' @importFrom stats cor
FanPC.CoFM <- function(data, m, A, D, p) {
if (!is.matrix(data)) data <- as.matrix(data)
X <- scale(data)
R <- cor(X)
eig <- eigen(R)
idx <- order(eig$values, decreasing = TRUE)[1:m]
AF <- eig$vectors[, idx] %*% diag(sqrt(eig$values[idx]))
h2 <- rowSums(AF^2)
DF <- diag(R - diag(h2))
MSESigmaA <- frobenius.norm(AF - A)^2 / (p^2)
MSESigmaD <- frobenius.norm(DF - D)^2 / (p^2)
LSigmaA <- frobenius.norm(AF - A)^2 / frobenius.norm(A)^2
LSigmaD <- frobenius.norm(DF - D)^2 / frobenius.norm(D)^2
list(AF = AF, DF = DF,
MSESigmaA = MSESigmaA, MSESigmaD = MSESigmaD,
LSigmaA = LSigmaA, LSigmaD = LSigmaD)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.