I'm not sure I fully understand your question and you haven't provided any reproducible example, so I'll try to wrap it up with a stand alone example and adress your comments on the way
So lets run a classification tree with response variable with 3 different levels
library(party)
irisct <- ctree(Species ~ .,data = iris)
plot(irisct)
So the plot shows us what is the distribution (in percentage) of the explained variable in each leaf (terminal node). For example, you can see that in node number 2, we have 100% of Setosa. The n=50
(you asked about it the comments) means that we have 50 observations in that specific node (not unique, but overal). Now if we want to see the tree structure, we can do:
irisct
##1) Petal.Length <= 1.9; criterion = 1, statistic = 140.264
## 2)* weights = 50
##1) Petal.Length > 1.9
## 3) Petal.Width <= 1.7; criterion = 1, statistic = 67.894
## 4) Petal.Length <= 4.8; criterion = 0.999, statistic = 13.865
## 5)* weights = 46
## 4) Petal.Length > 4.8
## 6)* weights = 8
## 3) Petal.Width > 1.7
## 7)* weights = 46
You can see that in 2)* weights = 50
, wieghts = 50, which means we have 50 observations in that node. As we didn't specify the weights
parameter in the ctree()
, ctree
by default sets a weight of 1 to each observation (you can set the weights parameter differntly, see ?ctree
). You can also see *
at some nodes, which means they are terminal nodes.
Now to get to you main question, you can get the distribution of each level in each node (no metter if it's terminal or not) by using the following code
target <- "Species" # your explained variable, which will be "ldclas" in your case
Node <- 5 # the node you want to investigate
n <- nodes(irisct, Node)[[1]] # retreving the weights of that node
x <- iris[which(as.logical(n$weights)), ] # retreiving all inforamtion for that node
paste(paste(names(table(x[target])), ": ", round((as.numeric(table(x[target]))/nrow(x))*100, 3), "%", sep = ""), collapse = ", ")
## [1] "setosa: 0%, versicolor: 97.826%, virginica: 2.174%"
The output gives you the distribution of each level in that specific node
Hope that was what you needed