Category Archives: RSTATS

But can it do the Cowboy Hat?

One of the interesting things about having a blog are the comments and emails that you receive. In the previous posting, I demonstrated how you can use the Bridge to R and R graphics to create histograms and contour plots that rivals anything that SAS/Graph can do. Well, I received an email from a long lost soul who I worked with in Michigan for about a year on a banking project. He asked, "But can it do the Cowboy Hat?"

That made me laugh out loud and brought back a lot of memories. David and I were both doing a lot of SAS programming work for a bank and this was in the era of IBM 3179G graphics terminals. SAS had just pushed out a new procedure called g3d for creating three dimensional plots. We were both kind of blown away by the sample program that came with SAS/Graph called the "Cowboy Hat." Well, long story short, David and I both wanted to find a way to create that kind of plot with our bank data, even if it killed us.

Over the course of three weeks (mostly in our spare time, obviously), we tried numerous variations of data that we had in our DB but the plots that came out of g3d never looked anywhere as good as the sample program. We would submit programs and wait for 10 minutes to slowly see our graphics terminal display the top part of the plot, wait another five seconds, and then watch the bottom part of the plot appear. We were always disappointed at what we had created.

One day, we learned that there was a project going on inside the bank to optimize the branch system and all the customer accounts had been geocoded with lat/long coordinates. Both our eyes lit up at the same time because we knew we finally had some data we could use to make a "cool" plot. As we investigated the file, things just kept getting better. There were additional coordinate pairs that specified the nearest "major intersection" and the coordinates of the centroid for the census block group that the account belonged.

We ended up using deposit balances for our Z axis, and the lat/long coordinates for our X and Y pair. After tweaking the code, we got this amazing plot to come out. It was a plot showing the strength of deposit balances over a specified area (Wayne, Oakland and Macomb counties) and the plot demonstrated all the characteristics of the Central Business District and Central Place Theory that is discussed in modern geography. We were both tickled to death. In retrospect, between the mainframe charge backs and our time that we billed, that plot could vie for the most expensive plot made to that date. But we didn’t care! It looked amazingly cool.

So to answer your question David, "Yes, R can do the Cowboy Hat." For reference, here’s a link to the SAS/Graph version.

Here’s the WPS and R code to do the same plot.

*–> Cowboy hat;
data hat;
   do x=-5 to 5 by .25;
      do y=-5 to 5 by .25;
         z=sin(sqrt(x*x+y*y));
         output;
      end;
   end;

*–> Perspective plots;
%Rstart(csv, hat,GRAPHWINDOW);
datalines4;

library(akima)
attach(hat)
surface <- interp(x, y, z)

persp(surface, axes="TRUE", theta=110, phi=15,
      ticktype="detailed", expand=0.50)
title("Cowboy Hat with R",font.main=1)

;;;; 
%Rstop(import=);

 

And the R version of the Cowboy Hat.

 

cowboyhat

About the author: Phil Rack is President of MineQuest, LLC. and has been a SAS language developer for more than 25 years. MineQuest provides WPS and SAS consulting and contract programming services and a reseller of WPS in North America.

Importing and Exporting R data frames with the Bridge to R

Even though the weather has been spectacular, I spent the better part of the weekend indoors watching the NCAA Basketball Tournament and adding a new feature in to the Bridge to R. I think anyone who uses the Bridge will find this very useful. The feature is the ability to read an R data frame into WPS.

We’ve always provided you with the ability to create a data frame within the Bridge, but for some reason have always struggled with how to read in a frame that was created in R. Part of the dilemma is keeping an arm’s length distance from R as to not infringe on copyright or overstep the license agreement.

The other aspect that is problematic is catching all the errors when something goes south, and eventually, there will be an issue where a data frame doesn’t exist or was misspecified and things go south quickly.

What I decided to do is extend the %Rstop macro that completes and executes the R interface by providing an “Import=” option. By listing the data frames in the “Import=” clause, i.e. the ones that you created in your R session, the Bridge to R will automatically look for those frames and read them in and convert them to WPS data sets for you.

Below is a short code example using the LM (linear model) function in R. If you’re an R programmer, you know that almost everything in R is an object. What you need to do is specify and create a data frame from the object. In the example, we’re creating three data frames. They are coeff, resid and fitted and they output data that corresponds to the model coefficient’s, the residuals and the fitted values.

%Rstart(csv,census,NOGRAPHWINDOW);

datalines4;

  attach(census)

  census.lm <- lm(pop2 ~ year+lpop, data=census)

  summary(census.lm)

  coeff = data.frame(coef(census.lm))

  resid = data.frame(resid(census.lm))

  fitted = data.frame(fitted(census.lm))

;;;;

%Rstop(import=coeff resid fitted);

The last line of the code above shows the import clause in the %Rstop macro. By listing the data frames that you created in R (and using the exact same capitalization), we can read in the data frames and create the corresponding WPS data sets.

This new enhancement will be available in the next release of the Bridge to R. In the next week, we’ll create a video or two on using Ggobi from the Bridge as well as showing how to import data frames.

About the author: Phil Rack is President of MineQuest, LLC. and has been a SAS language developer for more than 25 years. MineQuest provides WPS and SAS consulting and contract programming services and a reseller of WPS in North America.

Technorati Tags: ,,,,

Version 2.4 of the Bridge to R now Available

It’s been a while since I last posted to my blog. I’ve been very busy on two different projects as well as writing RFP’s for WPS license sales. Looking back on the blog, the last post was January 27th. WOW!

So what’s the latest news? A new release of the Bridge to R is now available for WPS Users. This release, v2.4 is a bit more robust being able to recover from some formerly catastrophic programming errors.

But the highlight of Version 2.4 is that it now includes support for Ggobi for interactive data visualization. We’ve simplified calling Ggobi and passing data to it so all you really need to do is type:

%ggobi( datasetname );

If you’re not familiar with Ggobi, I suggest you visit www.ggobi.org and view the tutorials and demos on the website. There’s some really nice things that they’ve implemented.

If you’re a WPS user, you will need version 2.4 of WPS to run the Bridge to R. It does make use of some new features available in WPS that requires v2.4.

If you have licensed WPS from MineQuest, and you’ve not received a copy of version 2.4 of the Bridge to R, contact sales@minequest.com and we’ll get a copy right out to you.

The Bridge to R is provided as a free utility from MineQuest only if you purchase your WPS license directly from us. If you’ve licensed a copy of WPS directly from World Programming or from another reseller, The Bridge to R can be purchased for $149 for a desktop license and $499 for a Windows Server license.

About the author: Phil Rack is President of MineQuest, LLC. and has been a SAS language developer for more than 25 years. MineQuest provides WPS and SAS consulting and contract programming services and a reseller of WPS in North America.

Linux Port of the Bridge to R

After some trial and error, I’ve finally been able to get WPS on Linux to talk – at arms length – to the statistics package, R. I’m pretty excited about this because it opens new avenues for the Bridge to R.

Given my time line, I hope to have the Bridge to R on Linux (x86) completed and tested by November 5th, 2009. If any WPS sites running Linux are interested in playing with a beta release of this, let me know and we will arrange for you to get a copy of the compiled macro catalog.

I’m making some assumptions here, but I imagine that the same code that implements the Bridge for Linux will also be able to run under SUN Solaris (x86) and Macintosh OSX. Compatibility between different Linux (x86) platforms will be something we will test down the road.

I do like the idea of running Linux as a 64-bit OS so we can run R programs that require a large memory address space. As the 64-bit platforms become common, I think this will become the standard installation for almost all servers and many desktop machines.

About the author: Phil Rack is President of MineQuest, LLC. and has been a SAS language developer for more than 25 years. MineQuest provides WPS and SAS consulting and contract programming services and a reseller of WPS in North America.

CP Release of the Bridge to R now Available

The Community Preview Release of the Bridge to R is available on the MineQuest website. The Community Preview release is available for SAS installations and requires SAS 9.2. The WPS release will be available as soon as the next release of WPS is made available to the public. For all practical purposes, the two versions are identical but the WPS version takes advantage of a few new functions that we really wanted to be able to use.

The CP version will operate through November 15, 2009. This should be plenty of time to experiment with the software and see how helpful it can be to your site. For more information on the Bridge to R and links to the download, click here…

or visit: http://www.minequest.com/BridgetoR.html

About the author: Phil Rack is President of MineQuest, LLC. and has been a SAS language developer for more than 25 years. MineQuest provides WPS and SAS consulting and contract programming services and a reseller of WPS in North America.

Technorati Tags: ,,

We’re Close to a new Release of the Bridge to R

We have the Bridge to R completed and have the draft documentation completed as well. Writing documentation is the rough part of this endeavor. It’s approximately 30 pages and includes a number of sample programs that you can use to get started and learn about how the Bridge works.

The product requires SAS 9.2 or WPS 2.4 to be installed on your computer. Versions earlier than that will not work. There are programming reasons for this requirement but we are pretty confident that most people will be on SAS v9.2 or the newer releases of WPS as soon as they can.

Our game plan is to make available the Bridge for both WPS and SAS users at the same time. We’re going to have a Community Preview release that will run for 60 days. So, we are planning for the period of October 1st thru November 30th for the Community Preview. This should be plenty of time to decide if the software is something that you find useful.

To participate in the Community Preview, we’re going to ask that you request a copy of the software via email or by phone. We will need your contact information including your name, company or organization that you are affiliated with, and your company or academic email address. We will also need to know for which platform, SAS or WPS, that you want to preview and test.

Once we receive your request, we will send you the Installation and Users Guide as well as the compiled software. Installation and setup is pretty easy and takes 10 to 15 minutes.

Overall, we’re pretty happy with the way this software rewrite has turned out. It’s stable, easy to understand, and abides 100% by the GPL license that R is offered under. It will also be affordable!

If you license WPS through MineQuest, we will provide a copy of the software to you as part of the purchase. If you license WPS from other sources, than there will be a onetime charge of $149 per copy for the software on the desktop. The software is tied to the release number of WPS or SAS. So, if you have SAS 9.2, the software will work on all point releases of 9.2. The same will apply to WPS. The Bridge will only run on the major release number of WPS 2.4. Hence, 2.4.1, 2.4.2, 2.4.5 will all work without having to upgrade. The upgrade be required when SAS or WPS moves off of 2.4.x or 9.2.x.

About the author: Phil Rack is President of MineQuest, LLC. and has been a SAS language developer for more than 25 years. MineQuest provides WPS and SAS consulting and contract programming services and a reseller of WPS in North America.

Technorati Tags: ,,,