Personal tools

R

Basic information on R, an open source statistical software.

What is R?

R is a open source high level programming language designed specifically for statistical computation and graphics. It is one of the most used stat programs by statisticians and is comparable (or better!) than many proprietary stats programs.

General Links

The R Project Homepage: http://www.r-project.org/

The R Journal: http://journal.r-project.org/

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

OpenWetWare R info: http://openwetware.org/wiki/R_Statistics

Crantastic, a review site for R packages: http://crantastic.org/

http://onertipaday.blogspot.com/

New York Times Article

Get R

Download R: http://cran.r-project.org/ (R can also be found in most Linux distribution repositories.)

How to install R: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-R-be-installed_003f

Documentation and Tutorials

GUIs for R

JGR http://jgr.markushelbig.org/JGR.html

R Commander http://socserv.mcmaster.ca/jfox/Misc/Rcmdr/

Basic code

# declare a vector
> x <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
# write a custom function for the square of a number
> sq <- function(x) x*x
> sq(5)
[1] 25
> y <- sq(x)                             
> y                                    
 [1]   1   4   9  16  25  36  49  64  81 100
# make a scatter plot
> plot(y ~ x)
xsquared.png
# calculate the mean and variance of y
> mean(y)            
[1] 38.5             
> var(y)             
[1] 1167.833
# fit a linear regression model
> summary(lm(y ~ x)) 

Call:
lm(formula = y ~ x)

Residuals:
   Min     1Q Median     3Q    Max 
    -8     -6     -2      4     12 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept) -22.0000     5.5498  -3.964  0.00415 **
x            11.0000     0.8944  12.298 1.78e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 8.124 on 8 degrees of freedom
Multiple R-squared: 0.9498,     Adjusted R-squared: 0.9435
F-statistic: 151.2 on 1 and 8 DF,  p-value: 1.778e-06
# add the regression line to the plot
> abline(lm(y ~ x))
xsqReg.png
# make some diagnostic plots for the fit
> par(mfrow=c(2, 2))
> plot(lm(y ~ x))
resid.png

Python and R

RPy http://rpy.sourceforge.net/index.html

R/SPlus - Python Interface http://www.omegahat.org/RSPython/

Document Actions