Home » Posts tagged 'rstats'
Tag Archives: rstats
Using a Linux only package in Windows #rstats
Here is some R code for using a R package that has only a tar.gz file available (used to load R packages in Linux) and no Zip file available (used to load R packages in Windows).
Step 1- Download the tar.gz file.
Step 2 Unzip it (twice) using 7zip
Step 3 Change the path variable below to your unzipped, downloaded location for the R sub folder within the package folder .
Step 4 Copy and Paste this in R
Step 5 Start using the R package in Windows (where 75% of the money and clients and businesses still are)
Caveat Emptor- No X Dependencies (ok!)
- WE DO NOT BREAK USERSPACE!
-
- Torvalds, Linus (2012-12-23). Linus Torvalds - LKML
Using R for Cricket Analysis #rstats #IPL
#Downloading the Data for batting across all formats of cricket library(XML) url="http://stats.espncricinfo.com/ci/engine/stats/index.html?class=11;template=results;type=batting" tables=readHTMLTable(url,stringsAsFactors = F) #Note we wrote stringsAsFactors=F in this to avoid getting factor variables, #since we will need to convert these variables to numeric variables table2=tables$"Overall figures" rm(tables) #Creating new variables from Span table2$Debut=as.numeric(substr(table2$Span,1,4)) table2$LastYr=as.numeric(substr(table2$Span,6,10)) table2$YrsPlayed=table2$LastYr-table2$Debut #Creating New Variables. In cricket a not out score is denoted by * which can cause data quality error. #This is treated by grepl for finding and gsub for removing the *. #Note the double \ to escape regex charachter table2$HSNotOut=grepl("\\*",table2$HS) table2$HS2=gsub("\\*","",table2$HS) #Creating a FOR Loop (!) to convert variables to numeric variables for (i in 3:17) { + table2[, i] <- as.numeric(table2[, i]) + } and we see why Sachin Tendulkar is the best (by using ggplot via Deducer)
Also see
- http://decisionstats.com/2013/04/14/using-r-for-cricket-analysis-rstats/
- http://decisionstats.com/2012/04/07/cricinfo-statsguru-database-for-statistical-and-graphical-analysi
-
Freaknomics Challenge-
- Prove match fixing does not and cannot exist in IPL
- Create an ideal fantasy team
Using R for Cricket Analysis #rstats
ESPN Crincinfo is the best site for cricket data (you can see an earlier detailed post on the database here http://decisionstats.com/2012/04/07/cricinfo-statsguru-database-for-statistical-and-graphical-analysis/ ), and using the XML package in R we can easily scrape and manipulate data
Here is the code.
library(XML) url="http://stats.espncricinfo.com/ci/engine/stats/index.html?class=1;team=6;template=results;type=batting" #Note I can also break the url string and use paste command to modify this url with parameters tables=readHTMLTable(url) tables$"Overall figures" #Now see this- since I only got 50 results in each page, I look at the url of next page table1=tables$"Overall figures" url="http://stats.espncricinfo.com/ci/engine/stats/index.html?class=1;page=2;team=6;template=results;type=batting" tables=readHTMLTable(url) table2=tables$"Overall figures" #Now I need to join these two tables vertically table3=rbind(table1,table2) Note-I can also automate the web scraping . Now the data is within R, we can use something like Deducer to visualize.
Created by Pretty R at inside-R.org
R 3.0 launched #rstats
The 3.0 Era for R starts today! Changes include better Big Data support.
Read the NEWS here
install.packages()has a new argumentquietto reduce the amount of output shown.- New functions
cite()andciteNatbib()have been added, to allow generation of in-text citations from"bibentry"objects. Acite()function may be added tobibstyle()environments. merge()works in more cases where the data frames include matrices. (Wish of PR#14974.)sample.int()has some support for n >= 2^31: see its help for the limitations.A different algorithm is used for(n, size, replace = FALSE, prob = NULL)forn > 1e7andsize <= n/2. This is much faster and uses less memory, but does give different results.list.files()(akadir()) gains a new optional argumentno..which allows to exclude"."and".."from listings.- Profiling via
Rprof()now optionally records information at the statement level, not just the function level. available.packages()gains a"license/restricts_use"filter which retains only packages for which installation can proceed solely based on packages which are guaranteed not to restrict use.- File ‘share/licenses/licenses.db’ has some clarifications, especially as to which variants of ‘BSD’ and ‘MIT’ is intended and how to apply them to packages. The problematic licence ‘Artistic-1.0’ has been removed.
- The
breaksargument inhist.default()can now be a function that returns the breakpoints to be used (previously it could only return the suggested number of breakpoints).
LONG VECTORS
This section applies only to 64-bit platforms.
- There is support for vectors longer than 2^31 – 1 elements. This applies to raw, logical, integer, double, complex and character vectors, as well as lists. (Elements of character vectors remain limited to 2^31 – 1 bytes.)
- Most operations which can sensibly be done with long vectors work: others may return the error ‘long vectors not supported yet’. Most of these are because they explicitly work with integer indices (e.g.
anyDuplicated()andmatch()) or because other limits (e.g. of character strings or matrix dimensions) would be exceeded or the operations would be extremely slow. length()returns a double for long vectors, and lengths can be set to 2^31 or more by the replacement function with a double value.- Most aspects of indexing are available. Generally double-valued indices can be used to access elements beyond 2^31 – 1.
- There is some support for matrices and arrays with each dimension less than 2^31 but total number of elements more than that. Only some aspects of matrix algebra work for such matrices, often taking a very long time. In other cases the underlying Fortran code has an unstated restriction (as was found for complex
svd()). dist()can produce dissimilarity objects for more than 65536 rows (but for examplehclust()cannot process such objects).serialize()to a raw vector is unlimited in size (except by resources).- The C-level function
R_alloccan now allocate 2^35 or more bytes. agrep()andgrep()will return double vectors of indices for long vector inputs.- Many calls to
.C()have been replaced by.Call()to allow long vectors to be supported (now or in the future). Regrettably several packages had copied the non-API.C()calls and so failed. .C()and.Fortran()do not accept long vector inputs. This is a precaution as it is very unlikely that existing code will have been written to handle long vectors (and the R wrappers often assume thatlength(x)is an integer).- Most of the methods for
sort()work for long vectors.
rank(),sort.list()andorder()support long vectors (slowly except for radix sorting).sample()can do uniform sampling from a long vector.
PERFORMANCE IMPROVEMENTS
- More use has been made of R objects representing registered entry points, which is more efficient as the address is provided by the loader once only when the package is loaded.
This has been done for packages
base,methods,splinesandtcltk: it was already in place for the other standard packages.Since these entry points are always accessed by the R entry points they do not need to be in the load table which can be substantially smaller and hence searched faster. This does mean that
.C/.Fortran/.Callcalls copied from earlier versions of R may no longer work – but they were never part of the API. - Many
.Call()calls in package base have been migrated to.Internal()calls. solve()makes fewer copies, especially whenbis a vector rather than a matrix.eigen()makes fewer copies if the input has dimnames.- Most of the linear algebra functions make fewer copies when the input(s) are not double (e.g. integer or logical).
- A foreign function call (
.C()etc) in a package without aPACKAGEargument will only look in the first DLL specified in the ‘NAMESPACE’ file of the package rather than searching all loaded DLLs. A few packages neededPACKAGEarguments added. - The
@<-operator is now implemented as a primitive, which should reduce some copying of objects when used. Note that the operator object must now be in package base: do not try to import it explicitly from package methods.
SIGNIFICANT USER-VISIBLE CHANGES
- Packages need to be (re-)installed under this version (3.0.0) of R.
- There is a subtle change in behaviour for numeric index values 2^31 and larger. These never used to be legitimate and so were treated as
NA, sometimes with a warning. They are now legal for long vectors so there is no longer a warning, andx[2^31] <- ywill now extend the vector on a 64-bit platform and give an error on a 32-bit one. - It is now possible for 64-bit builds to allocate amounts of memory limited only by the OS. It may be wise to use OS facilities (e.g.
ulimitin abashshell,limitincsh), to set limits on overall memory consumption of an R process, particularly in a multi-user environment. A number of packages need a limit of at least 4GB of virtual memory to load.64-bit Windows builds of R are by default limited in memory usage to the amount of RAM installed: this limit can be changed by command-line option –max-mem-size or setting environment variable R_MAX_MEM_SIZE.
Interview Dr. Ian Fellows Fellstat.com #rstats Deducer

Dr. Ian Fellows is a professional statistician based out of the University of California, Los Angeles. His research interests range over many sub-disciplines of statistics. His work in statistical visualization won the prestigious John Chambers Award in 2011, and in 2007-2008 his Texas Hold’em AI programs were ranked second in the world.
Applied data analysis has been a passion for him, and he is accustomed to providing accurate, timely analysis for a wide range of projects, and assisting in the interpretation and communication of statistical results. He can be contacted at info@fellstat.com
New Delhi UseRs March 2013 MeetUp #rstats
The fifth New Delhi UseRs Meet Up happened at Mimir Tech’s premises in Green Park, New Delhi. I presented on using GUIs for easier transitioning to R from other software but limited it to Deducer (for data visualization -specifically templates and facets in GGPLOT) and Rattle (for Data Mining). We also discussed a couple of things including how to apply R in other business domains, and open source alternatives to Meetup.com .
Interview Jeroen Ooms OpenCPU #rstats
Below an interview with Jeroen Ooms, a pioneer in R and web development. Jeroen contributes to R by developing packages and web applications for multiple projects.
Ajay- What are you working on these days?
Jeroen- My research revolves around challenges and opportunities of using R in embedded applications and scalable systems. After developing numerous web applications, I started the OpenCPU project about 1.5 year ago, as a first attempt at a complete framework for proper integration of R in web services. As I work on this, I run into challenges that shape my research, and sometimes become projects in their own. For example, the RAppArmor package provides the security framework for OpenCPU, but can be used for other purposes as well. RAppArmor interfaces to some methods in the Linux kernel, related to setting security and resource limits. The github page contains the source code, installation instructions, video demo’s, and a draft of a paper for the journal of statistical software. Another example of a problem that appeared in OpenCPU is that applications that used to work were breaking unexpectedly later on due to changes in dependency packages on CRAN. This is actually a general problem that affects almost all R users, as it compromises reliability of CRAN packages and reproducibility of results. In a paper (forthcoming in The R Journal), this problem is discussed in more detail and directions for improvement are suggested. A preprint of the paper is available on arXiv: http://arxiv.org/abs/1303.2140.
I am also working on software not directly related to R. For example, in project Mobilize we teach high school students in Los Angeles the basics of collecting and analyzing data. They use mobile devices to upload surveys with questions, photos, gps, etc using the ohmage software. Within Mobilize and Ohmage, I am in charge of developing web applications that help students to visualize the data they collaboratively collected. One public demo with actual data collected by students about snacking behavior is available at: http://jeroenooms.github.com/snack. The application allows students to explore their data, by filtering, zooming, browsing, comparing etc. It helps students and teachers to access and learn from their data, without complicated tools or programming. This approach would easily generalize to other fields, like medical data or BI. The great thing about this application is that it is fully client side; the backend is simply a CSV file. So it is very easy to deploy and maintain.
Ajay-What’s your take on difference between OpenCPU and RevoDeployR ?
Jeroen- RevoDeployR and OpenCPU both provide a system for development of R web applications, but in a fairly different context. OpenCPU is open source and written completely in R, whereas RevoDeployR is proprietary and written in Java. I think Revolution focusses more on a complete solution in a corporate environment. It integrates with the Revolution Enterprise suite and their other big data products, and has built-in functionality for authentication, managing privileges, server administration, support for MS Windows, etc. OpenCPU on the other hand is much smaller and should be seen as just a computational backend, analogous to a database backend. It exposes a clean HTTP api to call R functions to be embedded in larger systems, but is not a complete end-product in itself.
OpenCPU is designed to make it easy for a statistician to expose statistical functionality that will used by web developers that do not need to understand or learn R. One interesting example is how we use OpenCPU inside OpenMHealth, a project that designs an architecture for mobile applications in the health domain. Part of the architecture are so called “Data Processing Units”, aka DPU’s. These are simple, modular I/O units that do various sorts of data processing, similar to unix tools, but then over HTTPS. For example, the mobility dpu is used to calculate distances between gps coordinates via a simple http call, which OpenCPU maps to the corresponding R function implementing the harversine formula.
Ajay- What are your views on Shiny by RStudio?
Jeroen- RStudio seems very promising. Like Revolution, they deliver a more full featured product than any of my projects. However, RStudio is completely open source, which is great because it allows anyone to leverage the software and make it part of their projects. I think this is one of the reasons why the product has gotten a lot of traction in the community, which has in turn provided RStudio with great feedback to further improve the product. It illustrates how open source can be a win-win situation. I am currently developing a package to run OpenCPU inside RStudio, which will make developing and running OpenCPU apps much easier.
Ajay- Are you still developing excellent RApache web apps (which IMHO could be used for visualization like business intelligence tools?)
Jeroen- The OpenCPU framework was a result of those webapps (including ggplot2 for graphical exploratory analysis, lme4 for online random effects modeling, stockplot for stock predictions and irttool.com, an R web application for online IRT analysis). I started developing some of those apps a couple of years ago, and realized that I was repeating a large share of the infrastructure for each application. Based on those experiences I extracted a general purpose framework. Once the framework is done, I’ll go back to developing applications
Ajay- You have helped build web apps, openCPU, RAppArmor, Ohmage , Snack , mobility apps .What’s your thesis topic on?
Jeroen- My thesis revolves around all of the technical and social challenges of moving statistical computing beyond the academic and private labs, into more public, accessible and social places. Currently statistics is still done to mostly manually by specialists using software to load data, perform some analysis, and produce results that end up in a report or presentation. There are great opportunities to leverage the open source analysis and visualization methods that R has to offer as part of open source stacks, services, systems and applications. However, several problems need to be addressed before this can actually be put in production. I hope my doctoral research will contribute to taking a step in that direction.
Ajay- R is RAM constrained but the cloud offers lots of RAM. Do you see R increasing in usage on the cloud? why or why not?
Jeroen- Statistical computing can greatly benefit from the resources that the cloud has to offer. Software like OpenCPU, RStudio, Shiny and RevoDeployR all provide some approach of moving computation to centralized servers. This is only the beginning. Statisticians, researchers and analysts will continue to increasingly share and publish data, code and results on social cloud-based computing platforms. This will address some of the hardware challenges, but also contribute towards reproducible research and further socialize data analysis, i.e. improve learning, collaboration and integration.
That said, the cloud is not going to solve all problems. You mention the need for more memory, but that is only one direction to scale in. Some of the issues we need to address are more fundamental and require new algorithms, different paradigms, or a cultural change. There are many exciting efforts going on that are at least as relevant as big hardware. Gelman’s mc-stan implements a new MC method that makes Bayesian inference easier and faster while supporting more complex models. This is going to make advanced Bayesian methods more accessible to applied researchers, i.e. scale in terms of complexity and applicability. Also Javascript is rapidly becoming more interesting. Performance of Google’s javascript engine V8 outruns any other scripting language at this point, and the huge Javascript community provides countless excellent software libraries. For example D3 is a graphics library that is about to surpass R in terms of functionality, reliability and user base. The snack viz that I developed for Mobilize is based largely on D3. Finally, Julia is another young language for technical computing with lots of activity and very smart people behind it. These developments are just as important for the future of statistical computing as big data solutions.
About-
You can read more on Jeroen and his work at http://jeroenooms.github.com/ and reach out to him here http://www.linkedin.com/in/datajeroen



