On Thu, 24 Mar 2011, jdanielnd wrote:
> Hello!
>
> I am not familiar to deal with S4 objects in R, so this question can be
> stupid, but I hope I can get an answer. :P
>
> I'm trying to extract what are the response and explanatory variables
from a
> Binary Tree and Random Forest.
>
> I could already extract the response variable from a Binary Tree using the
> response method specified on documentation. But Random Forest didn't
had a
> similar method.
>
> And regarding the explanatory variables, I couldn't find any solution
at
> all. It seems to be a simple task to extract the explanatory variables from
> a Binary Tree, I just don't know how to deal with the
"Slots". In the case
> of the Random Forest, the task can be more complicated since it deal with
> several trees. What I want is the name of all variables used in any tree.
>
> Does someone have any clue on how should I try to solve this?
ctree() contains a "data" slot which contains an object of
"ModelEnvFormula". This provides the data along with meta-information
which variables are input and response variables. See
help("ModelEnvFormula", package = "modeltools")
for details and examples. As a simple application using ctree(), do the
following: (1) Fit a ctree() named ct. (2) Extract the associated
ModelEnvFormula call mf. (3) Inspect the components...
R> ct <- ctree(Species ~ ., data = iris)
R> mf <- ct at data
R> mf
A ModelEnvFormula with
response variable(s): Species
input variable(s): Sepal.Length Sepal.Width Petal.Length Petal.Width
number of observations: 150
R> head(mf at get("response"))
Species
1 setosa
2 setosa
3 setosa
4 setosa
5 setosa
6 setosa
R> head(mf at get("input"))
Sepal.Length Sepal.Width Petal.Length Petal.Width
1 5.1 3.5 1.4 0.2
2 4.9 3.0 1.4 0.2
3 4.7 3.2 1.3 0.2
4 4.6 3.1 1.5 0.2
5 5.0 3.6 1.4 0.2
6 5.4 3.9 1.7 0.4
Best,
Z
> Many thanks!
>
> Joao Daniel Duarte
> UFMG - Brazil
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/Ctree-Model-Variables-tp3402604p3402604.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>