Showing posts with label R. Show all posts
Showing posts with label R. Show all posts

Monday, December 12, 2011

R programming books

Three free books on R for Statistics

Avril Coghlan, a lecturer at University College Cork in Ireland, has written and made available for free three books ideal for students or practitioners new to R who want to use it for multivariate analysis, time series analysis or biomedical statistics. Each book begins with practical advice for installing and using R in general, before diving into their specialized topics:

* A Little Book of R for Multivariate Analysis (pdf, 49 pages) is a simple introduction to multivariate analysis using the R statistics software. It covers topics such as reading and plotting multivariate data, principal components analysis, and linear discriminant analysis.
* A Little Book of R for Biomedical Statistics (pdf, 33 pages) is a simple introduction to biomedical statistics using the R statistics software, with sections on relative risks and odds ratios, dose-response analysis, clinical trial design and meta-analysis.
* A Little Book of R for Time Series (pdf, 71 pages) is a simple introduction to time series analysis using the R statistics software (have you spotted the pattern yet?). It includes instruction on how to read and plot time series, time series decomposition, forecasting, and ARIMA models.

All three books are free to use, share and remix under a Creative Commons license, and are available from Dr Coghlan's home page linked below.

Dr Avril Coghlan: avrilomics

Friday, September 30, 2011

R Inferno

An advanced guide to the pitfalls of R programming, written in the style of Dante's inferno. Available from
www.burns-stat.com/pages/Tutor/R_inferno.pdf

Also, a tutorial on package development
documentation with roxygen
Unit testing with testthat
R CMD check -- automated checking

see https://github.com/hadley/devtools/wiki/

Wednesday, September 14, 2011

Inline c++ functions in R code

Short article on how to do this here:

http://dirk.eddelbuettel.com/blog/2011/09/08/#rcpp_for_recursion

This uses the rcpp package

## inline to compile, load and link the C++ code
require(inline)

## we need a pure C/C++ function as the generated function
## will have a random identifier at the C++ level preventing
## us from direct recursive calls
incltxt <- ' int fibonacci(const int x) { if (x == 0) return(0); if (x == 1) return(1); return (fibonacci(x - 1)) + fibonacci(x - 2); }' ## now use the snippet above as well as one argument conversion ## in as well as out to provide Fibonacci numbers via C++ fibRcpp <- cxxfunction(signature(xs="int"), plugin="Rcpp", incl=incltxt, body =' int x = Rcpp::as(xs);
return Rcpp::wrap( fibonacci(x) );
')

This single R function call cxxfunction() takes the code embedded in the arguments to the body variable (for the core function) and the incltxt variable for the helper function we need to call. This helper function is needed for the recursion as cxxfunction() will use an randomized internal identifier for the function called from R preventing us from calling this (unknown) indentifier. But the rest of the algorithm is simple, and as beautiful as the initial recurrence. Three lines, three statements, and three cases for F(0), F(1) and the general case F(n) solved by recursive calls. This also illustrates how easy it is to get an integer from R to C++ and back: the as and wrap simply do the right thing converting to and from the SEXP types used internally by the C API of R

Friday, July 22, 2011

Rgoogle vis

http://code.google.com/p/google-motion-charts-with-r/

Hans Rossling style charts in R