我正在使用包中的flexmixedruns
函数,当我尝试运行该函数fpc
时得到一个
。flexmix error
我的数据集既有连续数据又有分类数据,但我的大多数分类数据只有 2 个级别("Y"
或"N"
)。我的一些变量有几个级别。我想知道我是否收到错误,因为该函数将我所有的分类变量都视为多项分布。
有没有人有使用此功能的经验?
可重现的例子
##### check for fpc package
required.packages <- c("fpc")
new.packages <-
required.packages[!(required.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
rm(required.packages, new.packages)
library(fpc)
##### create data set
df <- matrix(
data=c("widget1", "widget2", "widget3", "widget4", "widget5", "widget6",
58, 18, 31, 130, 40, 31,
70, 19, 44, 120, 57, 50,
"1E6", "1E5", "1E4", "1E6", "1E5", "1E4",
"Y", "Y", "N", "N", "N", "Y",
"N", "Y", "N", "Y", "N", "Y"),
nrow=6, ncol=6)
df <- as.data.frame(x=df)
row.names(df) <- df[, 1]
df <- df[, -1]
colnames(df) <- c("cont1", "cont2", "multi1", "bin1", "bin2")
df$cont1 <- as.numeric(df$cont1)
df$cont2 <- as.numeric(df$cont2)
##### model
mdl <-
flexmixedruns(x=df, xvarsorted=TRUE, continuous=2, discrete=3, simruns=5,
n.cluster=3, recode=TRUE)
错误信息
Error in summary(flexout[[optimalk]]) :
error in evaluating the argument 'object' in selecting a method for function 'summary': Error in flexout[[optimalk]] : attempt to select less than one element