【问题标题】:Adding Factor Scores to the Original Dataset将因子分数添加到原始数据集
【发布时间】:2011-07-27 09:38:46
【问题描述】:

我运行因子分析并生成了 5 个因子。现在,我想在原始数据集中添加这些因素来运行回归,使这些因素使用自变量。谁能告诉我该怎么做?我用于因子分析的代码如下:

result.1<-subset(result,select=c(17:27))
fa.parallel(result.1)
View(result.1)
result.2<-factanal(result.1,factors=5,rotation="promax")
print(result.2)
print(result.2, digits = 2, cutoff = .2, sort = TRUE)
colnames(result.2$loadings)<-c("Fac_1","Fac_2","Fac_3","Fac_4","Fac_5")
print(loadings(result.2), digits = 2, cutoff = .2, sort = TRUE)

我尝试使用cbind 来获取因子的新变量列,但不幸的是它不起作用。

result.fac<-cbind(result,result.2)

问候, 阿里

【问题讨论】:

  • 请粘贴dput(result)的输出。在提出新问题之前,请返回并接受您之前问题的一些答案。

标签: r


【解决方案1】:

您必须将由 factanal 和 cbind 计算的分数保存到原始数据集中。例如:

data <- mtcars
f <- factanal(data, factors=5, rotation="promax", scores="regression")
data <- cbind(data, f$scores)

【讨论】:

    【解决方案2】:

    您可能有一些缺失的数据导致因子得分矩阵中的行缺失。 您需要匹配行名,如下所示:

    scores <- result.2$scores
    result.fac <- cbind(result[as.integer(rownames(scores)),],scores)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 2023-01-16
      • 2014-06-06
      • 2022-11-18
      • 1970-01-01
      • 2016-08-31
      相关资源
      最近更新 更多