The statistical packgage R
A scripting language for statistical analysis is now installed on Gridur.
The R package is an open source version of the commercial S Plus. More
information, including comprehensive manuals, can be found on:
To start up R on Gridur, you first have to run the following command when
using the C-shell (/bin/csh or /bin/tcsh):
module load R
This command only makes R available for later use; you will not enter the
R interactive shell by only submitting this command. After running the
command, you may (if you wish) start up another unix shell (for example
To start up R in interactive mode, just type:
You may also run an R program in batch using this command:
R --vanilla <r_program >r_output
Below follows an annotated example of an R program, which may be useful
for those with no former experience with R:
The program will read a file "s1" with the following content:
# Arranges for graphical output to be sent to
# a postscript file, r.eps. The 'onefile=FALSE'
# ensures the file will follow the encapsulated
# postscript standard.
# Organizes the graphical ouput device using
s1 <- read.table("s1",header=TRUE)
# 6 plotting areas on one page layed out in
# a 2 columns by 3 rows structure. Each 'plot'
# command below will send its output to a
# new area.
# The '<-' is the "assign to" operator. The
# 'read.table' command reads an ASCII file (s1)
# organized in columns separated by spaces.
# The 'header=TRUE' option is used when the
# first row contains names for each coloumn.
# The variable s1 will now hold an object
# representing the table.
# Fills the first four plotting areas with
m1.s1 <- lm(length ~ words + int,data=s1)
# scatter plots. The 's1$words' and similar
# constructs represents vectors corresponding
# to coloumns in the table. 'words' is the
# column name.
# Fits a linear regression model using
# 'length' as the dependent variable and
# 'words' and 'int' as independent variables
# Prints a summary of the regression
m2.s1 <- lm(log(length) ~ I(log(words)) + I(log(int)),data=s1)
# Trying a logarithmic fit
# Quit R
int long lines words
More examples can be found on /noserc2/extdata/felles/R on Gridur, but some of these
files depend on libraries not yet installed on Gridur.
778 2897 17775
198 842 5094
1061 3342 24495
930 4204 34453
104 20 1575
191 14 2175
30 13 677
109 573 3515
122 13 1038
53 345 2086
83 389 2394
722 2358 17143
280 1010 7448
566 15 4254