Fit the covariate-augumented generalized factor model

CMGFM(
  XList,
  Z,
  types,
  numvarmat,
  q = 15,
  Alist = NULL,
  init = c("LFM", "GFM", "random"),
  maxIter = 30,
  epsELBO = 1e-08,
  verbose = TRUE,
  add_IC_iter = FALSE,
  seed = 1
)

Arguments

XList

a list consisting of multiple matrices in which each matrix has the same type of values, i.e., continuous, or count, or binomial/binary values.

Z

a matrix, the fixed-dimensional covariate matrix with control variables.

types

a string vector, specify the variable type in each matrix in XList;

numvarmat

a length(types)-by-d matrix, specify the number of variables in modalities that belong to the same type.

q

an optional string, specify the number of factors; default as 15.

Alist

an optional vector, the offset for each unit; default as full-zero vector.

init

an optional character, specify the method in initialization.

maxIter

the maximum iteration of the VEM algorithm. The default is 30.

epsELBO

an optional positive value, tolerance of relative variation rate of the evidence lower bound value, default as '1e-8'.

verbose

a logical value, whether output the information in iteration.

add_IC_iter

a logical value, add the identifiability condition in iterative algorithm or add it after algorithm converges; default as FALSE.

seed

an integer, set the random seed in initialization, default as 1;

Value

return a list including the following components:

  • betaf - the estimated regression coefficient vector for each modality;

  • Bf - the estimated loading matrix for each modality;

  • M - the estimated modality-shared factor matrix;

  • Xif - the estimated modality-specified factor vector;

  • S - the estimated covariance matrix of modality-shared latent factors;

  • Om - the posterior variance of modality-specified latent factors;

  • muf - the estimated intercept vector for each modality;

  • Sigmam - the variance of modality-specified factors;

  • invLambdaf - the inverse of the estimated variances of error for each modality.

  • ELBO - the ELBO value when algorithm stops;

  • ELBO_seq - the sequence of ELBO values.

  • time_use - the running time in model fitting;

Details

None

References

None

See also

None

Examples

pveclist <- list('gaussian'=c(50, 150),'poisson'=c(50, 150),
   'binomial'=c(100,60))
q <- 6
sigmavec <- rep(1,3)
pvec <- unlist(pveclist)
datlist <- gendata_cmgfm(pveclist = pveclist, seed = 1, n = 300,d = 3,
                         q = q, rho = rep(1,length(pveclist)), rho_z=0.2,
                         sigmavec=sigmavec, sigma_eps=1)
XList <- datlist$XList
Z <- datlist$Z
numvarmat <- datlist$numvarmat
types <- datlist$types
rlist <- CMGFM(XList, Z, types=types, numvarmat, q=q)
#> iter = 2, ELBO= 1991125.056475, dELBO=1.000000 
#> iter = 3, ELBO= 2005063.871790, dELBO=0.007000 
#> iter = 4, ELBO= 2010542.767770, dELBO=0.002733 
#> iter = 5, ELBO= 2013223.740359, dELBO=0.001333 
#> iter = 6, ELBO= 2014945.775650, dELBO=0.000855 
#> iter = 7, ELBO= 2016228.099702, dELBO=0.000636 
#> iter = 8, ELBO= 2017258.673090, dELBO=0.000511 
#> iter = 9, ELBO= 2018123.186985, dELBO=0.000429 
#> iter = 10, ELBO= 2018867.740559, dELBO=0.000369 
#> iter = 11, ELBO= 2019520.570983, dELBO=0.000323 
#> iter = 12, ELBO= 2020100.677428, dELBO=0.000287 
#> iter = 13, ELBO= 2020621.729760, dELBO=0.000258 
#> iter = 14, ELBO= 2021094.053165, dELBO=0.000234 
#> iter = 15, ELBO= 2021525.743440, dELBO=0.000214 
#> iter = 16, ELBO= 2021923.351548, dELBO=0.000197 
#> iter = 17, ELBO= 2022292.338348, dELBO=0.000182 
#> iter = 18, ELBO= 2022637.400259, dELBO=0.000171 
#> iter = 19, ELBO= 2022962.720218, dELBO=0.000161 
#> iter = 20, ELBO= 2023272.171344, dELBO=0.000153 
#> iter = 21, ELBO= 2023569.470842, dELBO=0.000147 
#> iter = 22, ELBO= 2023858.213468, dELBO=0.000143 
#> iter = 23, ELBO= 2024141.525295, dELBO=0.000140 
#> iter = 24, ELBO= 2024420.678070, dELBO=0.000138 
#> iter = 25, ELBO= 2024692.109344, dELBO=0.000134 
#> iter = 26, ELBO= 2024946.637220, dELBO=0.000126 
#> iter = 27, ELBO= 2025178.764916, dELBO=0.000115 
#> iter = 28, ELBO= 2025392.822741, dELBO=0.000106 
#> iter = 29, ELBO= 2025594.259740, dELBO=0.000099 
#> iter = 30, ELBO= 2025785.510378, dELBO=0.000094 
str(rlist)
#> List of 14
#>  $ betaf     :List of 6
#>   ..$ : num [1:3, 1] -1.318 0.369 -1.637
#>   ..$ : num [1:3, 1] 3.28 0.622 -1.68
#>   ..$ : num [1:3, 1] 0.568 0.856 0.306
#>   ..$ : num [1:3, 1] -2.71 -1.21 -2.85
#>   ..$ : num [1:3, 1] 0.627 0.491 -0.45
#>   ..$ : num [1:3, 1] -0.19927 -0.01962 -0.00376
#>  $ Bf        :List of 6
#>   ..$ : num [1:50, 1:6] 5.501 1.407 1.471 1.556 0.113 ...
#>   ..$ : num [1:150, 1:6] 0.774 1.134 0.976 -1.247 2.009 ...
#>   ..$ : num [1:50, 1:6] 4.179 0.368 -4.883 4.432 -0.168 ...
#>   ..$ : num [1:150, 1:6] 2.99 -1.114 -0.153 2.92 1.78 ...
#>   ..$ : num [1:100, 1:6] 0.5797 -0.0761 0.5203 0.6216 0.1543 ...
#>   ..$ : num [1:60, 1:6] 1.93 1.34 1.99 1.76 1.41 ...
#>  $ M         : num [1:300, 1:6] -0.1705 0.0344 -0.2769 -0.1704 0.2217 ...
#>  $ Xif       :List of 6
#>   ..$ : num [1:300, 1] -0.659 0.379 -0.804 0.937 0.328 ...
#>   ..$ : num [1:300, 1] 0.749 -0.972 1.975 -0.416 1.916 ...
#>   ..$ : num [1:300, 1] -1.0817 0.117 -1.3592 0.5027 0.0489 ...
#>   ..$ : num [1:300, 1] 0.0807 -1.8632 0.8699 -1.2104 0.5942 ...
#>   ..$ : num [1:300, 1] -0.323 -0.341 -0.4353 -0.0484 -0.3411 ...
#>   ..$ : num [1:300, 1] -0.000436 0.001818 -0.001396 0.003723 -0.001323 ...
#>  $ S         : num [1:6, 1:6] 0.000717 -0.001078 0.000102 0.000156 -0.000174 ...
#>  $ Om        : num [1:2, 1:3] 0.018736 0.000697 0.0159 0.00381 0.002571 ...
#>  $ muf       :List of 6
#>   ..$ : num [1:50, 1] 0.248 0.229 0.239 -0.098 0.743 ...
#>   ..$ : num [1:150, 1] -0.122 -0.436 0.187 -0.125 1.033 ...
#>   ..$ : num [1:50, 1] 0.175 0.746 0.338 0.472 0.321 ...
#>   ..$ : num [1:150, 1] 1.36 1.13 1.19 1.3 1.34 ...
#>   ..$ : num [1:100, 1] 0.218 0.215 0.353 0.361 0.118 ...
#>   ..$ : num [1:60, 1] -0.0528 -0.1754 -0.224 0.0372 -0.1882 ...
#>  $ Sigmam    : num [1:2, 1:3] 0.514 3.051 0.572 3.513 0.19 ...
#>  $ invLambdaf:List of 6
#>   ..$ : num [1:50, 1] 0.999 0.983 1.048 1.09 1.058 ...
#>   ..$ : num [1:150, 1] 0.975 1.047 0.95 0.918 0.94 ...
#>   ..$ : num [1:50, 1] 0.916 1.295 0.902 1.415 1.256 ...
#>   ..$ : num [1:150, 1] 1.32 1.41 1.12 1.01 1.03 ...
#>   ..$ : num [1:100, 1] 3.85 3.68 4.21 3.86 3.52 ...
#>   ..$ : num [1:60, 1] 3.46 3.3 3.42 3.6 3.44 ...
#>  $ ELBO      : num 2025786
#>  $ dELBO     : num 191
#>  $ ELBO_seq  : num [1:29] 1991125 2005064 2010543 2013224 2014946 ...
#>  $ numvarmat : num [1:3, 1:2] 50 50 100 150 150 60
#>   ..- attr(*, "dimnames")=List of 2
#>   .. ..$ : chr [1:3] "gaussian" "poisson" "binomial"
#>   .. ..$ : NULL
#>  $ time_use  : Named num 0.26
#>   ..- attr(*, "names")= chr "elapsed"