[R] convert a splus randomforest object to R

William Dunlap wdunlap at tibco.com
Wed Aug 10 00:25:08 CEST 2011


For a variety of reasons, there is no easy way to transfer
many kinds of complicated objects (and some simple ones)
from S+ to R (or vice versa).  If you want to compare
predictions made by randomForest in S+ and R, I would
recommend transferring the data.frames used to create the
model and to predict from from R to S+ and do the predictions
using the same program as the model was fit on.  Then transfer
the output of predict from S+ back to R.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Zhiming Ni
> Sent: Tuesday, August 09, 2011 2:31 PM
> To: Liaw, Andy; r-help at r-project.org
> Subject: Re: [R] convert a splus randomforest object to R
> 
> In Splus the randomForest package version is 4.5-18; in R randomForest
> version is 4.6-2. I'm using R version 2.13.1.
> 
> After restore the randomForest object into R using data.restore(), below
> are str(cost.rf) outputs,
> 
> List of 17
>  $ call           : language randomForest(x =
> train.roughfix[stop("Argument '' is missing"),      -1L], y =
> train.roughfix[stop("Argument '' is missing"),  ...
>  $ type           : chr "regression"
>  $ predicted      : atomic [1:51368] 23921 8884 2799 4432 7201 ...
>   ..- attr(*, ".Names")= chr [1:51368] "1" "2" "3" "4" ...
>  $ mse            : num [1:500] 1.65e+09 9.76e+08 7.70e+08 6.77e+08
> 6.22e+08 ...
>  $ rsq            : num [1:500] -1.952 -0.747 -0.379 -0.213 -0.114 ...
>  $ oob.times      : int [1:51368] 185 190 189 176 182 184 164 200 189
> 200 ...
>  $ importance     : num [1:78, 1:2] 1040619 34174 148774 48116 235056
> ...
>   ..- attr(*, "dimnames")=List of 2
>   .. ..$ : chr [1:78] "Age" "AntiarrhythmicsC" "AntiarrhythmicsDays"
> "AntiarrhythmicsIIIC" ...
>   .. ..$ : chr [1:2] "%IncMSE" "IncNodePurity"
>  $ importanceSD   : atomic [1:78] 308517 9618 43424 11313 101015 ...
>   ..- attr(*, ".Names")= chr [1:78] "Age" "AntiarrhythmicsC"
> "AntiarrhythmicsDays" "AntiarrhythmicsIIIC" ...
>  $ localImportance: num [1:78, 1:51368] 0 0 0 0 0 0 0 0 0 0 ...
>   ..- attr(*, "dimnames")=List of 2
>   .. ..$ : chr [1:78] "Age" "AntiarrhythmicsC" "AntiarrhythmicsDays"
> "AntiarrhythmicsIIIC" ...
>   .. ..$ : chr [1:51368] "1" "2" "3" "4" ...
>  $ proximity      : symbol proximity
>  $ ntree          : int 500
>  $ mtry           : num 6
>  $ forest         : atomic [1:10] c(525, 525, 525, 525, 525, 5
> structure(c(-3, -3, -3, -3, H structure(c(2, 4, 6, 8, 10, H
> structure(c(3, 5, 7, 9, 11, H ...
>   ..- attr(*, ".Names")= chr [1:10] "ndbigtree" "nodestatus"
> "leftDaughter" "rightDaughter" ...
>  $ coefs          : symbol coefs
>  $ y              : num [1:51368] 26697 28758 611 1035 12483 ...
>  $ test           : symbol test
>  $ inbag          : symbol inbag
>  - attr(*, "class")= chr "randomForest"
> 
> I tried dump() in Splus then source() in R as well, but the source()
> function returns error:
> 
> Error in attributes(.Data) <- c(attributes(.Data), attrib) :
>   attributes must be named
> 
> 
> Thanks,
> Jimmy
> 
> -----Original Message-----
> From: Liaw, Andy [mailto:andy_liaw at merck.com]
> Sent: Tuesday, August 09, 2011 12:12 PM
> To: Zhiming Ni; r-help at r-project.org
> Subject: RE: convert a splus randomforest object to R
> 
> You really need to follow the suggestions in the posting guide to get
> the best help from this list.
> 
> Which versions of randomForest are you using in S-PLUS and R?  Which
> version of R are you using?  When you restore the object into R, what
> does str(object) say?  Have you also tried dump()/source() as the R Data
> Import/Export manual suggests?
> 
> Andy
> 
> > -----Original Message-----
> > From: r-help-bounces at r-project.org
> > [mailto:r-help-bounces at r-project.org] On Behalf Of Zhiming Ni
> > Sent: Tuesday, August 02, 2011 8:11 PM
> > To: r-help at r-project.org
> > Subject: [R] convert a splus randomforest object to R
> >
> > Hi,
> >
> > I have a randomforest object "cost.rf" that was created in splus 8.0,
> > now I need to use this trained RF model in R. So in Splus, I dump the
> > RF file as below
> >
> > data.dump("cost.rf", file="cost.rf.txt", oldStyle=T)
> >
> > then in R, restore the dumped file,
> >
> > library(foreign)
> >
> > data.restore("cost.rf.txt")
> >
> > it works fine and able to restore the "cost.rf" object. But when I try
> 
> > to pass a new data through this randomforest object using predict()
> > function, it gives me error message.
> >
> > in R:
> >
> > library(randomForest)
> > set.seed(2211)
> >
> > pred <- predict(cost.rf, InputData[ , ])
> >
> > Error in object$forest$cutoff : $ operator is invalid for atomic
> > vectors
> >
> >
> > Looks like after restoring the dump file, the object is not compatible
> 
> > in R. Have anyone successfully converted a splus randomforest object
> > to R? what will be the appropriate method to do this?
> >
> > Thanks in advance.
> >
> > Jimmy
> >
> > ==========================================
> > This communication contains information that is confidential, and
> > solely for the use of the intended recipient. It may contain
> > information that is privileged and exempt from disclosure under
> > applicable law. If you are not the intended recipient of this
> > communication, please be advised that any disclosure, copying,
> > distribution or use of this communication is strictly prohibited.
> > Please also immediately notify SCAN Health Plan at 1-800-247-5091,
> > x5263 and return the communication to the originating address.
> > Thank You.
> > ==========================================
> >
> > 	[[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
> >
> Notice:  This e-mail message, together with any attachme...{{dropped:24}}
> 
> ______________________________________________
> 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.



More information about the R-help mailing list