-
-
Notifications
You must be signed in to change notification settings - Fork 40
Closed
Description
The problem
There are many times you might want to run factor analysis from a correlation matrix rather than raw data. For example, secondary analysis of other's work. This is possible in psych::fa() e.g
raq_items <- discovr::raq |> dplyr::select(-id)
raq_poly <- correlation::correlation(raq_items, method = "polychoric")
raq_poly_mtx <- as.matrix(raq_poly) # store correlation matrix
raq_fa <- psych::fa(r = raq_poly_mtx, n.obs = 2571, nfactors = 4)
#> Loading required namespace: GPArotationCreated on 2025-06-26 with reprex v2.1.1
However, this doesn't work with factor_analysis() sdespite it being a wrapper for psych:fa(). Things I have tried:
- Pass the matrix direct to r so it filters through to
fa()
raq_items <- discovr::raq |> dplyr::select(-id)
raq_poly <- correlation::correlation(raq_items, method = "polychoric")
raq_poly_mtx <- as.matrix(raq_poly) # store correlation matrix
raq_fa <- parameters::factor_analysis(x = raq_items,
n = 4,
rotation = "oblimin",
r = raq_poly_mtx,
standardize = FALSE)
#> Error in is.na(n.obs) && (n.iter > 1): 'length = 59133' in coercion to 'logical(1)'Created on 2025-06-26 with reprex v2.1.1
- Assign the matrix to the
corargument
raq_items <- discovr::raq |> dplyr::select(-id)
raq_poly <- correlation::correlation(raq_items, method = "polychoric")
raq_poly_mtx <- as.matrix(raq_poly) # store correlation matrix
raq_fa <- parameters::factor_analysis(x = raq_items,
n = 4,
rotation = "oblimin",
cor = raq_poly_mtx,
standardize = FALSE)
#> Error in switch(cor, cor = {: EXPR must be a length 1 vectorCreated on 2025-06-26 with reprex v2.1.1
- Assign it directluy to
x
raq_fa <- parameters::factor_analysis(x = raq_poly_mtx,
n = 4,
rotation = "oblimin",
standardize = FALSE)
#> Error: object 'raq_poly_mtx' not foundCreated on 2025-06-26 with reprex v2.1.1
Solution
Make it work 😉
Metadata
Metadata
Assignees
Labels
No labels