Training on Rlanguage Mrti Liberts Central Statistical Bureau
Training on R-language Mārtiņš Liberts Central Statistical Bureau of Latvia
Outline n Introduction with R n n Practical examples with R Sampling package n Practical examples with Sampling package
R — a language and environment n n R (www. R-project. org) is an advanced statistical computing system with very high quality graphics that is freely available for most computing platforms. The S language is often the vehicle of choice for research in statistical methodology and R provides a free software route to participation in that activity.
R n n R is being developed for the Unix, Windows and Mac families of operating systems. It is a system available as source code (at www. Rproject. org) that compiles on almost all current Unix and Linux systems, and has binary versions for the major Linux distributions, Free. BSD, Mac. OS X and Windows. It is distributed under GPL 2 (the “GNU Public Licence”). The core system is fairly small but can be extended by packages, several ‘recommended’ ones ship with R and about 300 (and growing) are available from CRAN (CRAN. R-project. org and mirrors).
Work with R n Console n n Scripts n n R prompt > Input Output Input Workspace n Storage of the objects created during work sessions
Work with R
Work with R n Running commands from console n n Type in the commands and execute by Enter Running commands from script n n n Select commands for running and execute by Ctrl+R It is possible to select only the part of command execute this part Whole line where the cursor is positioned will be executed if nothing is selected
Work with R • • 2+4 pi sin(pi/2) S=0 for (i in 1: 10) S=S+i S
Help in R help. start() n ? sin n help. search("sin") n
R objects n n n n Numbers and vectors Matrices Lists Data frames Logical values Missing values Factors The function is. *
Numbers and vectors a=5 n Y=c(1, 3, 6, 8) n Y+a n Y[3] n
Arithmetic operators and functions n Operators: n n +-*/^ %*% %/% %% : Functions: abs exp gamma log log 10 sign sqrt sin cos tan sinh asinh max min range length sum prod sort order rank rev cumsum cumprod var mean. . .
Generating sequences of numbers n Using : 1: 5 n 5: 1 n n Using seq n n seq(from=0, to=3, length=6) Using rep n rep(1, 5)
matrix, data. frames n matrix M=cbind(1: 5, 6: 10, 11: 15) n M[1, 2] M[1, ] M[, 3] M[1, 2] n n data. frame treeframe=data. frame (diameter=c(10, 15, 20, 25), height=c(1. 5, 1. 6, 1. 2, 2. 1)) n treeframe[, 1] n treeframe$diameter n
Logical values n Logical operators n n == != > >= < <= &|! Examples n n X=seq(from=0, to=10, length=21) X<5 X[X<5] treeframe[treeframe$diameter<20, 2]
Packages CRAN. R-project. org n library(foreign) n n read. spss
The sampling package n n n n Version 0. 3 Date 2006 -04 -12 Title Sampling survey Author Yves Tillé yves. tille@unine. ch Alina Matei alina. matei@unine. ch Maintainer Yves Tillé yves. tille@unine. ch Description The sampling package contains a set of tools to select and to calibrate samples. Depends MASS, lp. Solve License GPL version 2 or later.
Functions regressionestimator n boundedregressionestimator n checkcalibration n Other functions n
- Slides: 18