2012-12-19 35 views
3

下面是我可以用來列出所有終端節點的權重:但我怎樣才能添加一些代碼來獲得響應預測以及每個終端的權重節點ID:如何獲得所有終端節點 - 權重和響應預測'ctree'in r

說,我希望我的輸出看起來像這樣

enter image description here

- 這裏下面是我迄今爲止得到的重量

nodes(airct, unique(where(airct))) 

謝謝

回答

4

二叉樹是一個很大的S4對象,所以有時很難提取數據。

但BinaryTree對象的繪圖方法,有一個窗體函數(節點)的可選面板函數繪製終端節點。所以當你繪製時你可以獲得關於這個節點的所有信息。

這裏我用的繪圖功能,提取信息,甚至更好,我USEE的gridExtra和包裝來改變終端節點的形式表

library(party) 
library(gridExtra) 
set.seed(100) 
lls <- data.frame(N = gl(3, 50, labels = c("A", "B", "C")), 
        a = rnorm(150) + rep(c(1, 0,150)), 
        b = runif(150)) 
pond= sample(1:5,150,replace=TRUE) 
tt <- ctree(formula=N~a+b, data=lls,weights = pond) 
output.df <- data.frame() 
innerWeights <- function(node){ 

dat <- data.frame (x=node$nodeID, 
        y=sum(node$weights), 
        z=paste(round(node$prediction,2),collapse=' ')) 
    grid.table(dat, 
      cols = c('ID','Weights','Prediction'), 
      h.even.alpha=1, 
      h.odd.alpha=1, 
      v.even.alpha=0.5, 
      v.odd.alpha=1) 
    output.df <<- rbind(output.df,dat) # note the use of <<- 

} 

plot(tt, type='simple', terminal_panel = innerWeights) 


data 
    ID Weights  Prediction 
1 4  24 0.42 0.5 0.08 
2 5  17 0.06 0.24 0.71 
3 6  24 0.08 0 0.92 
4 7  388 0.37 0.37 0.26 

enter image description here

+0

這正是我需要的,謝謝〜 – JPC

0

這裏就是我發現,它工作正常,有點額外的信息。但我只是想在這裏發佈,以防將來有人需要它們。

y <- do.call(rbind, nodes(tt, unique(where(tt)))) 
write.table(y, 'clipboard', sep='\t') 

@agstudy,讓我知道你在想什麼。