我正在用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
答案 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)