[R] Regression Trees

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jan 16 21:42:08 CET 2002


On Wed, 16 Jan 2002, Vladimir N. Kutinsky wrote:

> Hi, all.
>
> I'm trying to implement an interface between R and A+ programming
> language (www.aplusdev.org). In A+ I create a scipt file which I pass to
> R (R CMD BATCH file), the results are written into a file and then I
> read them back in A+ where I can continue my work with my data.  Now, I
> work with Regression tress and this is the problem:
>
> when I print the tree I get something like this:
>     1)  root 1130 19580.00 535.6
>       2) V17: 2,3,4,5 853 4833.00 533.7
>         4)V9 < 541.5 185 1011.00 531.9 *
>     ................................etc
>
> When I use this tree for prediction :
>
>      >predict.tree(t, data[1,])
>
> I get something like this:
>
>      >531.9205  //note the precision!!!
>
> though, according to the tree table above(suppose that the new point
> gets to the 4th node) I should have got 531.9!
> It looks like the function print.tree(t) rounds the predicted values. If
> it is so, the question is if there is a way to make print.tree print the
> predicted values as they are, without rounding them.
> Is the problem in anything else?

Yes, all print methods round, including that printing the second result
you gave.  Use the digits argument, or options("digits").

> By the way, does anybody have any suggestions of how to make the
> interface another way, other than through script files?
> Can R functions be called directly from within C scripts (like
> tr=tree(data,formula)). I see that the function "tree" calls a C
> function "BDRgrow1" and that would be just fine if it wasn't for some
> additional R code contained in the "tree" function.

Ah. but predict.tree is very different.

Yes, R code can be called from C programs, and this is documented in
various places, which I'll leave as a research project for you.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list