Skip to content

Running EFA from a correlation matrix #1118

@profandyfield

Description

@profandyfield

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: GPArotation

Created 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:

  1. 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

  1. Assign the matrix to the cor argument
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 vector

Created on 2025-06-26 with reprex v2.1.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 found

Created on 2025-06-26 with reprex v2.1.1

Solution

Make it work 😉

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions