How to perform factor analysis in R language?
In R language, factor analysis is usually done using the principal component analysis (PCA) or factor analysis (FA) functions. Here is a simple example code to perform factor analysis:
# 导入数据
data <- read.csv("data.csv")
# 创建一个因子分析模型
fa_model <- factanal(data, factors=3)
# 打印因子负荷
print(fa_model$loadings)
# 打印解释的方差
print(fa_model$communalities)
# 打印因子得分
print(predict(fa_model))
In this example, we first import the data and then create a factor analysis model with 3 factors. We can examine the factor loadings using fa_model$loadings, the explained variance using fa_model$communalities, and see the factor scores by using predict(fa_model).
By using the code above, you can perform factor analysis in R and view the results. You can also adjust the factors parameter to change the number of factors.