我想知道partkykit::ctree
函数是否会忽略具有非语法名称的变量,或者我是否遗漏了什么?
玩具示例:
myData<-data.frame(
Y = factor(rep(LETTERS[1:3], each=10)),
x1 = 1:30,
x2 = c(1:10,2:11,3:12)
)
显然x1
是最好的“预测器” Y
:
ctree(Y~., data=myData)
Model formula:
Y ~ x1 + x2
Fitted party:
[1] root
| [2] x1 <= 10: A (n = 10, err = 0,0%)
| [3] x1 > 10
| | [4] x1 <= 20: B (n = 10, err = 0,0%)
| | [5] x1 > 20: C (n = 10, err = 0,0%)
Number of inner nodes: 2
Number of terminal nodes: 3
但是当我将其名称更改为非语法名称时,它似乎在树构造过程中被忽略了:
myData<-data.frame(
Y = factor(rep(LETTERS[1:3], each=10)),
`x 1` = 1:30,
x2 = c(1:10,2:11,3:12),
check.names = F
)
ctree(Y~., data=myData)
Model formula:
Y ~ `x 1` + x2
Fitted party:
[1] root: A (n = 30, err = 66,7%)
Number of inner nodes: 0
Number of terminal nodes: 1
你能建议任何方法来克服这种行为('因为我真的 - 真的 - 真的希望x 1
用作一个名字,不要问为什么)?