How to create factors from factanal?

前端 未结 4 1855
旧巷少年郎
旧巷少年郎 2021-02-03 11:12

When performing a factor analysis using factanal the usual result is some loadings table plus several other information. Is there a direct way to use these loadings to create a

4条回答
  •  生来不讨喜
    2021-02-03 11:46

    A similar question was asked on Psych SE.

    There, I provide a function in case you want to generate factor scores for new data.


    I wrote the following function that takes the fit object returned by factanal and new data that you provide (e.g., a data frame or matrix with identical variable names).

    score_new_data <- function(fit, data) {
        z <- as.matrix(scale(data[,row.names(fit$correlation)]))
        z %*% solve(fit$correlation, fit$loadings)
    }
    

    So for example,

    bfi <- na.omit(bfi)
    variables <- c("A1", "A2", "A3", "A4", "C1", "C2", "C3", "C4")
    data <- bfi[,variables]
    fit <- factanal(data, factors = 2, scores = "regression", rotation = "varimax")
    

    This is a typical factor analysis.

    And now supply some new data along with the fit of the factor analysis:

    score_new_data(fit, data[1:5, ])
    

    And it generates the following:

    > score_new_data(fit, data[1:5, ])
             Factor1    Factor2
    61623  1.5022427  0.5457393
    61629 -0.6817812 -0.9755466
    61634 -0.2901822  0.1051234
    61640  0.5429929 -0.4955180
    61661 -1.0732722  0.8202019
    

提交回复
热议问题