Enhancement: `tab_fa` for presenting {psych} output with factor names
ClaudiuPapasteri opened this issue · comments
I love using sjPlot
for presenting nice tables, but I like to do the analyses using the original functions that are wrapped by sjPlot
. For example sjPlot::tab_fa()
nicely wraps psych::fa()
but does not return the fa
class object with all relevant info. Fortunately, sjPlot::tab_fa()
accepts these object and just outputs them in nice tables with one simple shortcoming: it renames the factors. This behaviour is hardcoded at line 332. We have argument var.labels
for item names. Simple fixes would be either to have an argument fac.labels
or just store factor names for fa
class objects and print those.
library(psych)
library(sjPlot)
efa_bfi <- psych::fa(na.omit(psych::bfi[, 1:25]), nfactors = 6, rotate = "oblimin")
#> Loading required namespace: GPArotation
efa_bfi$loadings
#>
#> Loadings:
#> MR2 MR1 MR3 MR5 MR4 MR6
#> A1 -0.106 -0.563 0.288
#> A2 0.701
#> A3 -0.103 0.628 0.120
#> A4 0.191 0.410 -0.126 0.130
#> A5 -0.166 -0.187 0.460 0.108 0.218
#> C1 0.548 0.191
#> C2 0.142 0.674 0.184
#> C3 0.562
#> C4 -0.675 0.291
#> C5 0.153 0.176 -0.553 0.101
#> E1 -0.136 0.600 0.101 -0.130
#> E2 0.682
#> E3 -0.332 0.153 0.386 0.240
#> E4 -0.532 0.219 0.278
#> E5 0.150 -0.393 0.263 0.242
#> N1 0.848
#> N2 0.833
#> N3 0.674 0.135
#> N4 0.430 0.433 -0.137
#> N5 0.437 0.238 0.174 -0.128 0.149
#> O1 0.566
#> O2 0.116 -0.420 0.305
#> O3 0.655
#> O4 0.355 0.152 0.364
#> O5 -0.491 0.351
#>
#> MR2 MR1 MR3 MR5 MR4 MR6
#> SS loadings 2.391 1.919 1.992 1.775 1.640 0.704
#> Proportion Var 0.096 0.077 0.080 0.071 0.066 0.028
#> Cumulative Var 0.096 0.172 0.252 0.323 0.389 0.417
sjPlot::tab_fa(efa_bfi)
#> Cronbach's Alpha can only be calculated when having a data frame with each component / variable as column.
Factor 1 | Factor 2 | Factor 3 | Factor 4 | Factor 5 | Factor 6 | |
---|---|---|---|---|---|---|
A1 | 0.09 | -0.11 | 0.07 | -0.56 | 0.03 | 0.29 |
A2 | 0.05 | -0.04 | 0.07 | 0.70 | -0.00 | -0.07 |
A3 | -0.03 | -0.10 | 0.03 | 0.63 | 0.06 | 0.12 |
A4 | -0.07 | -0.08 | 0.19 | 0.41 | -0.13 | 0.13 |
A5 | -0.17 | -0.19 | 0.01 | 0.46 | 0.11 | 0.22 |
C1 | 0.02 | 0.07 | 0.55 | -0.04 | 0.19 | 0.09 |
C2 | 0.07 | 0.14 | 0.67 | 0.02 | 0.10 | 0.18 |
C3 | 0.01 | 0.06 | 0.56 | 0.07 | -0.05 | 0.06 |
C4 | 0.05 | 0.08 | -0.67 | -0.05 | 0.04 | 0.29 |
C5 | 0.15 | 0.18 | -0.55 | -0.00 | 0.10 | 0.04 |
E1 | -0.14 | 0.60 | 0.10 | -0.13 | -0.08 | 0.09 |
E2 | 0.05 | 0.68 | -0.03 | -0.08 | -0.07 | 0.02 |
E3 | 0.01 | -0.33 | 0.00 | 0.15 | 0.39 | 0.24 |
E4 | -0.05 | -0.53 | 0.03 | 0.22 | 0.01 | 0.28 |
E5 | 0.15 | -0.39 | 0.26 | 0.05 | 0.24 | 0.05 |
N1 | 0.85 | -0.10 | 0.00 | -0.07 | -0.05 | 0.00 |
N2 | 0.83 | -0.05 | 0.02 | -0.04 | 0.00 | -0.08 |
N3 | 0.67 | 0.14 | -0.03 | 0.08 | 0.03 | 0.08 |
N4 | 0.43 | 0.43 | -0.14 | 0.08 | 0.09 | 0.06 |
N5 | 0.44 | 0.24 | -0.00 | 0.17 | -0.13 | 0.15 |
O1 | -0.05 | -0.03 | 0.07 | -0.04 | 0.57 | 0.07 |
O2 | 0.12 | -0.02 | -0.08 | 0.09 | -0.42 | 0.31 |
O3 | -0.01 | -0.10 | 0.01 | 0.04 | 0.66 | 0.04 |
O4 | 0.08 | 0.35 | -0.03 | 0.15 | 0.36 | -0.01 |
O5 | 0.04 | -0.05 | -0.03 | -0.03 | -0.49 | 0.35 |
Created on 2023-05-18 with reprex v2.0.2