在打印类别时,FactoMineR的摘要中的错误.FAMD

时间:2018-05-31 13:21:04

标签: r categories pca

我正在用FactoMineR做一个FAMD,用imputeFAMD处理NAs。 FAMD工作正常,但summary()在打印类别时会产生错误。有19个连续变量和2个变量变量。

library(FactoMineR)
library(missMDA)#handle missing values
n = c(2, 3, 5, 3, 4, 6, 7, 3, 7, 3, 7, 8, 11, 4, 13) 
s = c("aa", "bb", "cc", "aa", "bb", "cc", "aa", "bb", "cc", "aa", "bb", "cc", "aa", "bb", "cc") 
b = c(1, 4, NA, NA, 2, 1, 7, 1, 2, NA, NA, 2, 1, 7, NA) 
all = data.frame(n, s, b)
complete = imputeFAMD(all)
FAMDall = FAMD(all, tab.comp = complete)
summary(FAMDall, nbelements = Inf, ncp=4)

在连续变量之后,summary(FAMDall, nbelements = Inf, ncp=4)的输出停止如下:

Categories
Error in mat[, indice + nb.col * (0:(ncp - 1))] <- obj$cos2[1:nbelements,  : 
  number of items to replace is not a multiple of replacement length

1 个答案:

答案 0 :(得分:1)

问题似乎出现在tab.comp参数中。 FactoMineR上的?FAMD文档会询问imputeFAMD生成的整个对象,但您需要的是$tab.disj列表元素中的插补矩阵。请参阅?imputeFAMD中的示例部分。这应该有效:

n = c(2, 3, 5, 3, 4, 6, 7, 3, 7, 3, 7, 8, 11, 4, 13) 
s = c("aa", "bb", "cc", "aa", "bb", "cc", "aa", "bb", "cc", "aa", "bb", "cc", "aa", "bb", "cc") 
b = c(1, 4, NA, NA, 2, 1, 7, 1, 2, NA, NA, 2, 1, 7, NA) 
all = data.frame(n, s, b)
complete = imputeFAMD(all)
FAMDall = FAMD(all, tab.comp = complete$tab.disj)
summary(FAMDall, nbelements = Inf, ncp=4)