install.packages("remotes")
::install_github("rdevito/MSFA")
remoteslibrary(MSFA)
1 Package Installation
I have this separate section to introduce the package installation because installing some packages requires extra efforts.
1.1 Stack FA, Ind FA, and BMSFA
The Stack FA, Ind FA, and BMSFA models are implemented in the MSFA
package, which is not available on CRAN. We can install it from GitHub using the remotes
package. We use sp_fa()
within the MSFA
package to fit the Stack FA and Ind FA model, and sp_msfa()
to fit the BMSFA model.
I edited the functions a bit so that sp_fa() and sp_msfa() can accept the scaling
and centering
arguments. So that we can only center the data without scaling it, or centering and scaling, or neither.
#devtools::install_github("Mavis-Liang/MSFA")
1.2 PFA
PFA does not provide any downloadable R packages and we need to download the R scripts from their GitHub repository, put them in the same directory as the main script, and source them for use.
We only need the three files: FBPFA-PFA.R
, FBPFA-PFA with fixed latent dim.R
, and PFA.cpp
, which can be found in https://github.com/royarkaprava/Perturbed-factor-models. The FBPFA-PFA.R
file contains the full Bayesian inference algorithm for the PFA model, directly set the latent dimensions equal to the dimensions or the original data. The FBPFA-PFA with fixed latent dim.R
file contains the same algorithm that requires to set numbers of common factors \(K\). We also notice that two version of the models are both PFA()
, and some functions in the FBPFA-PFA with fixed latent dim.R
file depends on the FBPFA-PFA.R
file. Therefore, since we want to run the dimension reduction version of the model, we must source the FBPFA-PFA.R
file first, and then source the FBPFA-PFA with fixed latent dim.R
file.
# Suppose the files are in the same directory as the main script
source("FBPFA-PFA.R")
source("FBPFA-PFA with fixed latent dim.R")
1.3 MOM-SS
::install("sparseMatrixStats") # Dependency
BiocManagerinstall.packages("mombf")
install.packages("devtools")
::install_github("AleAviP/BFR.BE")
devtoolslibrary(BFR.BE)
1.4 SUFA
To install SUFA on Linux, you need to also install extra dependencies like PROJ, sqlite3 and GDAL onto PATH. On Windows, you might need to do several updates, particularly the updates for terra. We can skip building the vignettes to save time, as it contains the computation of a large dataset.
::install_github("noirritchandra/SUFA", build_vignettes = FALSE)
devtoolslibrary(SUFA)
1.5 Tetris
Similar to PFA, Tetris does not provide any downloadable R packages and we need to download the R scripts from their GitHub repository, put them in the same directory as the main script, and source them for use. The R scripts can be found in https://github.com/igrabski/tetris/tree/main.
# Suppose the files are in the same directory as the main script
source("Tetris.R")
1.6 Other utility packages
library(tidyverse)
library(Matrix)#for the bdiag function