【发布时间】:2019-11-03 08:08:31
【问题描述】:
对于我的研究,我想做多项逻辑逐步向前选择(尽管有缺点)。为此,我运行以下示例代码:
x1=sample(1:100,10,replace=T)
x2=sample(1:100,10,replace=T)
x3=sample(1:100,10,replace=T)
x4=sample(1:100,10,replace=T)
x5=sample(1:100,10,replace=T)
x=as.data.frame(cbind(x1,x2,x3,x4,x5))
y=as.data.frame(c(0,0,2,3,0,0,3,1,0,0))
xy=as.data.frame(cbind(x,y))
names(xy)[6]="y"
beststep=train(multinom(y~x1+x2+x3+x4+x5,data=xy), method="glmStepAIC", direction="forward", k=log(10))
这会导致以下错误:
Error: Please use column names for `x
数据框 xy 的列都已命名。这可能是什么问题以及如何解决?
【问题讨论】:
-
一般来说,
as.data.frame(cbind(...))是一种反模式。请改用data.frame(...)。在这种情况下,这并不重要,因为您的所有数据都是同一类型,但cbind()首先转换为矩阵,因此如果您混合字符串和数字(甚至整数和双精度)数据类型,cbind矩阵转换会搞砸。 -
没错,但不幸的是它并没有解决问题。