Skip to content

JozefRivest/factortable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

factortable

factortable is a versatile tool for summarizing exploratory factor analysis results in multiple formats. It allows flexible customization of included statistics and supports various table output formats. The goal of the package is to integrate seamlessly into workflows using functions and commands from the psych package. More information is available on the official CRAN repository.

The package automatically detects the estimation method and rotation technique used. Accordingly, columns containing factor loadings are named based on the estimation method (e.g., MLE, PA, MR). Additionally, if an oblique rotation is applied, the correlation between factors is displayed automatically.

By default, the basic output includes no customization, giving users the flexibility to tailor the table to their specific needs. Currently, the supported output formats include:

By default, the package uses the tinytable output format, due to its intuitive syntax and high degree of customizability. Moreover, the package has no external dependencies—except when saving tables as images—making it highly stable and less prone to conflicts or bugs caused by dependency issues.

To help users understand how these output formats can be used, here are some examples:

Tinytable

library(psych)
library(MPsychoR)

data("Rmotivation")
dat <- Rmotivation
vind <- grep("ext|int", colnames(Rmotivation))

dat1 <- dat[, vind]

cor_dat <- tetrachoric(dat1)
cor_dat$rho

model_fa <- fa(
  cor_dat$rho,
  nfactors = 2,
  rotate = "none",
  fm = "ml"
)

factortable(model_fa, output = "tinytable") |>
  style_tt(i = c(0, 18), bold = TRUE) # Making the top row and the "information" row bold

Tinytable

GT

library(psych)
library(MPsychoR)

data("Rmotivation")
dat <- Rmotivation
vind <- grep("ext|int", colnames(Rmotivation))

dat1 <- dat[, vind]

cor_dat <- tetrachoric(dat1)
cor_dat$rho

model_fa <- fa(
  cor_dat$rho,
  nfactors = 2,
  rotate = "none",
  fm = "ml"
)

factortable(model_fa, output = "gt") |>
  tab_caption("Adding a nice and insightful caption to the table") |>
  tab_source_note("Test for a footnote using a GT table output")

GT

Flextable

library(psych)
library(MPsychoR)

data("Rmotivation")
dat <- Rmotivation
vind <- grep("ext|int", colnames(Rmotivation))

dat1 <- dat[, vind]

cor_dat <- tetrachoric(dat1)
cor_dat$rho

not_colored <- c("Information", "SS loadings", "Proportion Var", "Proportion Explained")

factortable(model_fa, output = "data.frame") |>
  qflextable() |>
  color(~ ML1 >= 0.3 & !Items %in% not_colored, ~ML1, color = "orange", part = "body") |>
  color(~ ML2 >= 0.3 & !Items %in% not_colored, ~ML2, color = "red", part = "body") |>
  add_footer_lines("Here is a footer about the content of the table")

Flextable

LaTeX

Currently, the LaTeX output is managed through tinytable. Users are highly encouraged to read the documentation from tinytable and from tabularray. One thing to note is that tinytable offers already awesome customization options that can be applied before printing the LaTeX code.

library(psych)
library(MPsychoR)

data("Rmotivation")
dat <- Rmotivation
vind <- grep("ext|int", colnames(Rmotivation))

dat1 <- dat[, vind]

cor_dat <- tetrachoric(dat1)
cor_dat$rho

factortable(model_fa, output = "latex") # For a barebone output

factortable(model_fa, output = "tinytable") |>
  style_tt(i = c(0, 18), bold = TRUE) |> # Making the top row and the "information" row bold
  print("latex")

LaTeX

Barebone output:

\begin{table}
\centering
\begin{tblr}[         %% tabularray outer open
]                     %% tabularray outer close
{                     %% tabularray inner open
width={1\linewidth},
colspec={X[]X[]X[]X[]X[]X[]},
}                     %% tabularray inner close
\toprule
Items & ML1 & ML2 & Communality & Uniqueness & Complexity \\ \midrule %% TinyTableHeader
ext1 & 0.185 & 0.283 & 0.114 & 0.886 & 1.73 \\
ext2 & 0.177 & 0.219 & 0.08 & 0.92 & 1.92 \\
ext3 & 0.287 & 0.053 & 0.085 & 0.915 & 1.07 \\
ext4 & 0.235 & 0.626 & 0.447 & 0.553 & 1.28 \\
ext5 & 0.056 & -0.032 & 0.004 & 0.996 & 1.6 \\
ext6 & -0.002 & 0.062 & 0.004 & 0.996 & 1 \\
ext7 & 0.305 & 0.431 & 0.279 & 0.721 & 1.8 \\
ext8 & 0.086 & 0.908 & 0.832 & 0.168 & 1.02 \\
ext9 & 0.36 & 0.431 & 0.315 & 0.685 & 1.94 \\
ext10 & 0.127 & 0.593 & 0.368 & 0.632 & 1.09 \\
ext11 & 0.185 & 0.584 & 0.375 & 0.625 & 1.2 \\
ext12 & 0.157 & 0.766 & 0.611 & 0.389 & 1.08 \\
int1 & 0.817 & -0.172 & 0.697 & 0.303 & 1.09 \\
int2 & 0.722 & -0.133 & 0.539 & 0.461 & 1.07 \\
int3 & 0.804 & -0.175 & 0.678 & 0.322 & 1.09 \\
int4 & 0.736 & -0.065 & 0.546 & 0.454 & 1.02 \\
int5 & 0.881 & -0.148 & 0.798 & 0.202 & 1.06 \\
Information &  &  &  &  &  \\
SS loadings & 3.66 & 3.11 & NA & NA & NA \\
Proportion Var & 0.22 & 0.18 & NA & NA & NA \\
Proportion Explained & 0.54 & 0.46 & NA & NA & NA \\
\bottomrule
\end{tblr}
\end{table} 

Customized output:

\begin{table}
\centering
\begin{tblr}[         %% tabularray outer open
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]Q[]Q[]Q[]Q[]},
row{1,19}={}{cmd=\bfseries,},
}                     %% tabularray inner close
\toprule
Items & ML1 & ML2 & Communality & Uniqueness & Complexity \\ \midrule %% TinyTabl
eHeader
ext1 & 0.185 & 0.283 & 0.114 & 0.886 & 1.73 \\
ext2 & 0.177 & 0.219 & 0.08 & 0.92 & 1.92 \\
ext3 & 0.287 & 0.053 & 0.085 & 0.915 & 1.07 \\
ext4 & 0.235 & 0.626 & 0.447 & 0.553 & 1.28 \\
ext5 & 0.056 & -0.032 & 0.004 & 0.996 & 1.6 \\
ext6 & -0.002 & 0.062 & 0.004 & 0.996 & 1 \\
ext7 & 0.305 & 0.431 & 0.279 & 0.721 & 1.8 \\
ext8 & 0.086 & 0.908 & 0.832 & 0.168 & 1.02 \\
ext9 & 0.36 & 0.431 & 0.315 & 0.685 & 1.94 \\
ext10 & 0.127 & 0.593 & 0.368 & 0.632 & 1.09 \\
ext11 & 0.185 & 0.584 & 0.375 & 0.625 & 1.2 \\
ext12 & 0.157 & 0.766 & 0.611 & 0.389 & 1.08 \\
int1 & 0.817 & -0.172 & 0.697 & 0.303 & 1.09 \\
int2 & 0.722 & -0.133 & 0.539 & 0.461 & 1.07 \\
int3 & 0.804 & -0.175 & 0.678 & 0.322 & 1.09 \\
int4 & 0.736 & -0.065 & 0.546 & 0.454 & 1.02 \\
int5 & 0.881 & -0.148 & 0.798 & 0.202 & 1.06 \\
Information &  &  &  &  &  \\
SS loadings & 3.66 & 3.11 &  &  &  \\
Proportion Var & 0.22 & 0.18 &  &  &  \\
Proportion Explained & 0.54 & 0.46 &  &  &  \\
\bottomrule
\end{tblr}
\end{table} 

Custom latex

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors