Child pages
  • R
Skip to end of metadata
Go to start of metadata

R

R is a software environment for statistical computing and graphics. A simple R program and an associated submit script are as follows. The output in this instance appears in a PostScript file named Rplots.ps:

Category of SoftwareStatistics & Mathematics
 What is R?R is `GNU S' - A language and environment for statistical computing and graphics. R is similar to the award-winning S system, which was developed at Bell Laboratories by John Chambers et al. It provides a wide variety of statistical and graphical techniques (linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, ...).

R is designed as a true computer language with control-flow constructions for iteration and alternation, and it allows users to add additional functionality by defining new functions. For computationally intensive tasks, C, C++ and Fortran code can be linked and called at run time.

There is an Australian AARNet mirror of the main R web site.

http://en.wikipedia.org/wiki/R_%28programming_language%29

How to useR is free to use

Sample code

R instructions placed in filename 'example.r'
x <- c(1,2,3,4,5,6)   # Create ordered collection (vector)
y <- x^2              # Square the elements of x
print(y)              # print (vector) y
mean(y)               # Calculate average (arithmetic mean) of (vector) y; result is scalar
var(y)                # Calculate sample variance
lm_1 <- lm(y ~ x)     # Fit a linear regression model "y = f(x)" or "y = B0 + (B1 * x)"
                        # store the results as lm_1
print(lm_1)           # Print the model from the (linear model object) lm_1
summary(lm_1)         # Compute and print statistics for the fit
                      # of the (linear model object) lm_1
par(mfrow=c(2, 2))     # Request 2x2 plot layout
plot(lm_1)             # Diagnostic plot of regression model
Script file called 'submit.sh'
#!/bin/sh
#$ -S /bin/sh
#$ -cwd
 
### time limit format: hh:mm:ss
#$ -l h_rt=20:00:00 
 
### memory limit (e.g., 2GB)
#$ -l h_vmem=2G
module load R
R --vanilla < example.r
# or R --vanilla < example.r > output.txt
Submit to MCC
qsub submit.sh
Output
  R version 2.6.0 (2007-10-03)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
 Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R. 
> x <- c(1,2,3,4,5,6) # Create ordered collection (vector)
> y <- x^2 # Square the elements of x
> print(y) # print (vector) y
[1] 1 4 9 16 25 36
> mean(y) # Calculate average (arithmetic mean) of (vector) y; result is scalar
[1] 15.16667
> var(y) # Calculate sample variance
[1] 178.9667
> lm_1 <- lm(y ~ x) # Fit a linear regression model "y = f(x)" or "y = B0 + (B1 * x)"
> # store the results as lm_1
> print(lm_1) # Print the model from the (linear model object) lm_1
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x 
 -9.333 7.000 
> summary(lm_1) # Compute and print statistics for the fitCall:
lm(formula = y ~ x)
Coefficients:
(Intercept) x 
 -9.333 7.000 
> summary(lm_1) # Compute and print statistics for the fit
Call:
lm(formula = y ~ x)
Residuals:
 1 2 3 4 5 6 
 3.3333 -0.6667 -2.6667 -2.6667 -0.6667 3.3333 
Coefficients:
 Estimate Std. Error t value Pr(>|t|) 
(Intercept) -9.3333 2.8441 -3.282 0.030453 * 
x 7.0000 0.7303 9.585 0.000662 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
Residual standard error: 3.055 on 4 degrees of freedom
Multiple R-Squared: 0.9583, Adjusted R-squared: 0.9478 
F-statistic: 91.88 on 1 and 4 DF, p-value: 0.000662 
> # of the (linear model object) lm_1
> par(mfrow=c(2, 2)) # Request 2x2 plot layout
> plot(lm_1) # Diagnostic plot of regression model
>

 

 

 

  • No labels