-
Notifications
You must be signed in to change notification settings - Fork 29
EFA with Mixed Data Types
Mattan S. Ben-Shachar edited this page Jul 27, 2021
·
1 revision
library(psych)
dat <- mtcars[c("mpg", "disp", "hp", "drat", "wt", "qsec", "vs", "am", "gear")] |> na.omit()
mixedCor(dat,
c = c("mpg", "disp", "hp", "drat", "wt", "qsec"),
p = c("gear"),
d = c("am", "vs"))
#> Call: mixedCor(data = dat, c = c("mpg", "disp", "hp", "drat", "wt",
#> "qsec"), p = c("gear"), d = c("am", "vs"))
#> mpg disp hp drat wt qsec vs am gear
#> mpg 1.00
#> disp -0.85 1.00
#> hp -0.78 0.79 1.00
#> drat 0.68 -0.71 -0.45 1.00
#> wt -0.87 0.89 0.66 -0.71 1.00
#> qsec 0.42 -0.43 -0.71 0.09 -0.17 1.00
#> vs 0.82 -0.88 -0.90 0.55 -0.69 0.92 1.00
#> am 0.75 -0.74 -0.30 0.89 -0.86 -0.29 0.26 1.00
#> gear 0.55 -0.63 -0.14 0.80 -0.66 -0.24 0.32 1.00 1.00
efa <- fa(dat, nfactors = 3,
fm = "pa", rotate = "oblimin",
cor = "mixed") # <<<<<< this
I know nothing about cars, so maybe this does make sense?
parameters::model_parameters(efa, sort = TRUE, threshold = 0.45)
#> # Rotated loadings from Factor Analysis (oblimin-rotation)
#>
#> Variable | PA1 | PA2 | PA3 | Complexity | Uniqueness
#> --------------------------------------------------------
#> wt | 0.89 | | | 1.03 | 0.11
#> mpg | -0.81 | | | 1.12 | 0.13
#> hp | 0.78 | | | 1.84 | 0.13
#> am | -0.71 | | 0.54 | 2.42 | -0.20
#> disp | 0.65 | | | 1.77 | 0.09
#> vs | | 0.98 | | 1.21 | -0.19
#> qsec | | 0.96 | | 1.05 | 0.04
#> gear | | | 1.03 | 1.01 | -0.04
#> drat | | | 0.59 | 1.74 | 0.27
#>
#> The 3 latent factors (oblimin rotation) accounted for 96.44% of the total variance of the original data (PA1 = 41.80%, PA2 = 28.81%, PA3 = 25.82%).
head(efa$scores)
#> PA1 PA2 PA3
#> Mazda RX4 -0.7132604 -1.1436652 0.6883296
#> Mazda RX4 Wag -0.5945421 -1.0484639 0.6801836
#> Datsun 710 -1.8079669 0.9292450 1.1463418
#> Hornet 4 Drive -0.3823838 1.4346867 -0.8482820
#> Hornet Sportabout 0.9090902 -0.7456465 -1.1785893
#> Valiant -0.3670598 1.6176777 -0.7955352