Using R Commandeer For Data Analysis
Using R Commandeer For Data Analysis
Part One
Using R Commander
for Data Analysis
March 2015
Written by
N.Nilgn oka
1|Page
Introduction to R Commander
What is R Commander
The R Commander (Fox, 2005) provides a graphical user interface (GUI") to the open-source
R statistical computing environment. R is a command-driven system, and new users often
find learning R challenging. This is particularly true of those who are new to statistical
methods, such as students in basic-statistics courses.
R commander is free statistical software. R commander was developed as an easy to use
graphical user interface (GUI) for R (freeware statistical programming language) and was
developed by Prof. John Fox to allow the teaching of statistics courses and removing the
hindrance of software complexity from the process of learning statistics. This means it has
drop down menus that can drive the statistical analysis of data.
It also has a series of plug-ins which extend the range of application
RcmdrPlugin.Export Graphically export objects to LaTeX or HTML
RcmdrPlugin.FactoMineR Graphical User Interface for FactoMineR
RcmdrPlugin.HH Rcmdr support for the HH package
RcmdrPlugin.IPSUR Introduction to Probability and Statistics Using R
RcmdrPlugin.SurvivalT Rcmdr Survival Plug-In
RcmdrPlugin.TeachingDemos Rcmdr Teaching Demos Plug-In
RcmdrPlugin.epack Rcmdr plugin for time series
RcmdrPlugin.orloca orlocaRcmdr Plug-in
Installing R Commander
You need to first install R and then R commander. After starting R program from Package
menu select CRAN Mirror.
2|Page
Package
3|Page
After installing Rcmdr. You must load Rcmdr to work on it. When loading is done you will see
a screen like in picture.
Rcmdr Screen
Drop
down
menus
Toolbars
Script Window: R commands
generated by the GUI
You can type commands directly
here. Select then by highlighting and
then send the code by pressing the
Submit button (on right below the
script window)
Output Window
DARK BLUE: printed output
RED: command that was used
Message Window:
RED: Error messages
GREEN: Warnings
BLUE: Other information
Graphs will appear in a separate Graphics Device Window. Only the most recent graph will
appear. You can use page up and page down keys to recall previous graphs.
Drop down Menu item
File
Menu items for loading and saving script files; for saving output and the R
workspace; and for exiting.
Edit
Menu items (Cut, Copy, Paste, etc.) for editing the contents of the script and
output windows. Right clicking in the script or output window also brings up an
edit context menu
Data
Submenus containing menu items for reading and manipulating data.
Statistics
Submenus containing menu items for a variety of basic statistical analyses.
Graphs
Menu items for creating simple statistical graphs.
Models
Menu items and submenus for obtaining numerical summaries, confidence
intervals, hypothesis tests, diagnostics, and graphs for a statistical model, and
for adding diagnostic quantities, such as residuals, to the data set. Distributions
Probabilities, quantiles, and graphs of standard statistical distributions (to be
used, for example, as a substitute for statistical tables).
Tools
Menu items for loading R packages unrelated to the Rcmdr package (e.g., to
access data saved in another package), and for setting some options.
Help
Menu items to obtain information about the R Commander (including an
introductory manual derived from this paper). As well, each R Commander
dialog box has a Help button.
4|Page
Toolbar buttons
Data set
Menu items are inactive (ie, greyed out) if not applicable to the current context.
Manual entry
Start a new data set through Data -> New data set
Enter a new name for the dataset -> OK
Define the variables (column) by clicking on the column label and then in the resulting dialog
box enter the name and type. Where type can be numeric (quantitative) or character
(qualitative). Click on the x in the right hand corner to close this dialog box.
This data frame is then the active dataset for R commander.
5|Page
Chose a name for the new dataset (note you cannot have spaces)
Specify the characteristics of the data files (e.g. commas for csv files) -> OK
Browse and select the file/Open
Once data is imported you should double-check the file was read-in correctly:
Message window: are there any errors?
Do the number of rows and columns look as expected?
View the data via View data set button
6|Page
Opening Food.xls File in R Commander. Import from Excel, Access or dBase DataSet
On R Commander window you will notice that DataSet to be Food on Toolbar area. There
you can click to view dataset to see your Food data files.
7|Page
View Data set will open Food file in different window. There you can check for your DataSet
that is correct and same as in Excel.
Numerical Summaries
In R Commander you can get Statistics of your Data set. For this you must select Statistics
from Menu bar.
Summaries Numerical Summaries will give you some statistics of your DataSet.
8|Page
On Numerical Summaries dialog box you must select variables to get summaries. You can
either select one or more.
Results will come to Output area of R Commander window. To understand the results, you
may find what parameters mean in the table.
Understanding the
output: parameter
mean
sd
N
NA
0%
25%
50%
75%
100%
What is it?
Measure of central tendency
Standard deviation - a measure of variability in the data
Number of readings
Number of missing values
Minimum value
The value below which 25 percent of the observations may be
found.
The value below which 50 percent of the observations may be
found.
The value below which 75 percent of the observations may be
found.
Maximum value
9|Page
10 | P a g e
You can either use Options in <auto> mode or you can write labels for y-axis and Graph title.
But do not forget to change the title and the label for your future works.
11 | P a g e
XY Conditioning Plot
To get XY Conditioning Plot click to Graphs menu select XY Conditioning Plot Command.
On XY Conditioning Plot dialog box you must select variable for dependent and independent
variables for your Dataset.
12 | P a g e
13 | P a g e
food_exp
700
600
500
400
300
food_exp
200
100
0
10
20
30
40
Scatterplots
Graph -> Scatterplot
Plot by groups will allow a selection of a categorical variable such the scatter plot will use
colour to distinguish groups by the categorical variable and fit regression lines independently
for each group. Interpretation of the output?
The solid line: is loess line. A loess line is a locally weighted line and is used to assess
whether the assumption of linearity is appropriate. Visually you are looking to see whether
the loess line suggestions a significant deviation from the linear.
The box plots give an indication to the spread of each variable independently.
On Linear regression dialog box you can give name to your model. Here it uses RegModel.1
(you can either change it or keep)
When working with R it is important to save results in a text file. For this File menu, Save
output as must be selected.
17 | P a g e
18 | P a g e
19 | P a g e
Saving Workspace
You must save Script as; R Markdown files as; R workspace as in Food folder.
Correlation
As we know the correlation is a measure of the strength (and direction) of the Linear
relationship. To get correlation matrix you simply click to Statistics menu Summaries and the
Correlation matrix.
On correlation matrix dialog box you must select variables (both response and explanatory
variables).
20 | P a g e
21 | P a g e
Histogram in R Commander
Finding Histogram is different in R than in Excel. In Excel you need to create BIN column but
in R Commander there is no need to create a BIN column. But in R commander you need to
Add Observation to your model.
To do this you need and to be sure of you are working with Food dataset and the model to
be RegModel.1, otherwise you could get the results for any other dataset.
22 | P a g e
Add Observation Statistics to Data dialog box you need to click Residuals for histogram.
After adding residuals to your model it is time to select Graphs menu Histogram command.
23 | P a g e
If you would select correctly your graphic will be same as shown as in picture.
24 | P a g e
25 | P a g e