gsspFactorm: High Dimensional Sparse Factor Analysis Model

Description Usage Arguments Value Note Author(s) References See Also Examples

View source: R/hello.R

Description

sparse factor analysis to extract latent linear factor and estimate row-sparse and entry-wise-sparse loading matrix.

Usage

1
  gsspFactorm(X, q=NULL, lambda1=nrow(X)^(1/4), lambda2=nrow(X)^(1/4))

Arguments

X

a n-by-p matrix, the observed data

q

an integer between 1 and p or NULL, default as NULL and automatically choose q by the eigenvalue ratio method.

lambda1

a non-negative number, the row-sparse penalty parameter, default as n^(1/4).

lambda2

a non-negative number, the entry-sparse penalty parameter, default as n^(1/4).

Value

return a list with class named fac, including following components:

hH

a n-by-q matrix, the extracted lantent factor matrix.

sphB

a p-by-q matrix, the estimated row-sparseloading matrix.

hB

a p-by-q matrix, the estimated loading matrix without penalty.

q

an integer between 1 and p, the number of factor extracted.

propvar

a positive number between 0 and 1, the explained propotion of cummulative variance by the q factors.

egvalues

a n-dimensional(n<=p) or p-dimensional(p<n) vector, the eigenvalues of sample covariance matrix.

Note

nothing

Author(s)

Liu Wei

References

Wei Liu, Huazhen Lin, Jin Liu (2020). Estimation and inference on high-dimensional sparse factor models.

See Also

factor, Factorm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  dat <- gendata(n = 300, p = 500)
  res <- gsspFactorm(dat$X)
  ccorFun(res$hH, dat$H0) # the smallest canonical correlation
  ## comparison of l2 norm
  par(mar=c(5,5,2,2), mfrow=c(1,2))
  plot(rowSums(dat$B0^2), type='o', ylab='l2B', main='True')
  l2B <- rowSums(res$sphB^2)
  plot(l2B, type='o', main='Est.')

  Bind <- ifelse(dat$B0==0, 0, 1)
  hBind <- ifelse(res$sphB==0, 0, 1)
  ## structure of loading matrix
  image(x=1:nrow(Bind), y= 1:ncol(Bind), z=Bind , col = 1:3,#hcl.colors(12, "YlOrRd",rev=F),
        ylab='columns', xlab='rows',cex.lab=1.8, cex.axis=1.6 )
  image(x=1:nrow(Bind), y= 1:ncol(Bind), z=hBind , col = 1:3,#hcl.colors(12, "YlOrRd",rev=F),
        ylab='columns', xlab='rows',cex.lab=1.8, cex.axis=1.6 )

  ## Select good penalty parameters
  dat <- gendata(n = 300, p = 200)
  res <- gsspFactorm(dat$X, lambda1=0.04*nrow(dat$X)^(1/4) ,lambda2=1*nrow(dat$X)^(1/4))
  ccorFun(res$hH, dat$H0) # the smallest canonical correlation

  ## comparison of l2 norm
  plot(rowSums(dat$B0^2), type='o', ylab='l2B', main='True')
  l2B <- rowSums(res$sphB^2)
  plot(l2B, type='o', main='Est.')

  ## comparison of structure of loading matrix
  Bind <- ifelse(dat$B0==0, 0, 1)
  hBind <- ifelse(res$sphB==0, 0, 1)
  image(x=1:nrow(Bind), y= 1:ncol(Bind), z=Bind , col = 1:3,#hcl.colors(12, "YlOrRd",rev=F),
        ylab='columns', xlab='rows',cex.lab=1.8, cex.axis=1.6, main='True')
  image(x=1:nrow(Bind), y= 1:ncol(Bind), z=hBind , col = 1:3,#hcl.colors(12, "YlOrRd",rev=F),
        ylab='columns', xlab='rows',cex.lab=1.8, cex.axis=1.6, main='Est.' )

feiyoung/SpagFainfer documentation built on April 4, 2020, 5:20 p.m.