R - partykit树的nodes()问题

时间:2018-03-01 10:54:38

标签: r party

我有与

类似的问题

how to get all terminal nodes - weight & response prediction 'ctree' in r

我想得到这样的结果。然而,在我的情况下,nodes() - 函数不能正常工作。我不明白为什么。

tree <- ctree(DV ~ IV, data = data)

nodes(tree, unique(where(tree))) 

当我运行它时,我总是得到以下错误:

Error in match.arg(data, choices = c("all", "organization", "endpoint",  : 
  'arg' must be NULL or a character vector

为了使功能有效,我该怎么做?

非常感谢你!

1 个答案:

答案 0 :(得分:0)

尝试使用ctree包的party功能:

library(party)
set.seed(1)
x <- rnorm(100)
y <- x+runif(100)
data <- data.frame(DV=y , IV=x)

tree <- party::ctree(DV ~ IV, data = data)
nodes(tree, unique(where(tree))) 

# [[1]]
# 3)*  weights = 19 

# [[2]]
# 6)*  weights = 26 

# [[3]]
# 9)*  weights = 19 

# [[4]]
# 8)*  weights = 19 

# [[5]]
# 5)*  weights = 17