Benchmarks Online

Skip Navigation Links


Page One

Campus Computing News

Microsoft Campus Agreement Benefits Faculty and Staff

Checkin 4.0 on the Move

EIS Online Help Available

Call for Proposals: CUMREC

Today's Cartoon

RSS Matters

The Network Connection

Link of the Month

WWW@UNT.EDU

Short Courses

IRC News

Staff Activities

Subscribe to Benchmarks Online
    

 Research and Statistical Support - University of North Texas

RSS Matters

Link to the last RSS article here: Using S-Plus Graphics in Excel; SPSS News   - Ed.

Two User Interfaces to the R Statistical System:  Rcgi and R Commander

By Dr. Rich Herrington, Research and Statistical Support Services Manager

This month we continue our exploration of window interfaces for R:  R Commander - a simple drop down menu system; and Rcgi - a CGI based web interface to R. The following is an excerpt from the R website http://www.r-project.org

 R is a language and environment for statistical computing and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S. There are some important differences, but much code written for S runs unaltered under R.  R provides a wide variety of statistical (linear and nonlinear modeling, classical statistical tests, time-series analysis, classification, clustering, ...) and graphical techniques, and is highly extensible. The S language is often the vehicle of choice for research in statistical methodology, and R provides an Open Source route to participation in that activity. One of R's strengths is the ease with which well-designed publication-quality plots can be produced, including mathematical symbols and formulae where needed. Great care has been taken over the defaults for the minor design choices in graphics, but the user retains full control. R is available as Free Software under the terms of the Free Software Foundation's GNU General Public License in source code form. It compiles and runs out of the box on a wide variety of UNIX platforms and similar systems (including FreeBSD and Linux). It also compiles and runs on Windows 9x/NT/2000 and MacOS (from Introduction).

Starting R in the SDI Mode

At this point it is assumed that you have installed R and have an R icon on your desktop (see the earlier Benchmarks Online article on downloading and installing R).  Additionally, it is assumed that you have installed all of the supporting R Commander (Rcmdr) packages. To use the Rcmdr library, we will want to configure the R system window to have a "single document interface" mode (sdi). Right mouse click the R icon on your desktop and select properties. Add " --sdi  " to the Target field after the Rgui.exe statement (see below). Click apply, then ok.  Double click the R icon on your desktop to start the R system.

Screenshot: configuring the R system window

Loading the R Commander (Rcmdr) Package

To load the Rcmdr package, select Packages from the main menu bar in your main R console window and select Load Package. Select Rcmdr in the list. The Rcmdr window system will appear. Alternatively, you can manually load the Rcmdr package window from the main R console window by typing the "library" function, with the appropriate library, into the command prompt: 

 Screenshot: Rcmdr window system

After selecting the Rcmdr package in the package selection window OR by loading the package manually, the following menu system will appear:

Screenshot: R Commander window

Some Fundamentals of the Rcmdr Window System

The Rcmdr window system can be resized by "grabbing" one of the corners of the window with the mouse (hover over the corner until you get a "double-headed" arrow" then press your left mouse button and drag the mouse). The upper window in the Rcmdr window is a script window where commands can be typed and then be submitted for processing. Once these commands have been typed in, the commands can be highlighted and the "Submit" button can be clicked. Alternatively, a right-mouse click on the highlighted script brings up a small menu where the script can be submitted for processing. Additionally, this menu can be used to find, select all, delete, copy and paste scripts that are in this window. Type the following script in the R script window; highlight the script;  right-mouse click and "Submit" the script:

Screenshot: Rcmdr window system

Submitting the R script above, generates 30 random normal numbers; places them in the object "x"; displays the object "x"; and then generates a frequency distribution of the numbers (histogram). The bottom window of the Rcmdr generates the output from your R commands. You can scroll through this output; copy, cut, and paste the output.

Screenshot: Rcmdr window system

The following graph is also generated:

Histogram of x

Additionally, using the drop down menu system in Rcmdr generates a script that appears in the script window. This convenience allows one the benefit of the drop down menu system, but also allows one to learn the R command language set as well.  Additionally, commands that are generated by the window system can be saved to a script file for additional processing at a later time. For an example, lets generate a normal density function from the menu system (click "ok" to accept the default normal density parameters):

Screenshot: Rcmdr window system script window

The following R script is generated in your script window; and the following is generated in your output window:

Screenshot: Rcmdr window system

Notice that when your graphic image is generated that a history of plots are recorded.  Click on "History" then "Recording". This should be checked as it is turned on when Rcmdr starts. You can use your "PAGE-UP" and "PAGE-DOWN" keys on the keyboard to flip back and forth through the various plots you have generated.

Screenshot: Rcmdr window system

On the File menu option of your R graphics device you will notice that you can copy your image to your clipboard for insertion into other Windows programs (i.e. Microsoft Word).  Also you can print the image out as well.

Screenshot: Rcmdr window system

Running R scripts from your Rcmdr window in your Rcgi Web Interface and Vice-Versa

Now we want to Start a web browser at the following link:

http://rss.acs.unt.edu:/cgi-bin/R/Rprog

Paste the R script from your R Commander window into the R Web interface:

Screenshot: Rcmdr window system

The "Clear the R program" button will clear the text from the CGI window; The "Display Graphic (GIF)" button will display any images that have been generated. Running the R script produces the following text:

Screenshot: program output

The R script that is processed is produced with the output below the R script.  Viewing the graphics can be done by selecting the "Low Quality GIF" link at the bottom of the page OR the "Display Graphic (GIF) button at the top of the page.  A graphic image(s) is generated within the browser:

Screenshot: graphic image

Here we see that the script produces two images.  These images can be printed from your browser. Additionally, a right-mouse click on these images will allow you to copy to your clipboard for pasting into other programs (i.e. Microsoft Word), or for saving to a file. To get back to the script window, press the Back Page on your web browser. You can continue to click the "Back Page" on your browser to get to the point from which the script window was generated (such as from within an HTML document). Note:  you can right-mouse click on the "Display Graphic" button or the "Low Quality GIF" button and select the "Open in new window" option to open your graphics in a separate window from your script window. 

Creating a Data-frame to Use within R Commander

In R we can create a number of different data objects. We can create scalars (single numbers), vectors (concatenated scalars - a single column or single row of numbers), or a matrix (concatenated vectors - several adjacent columns with multiple rows).  Additionally, data can be of type "character" or "numeric". Vectors and matrices must be all of one type or the other. For example: 

Screenshot: Rcmdr window system

We could not mix character type "rich" and the numeric type "3" in a vector or matrix.  We need a "data-frame" for this purpose. The data-frame is what is we will refer to a rectangular data matrix where columns are "variables" or measurements on each respondent and rows are the distinct respondents. For example, a column could consist of names, another column might consist of salaries. "Names" would be a character variable and "Salary" would be numeric variable in the same data matrix. R Commander will need all data that will appear in the drop down dialog boxes to be in the form of a data-frame so that variable information can be utilized in the menu system.  To create a simulated data-frame we can use the following script:

Screenshot: Rcmdr window system

Notice that the data.frame function generates default variable headings:  X1, X2, X3, X4, X5.  These would represent variables for respondents.  The numbers 1,2,3,4,5 would represent different respondents.  Next, notice that the "Data Set" icon is grayed out and there is "<No active dataset>".  Click the "Data Set" icon button and a drop down menu list will appear.  Select the "x.df" object:

Screenshot: Rcmdr window system

Notice that there is now an "Active data set" called x.df.

Screenshot: Rcmdr window system

This mechanism allows a user to switch between different data sets for viewing and editing.  Simple editing and viewing in a spreadsheet fashion can be accomplished by selecting "Edit data set" or "View data set":

Screenshot: edit data

NOTE:  Make sure that you close the editing or viewing  window before opening or moving to other windows!!  There is a limitation of the spreadsheet program in that it doesn't work well with other windows that are concurrently open.  For this reason, edit, enter or view your spreadsheet and finish this task before moving on to other window movements or dialog boxes. Remember, in general you will need to have an active data set in order to use the menu systems - unless you are using the menu system to generate a graph or data (not ACTING on data).

Using other Menus in R Commander

In general, the variables of the data-frame will appear in the men dialog boxes.  Selecting these variables with the mouse will make them active in the dialog box. For example to generate a histogram:

Screenshot: Rcmdr window system other menus

Producing the following density plot (a histogram with a relative frequency on the y-axis):

Screenshot: histogram

References

Fox, John (2003).  The R Commander: A Basic-Statistics GUI for R. http://socserv.mcmaster.ca/jfox/Misc/Rcmdr/

 

 

Return to top