Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: R for Stata Users

From   Fred Wolfe <>
Subject   Re: st: R for Stata Users
Date   Fri, 26 Feb 2010 12:21:01 -0600

I think that I agree with everything that has been said about R. I
have the book on order, and I certainly hope that it does more than
the blurb suggests.

I have used R for their -rpart- ("CART" - recursive partitioning) and
-randomForest- programs.  Here is an example of (probably poor) R code
that I used (BTW, I ended up making the publication graphs in Stata!):

   sink("rmd1_r.log", split=TRUE)
   mdbinshort$md_acrcrit <- as.factor(mdbinshort$md_acrcrit)
   cat.rp <- rpart(md_acrcrit ~ .,data=mdbinshort,method="class",xval=100)
   jpeg(filename = "mdbinshort1.jpeg")
   plot(cat.rp,uniform = T)

   cat.rf <- randomForest(md_acrcrit
~.,data=mdbinshort,importance=TRUE, proximity=TRUE)
   ## look at variable importance
   ## Plot variable importance
   jpeg(filename = "mdbinshort2.jpeg")
   varImpPlot(cat.rf,main="Predictors of FM Classification")

To make this work for me, I built all of the analysis files in Stata,
and then converted them to R as in this example:

// md data medium sx but not locations
   keep if mdpure == 1
   keep md_acrcrit mdrps mdpain mdfatig mdsleep mdmood mdcog somat
mdunfresh *sx
   save mdbinmedium, replace
   shell "/Applications/StatTransfer9/st.command" mdbinmedium.dta
mdbinmedium.rdata -y

// md data medium sx but not locations with rps as cat
   keep if mdpure == 1
   keep md_acrcrit rcat mdpain mdfatig mdsleep mdmood mdcog somat mdunfresh *sx
   save mdbinmediumcat, replace
   shell "/Applications/StatTransfer9/st.command" mdbinmediumcat.dta
mdbinmediumcat.rdata -y

The real problem is making all of this work in R if you are not an R
expert. I spent hours with errors and books.

What I would like to see, and that is why I am posting this, is a
Stata program that writes R specific program code. So that if I wanted
to run -rpart-, I could run a Stata program that would create the R
code, call R, and run the program.

I think I am not expert enough to attempt this myself. Perhaps this
list could compile that 5-10 most useful R programs and a community
effort to build translation programs could be undertaken.


On Fri, Feb 26, 2010 at 11:35 AM, Airey, David C
<> wrote:
> .
> Agreed. R is documented that way on purpose according to other R docs. It's the recommended style. But it would be helpful if they had a "verbose" option in their dynamically created help files, like with the Stata online help versus PDF manual help! God I love how fast I can get to helpful help in Stata. Yes, sometimes R has good vignettes, but not enough.
> All major statistical software environments are getting explicit with links to R functionality it seems. JMP (SAS) is building in R functionality to version 9 and SPSS 18  already does. I tried Roger Newson's SSC package to run R in Stata a while ago, and it worked fine. But linking to R is not the problem as Stas points out. You have to soak yourself in R head to toe until you are positively inebriated or pickled, is my guess.
> > Well, as pretty much of R documentation, it gives the minimal amount of
> > information. [...] -Stas

Fred Wolfe
National Data Bank for Rheumatic Diseases
Wichita, Kansas
NDB Office  +1 316 263 2125 Ext 0
Research Office +1 316 686 9195

*   For searches and help try:

© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index