coding beacon

[programming & visualization]

Tag Archives: R

Interactive Page with Data Science Skills in Demand

d-scientist-jd

Advertisements

Introducing my new blog: GTDiR

Getting Things Done in R (gtdir.wordpress.com) is my new blog which will be dedicated to what I personally develop in R and where I will share my thoughts on programming in the R environment.

Debugging in R

This is a collection of links related to debugging in R (to be updated)

Contents:
* Core debugging tools in R
* Core language tools in R
* Articles about debugging in R

Dynamic network visualization in R

One way to create editable networks is to use RCytoscape [link1, link2]. Another way is to use tkplot() from within “igraph” package. tkplot produces editable networks which you can adjust manually and save via tkplot.getcoords(). The latter method is described in the tutorial whose screenshot you can see below. Click on the screenshot to jump to the tutorial.

netw-vis_beginning.gif

###

An Attempt to Organize Datamining Resources

0. R Cheatsheets 

http://www.rstudio.com/resources/cheatsheets/


1. Choosing Visualization Tools

Three Golden Rules of Visualization Tools

Rule #1: No tool will turn you into a pro.
Rule #2: First learn one single tool very well.
Rule #3: Choose tools you are totally in love with.

Ggplot2

The main website by the author, Hadley Wickham: http://ggplot2.org/

* Ggplot2 package will give you the most return on the time you invest learning how to use it
A quick reference (cheatsheet) for ggplot2 “Data Visualization”
A short intro/tutorial for ggplot2

Ggvis

The main website: http://ggvis.rstudio.com/

Ggvis is used “…more for data exploration than data presentation. …ggvis makes many more assumptions about what you’re trying to do: this allows it to be much more concise, at some cost of generality.”
* “Ggvis provides a tree like structure allowing properties and data to be specified once and inherited by children.
Ggvis vs Ggplot2
Range selector for ggvis


2. Choosing Tools for Interactivity

Shiny

The main website: http://shiny.rstudio.com/gallery/

Shiny simply turns your R into a web server and lets you interact with your data through a browser. See the cheatsheet “Shiny” (also above).
Shiny is ok to start with, however you might wish to extend it with widgets or whatever fits your needs best.

Htmlwidgets

The main website: http://www.htmlwidgets.org/develop_intro.html

pros:
https://rstudio.github.io/dygraphs/gallery-range-selector.html
https://christophergandrud.github.io/networkD3/
http://www.htmlwidgets.org/showcase_threejs.html
https://github.com/htmlwidgets/sparkline

cons: large datasets might need to be uploaded to the client for some widgets


3. Building a Dashboard

Dashboard Theory

Stephen Few

Stephen’s Website
His book “Information Dashboard Design” on Amazon
Why Most Dashboards Fail (pdf)

Dashboards are Dumb (or how we sometimes delude ourselves with fancy dashboards)

The essence in one quote: “The key to usability is the association between appropriate controllers and the individual meters. In a car, the controllers are the steering wheel, the gas pedal, the brake pedal, the ignition switch, and the gearshift, primarily. Generally, there are one or two controllers associated with each meter and the action of each controller is usually proportional to the metric that appears on the meter (e.g. Gas pedal and brake pedal control speed; gas pedal and gear shift control RPM, etc.). There are more controllers on a plane, but the same relationships hold between controllers and meters, at least for older planes.”

Risk Communication Dashboards (pdf)

Nine User Interface Design Patterns

Ten Tips to Design User-Friendly Dashboards

Shiny and GoogleVis

http://www.r-bloggers.com/dashboards-in-r-with-shiny-and-googlevis/
EAHU scrsht

Shinydashboard

http://glimmer.rstudio.com/reinholdsson/shiny-dashboard/
shinydashboard001a

Examples

Security Dashboards in Shiny

Dashboard design Using MS Excel *

* In case you have to use Excel, have a look at “Sparklines for Excel” maintained by Fabrice Rimlinger: http://sparklines-excel.blogspot.com/


4. Managing Your Workflow

A workflow is used to automate repetitive operations you perform on the data. In case you generate so much data it turns into a hard-to-use pile, as was in my case, you can plan ahead and have a look at various tools that suit your needs. I am still a long way from organizing every aspect of the project into a coherent system, but my preliminary survey of available software makes me think that DAWN (see below) seems to be most flexible; however, it requires most programming skills. Other tools, such as Rapid Miner or Weka, can be used with the R programming environment almost out of the box.

Rapid Miner (open source)

https://rapidminer.com/ (R is integrated via a standard plugin downloadable from within the software itself)
rapidminer01

Dawn Science (open source)

Data Analysis WorkbeNch (DAWN) is an eclipse based workbench for doing scientific data analysis. It implements sophisticated support for the following:
(1) Visualization of data in 1D, 2D and 3D
(2) Python script development, debugging and execution
(3) Processing and Workflows for visual algorithms analyzing scientific data

http://www.dawnsci.org/ (use the source code & eclipse as the base)
DAWNsci01

Weka (open source)

http://www.cs.waikato.ac.nz/ml/weka/
weka001_image_downloaded_from_decisiontrees_net

How to integrate R into Weka: http://markahall.blogspot.ru/2012/07/r-integration-in-weka.html

Magittr (R package)

http://cran.r-project.org/web/packages/magrittr/index.html (included in dplyr package dependency)

This R package brings “forward-piping” operators, e.g. %>% (Just see the ‘cheatsheet’ “Data Wrangling” above.)
quote from the description of the package: “The magrittr package offers a set of operators which promote semantics that will improve your code by structuring sequences of data operations left-to-right (as opposed to from the inside and out), avoiding nested function calls, minimizing the need for local variables and function definitions, and making it easy to add steps anywhere in the sequence of operations.”

Other Datamining Software (commercial and open source)

http://decisiontrees.net/decision-trees-and-data-mining-software/


5. Data Mining/Analytics Workflow Theory

Introduction to Data Mining

saedsayad01

Understanding Data Analytics Project Life Cycle


6. Useful Quotes from R-Bloggers, Mostly

An Introduction to Statistical Learning with Applications in R (free pdf)

http://www-bcf.usc.edu/~gareth/ISL/
“This book provides an introduction to statistical learning methods. It is aimed for upper level undergraduate students, masters students and Ph.D. students in the non-mathematical sciences. The book also contains a number of R labs with detailed explanations on how to implement the various methods in real life settings, and should be a valuable resource for a practicing data scientist.”

Elements of Statistical Learning (free pdf)

http://statweb.stanford.edu/~tibs/ElemStatLearn/download.html
“The go-to bible for this data scientist and many others is The Elements of Statistical Learning: Data Mining, Inference, and Prediction by Trevor Hastie, Robert Tibshirani, and Jerome Friedman. Each of the authors is an expert in machine learning / prediction, and in some cases invented the techniques we turn to today to make sense of big data: ensemble learning methods, penalized regression, additive models and nonparemetric smoothing, and much much more.”

Machine learning

In-depth introduction to machine learning — 15 hours of expert videos

Free Ebooks on Machine Learning

Why you should learn R first for data science

http://www.r-bloggers.com/why-you-should-learn-r-first-for-data-science/ (selected quotes below):

Data wrangling
“It’s often said that 80% of the work in data science is data manipulation. … R has some of the best data management tools you’ll find. The dplyr package in R makes data manipulation easy. … When you “chain” the basic dplyr together, you can dramatically simplify your data manipulation workflow.”

Data visualization
“ggplot2 is one of the best data visualization tools around, as of 2015. What’s great about ggplot2 is that as you learn the syntax, you also learn how to think about data visualization. … there is a deep structure to all statistical visualizations. There is a highly structured framework for thinking about and creating all data visualizations. ggplot2 is based on that framework. By learning ggplot2, you will learn how to think about visualizing data.

Moreover, when you combine ggplot2 and dplyr together (using the chaining methodology), finding insight in your data becomes almost effortless.”

Machine learning
“While … most beginning data science students should wait to learn machine learning (it is much more important to learn data exploration first), machine learning is an important skill. When data exploration stops yielding insight, you need stronger tools … [and] R has some of the best tools and resources.

One of the best, most referenced introductory texts on machine learning, An Introduction to Statistical Learning, teaches machine learning using the R programming language. Additionally, the Stanford Statistical Learning course uses this textbook, and teaches machine learning in R.”

Data Sources

Quandl — free & premium financial market data (think “free Bloomberg in the format you want”)

Over 70 free large data repositories (updated) — a broad range of data (including finance related)

FDF Financial Data Finder

Datasets for Data Mining and Data Science at KDnuggets

Quant Finance Resources at CalTech

Ideas, Bells, and Whistles

Working with Time Series
Graphing Highly Skewed Data
In 4 Steps your Application (including R) is running on a Cloud Computing Cluster
Eight New Ideas From Data Visualization Experts
Hierarchical Clustering with R (featuring D3.js and Shiny)
A Growing List of 20+ Free Ebooks on Datamining
Big Data Made Simple: Feed on Visualization
My collection of visualization and datamining software and libraries


 7. Where to Ask for Help

General R questions

#R channel at Freenode (IRC network) — perhaps, the fastest way to get help with R
StackOverflow

Shiny

Shiny at rstudio.com
Shiny Google Group


Databases / formats for timeseries data

Databases

MongoDB (NoSQL)

SciDB

HDF (HDF5)

why HDF? http://www.hdfgroup.org/why_hdf/
https://en.wikipedia.org/wiki/Hierarchical_Data_Format
http://www.inside-r.org/packages/cran/hdf5/docs/hdf5
http://www.space-research.org/
users: http://www.hdfgroup.org/HDF5/users5.html

Interfaces

http://blog.revolutionanalytics.com/2014/01/fast-and-easy-data-munging-with-dplyr.html

Database Management Software

Tadpole https://github.com/hangum/TadpoleForDBTools/wiki Tadpole DB Hub is Unified infrastructure tool, various environment based interface for managing Apache Hive, Amazon RDS, CUBRID, MariaDB, MySQL, Oracle, SQLite, MSSQL, PostgreSQL and MongoDB databases. WEB base client tools (https://marketplace.eclipse.org/content/tadpole-db-hub)

Toad http://www.toadworld.com/m/freeware Sort of like a tadpole, just bigger and fatter

DBeaver http://dbeaver.jkiss.org/ Free multi-platform database tool for developers, SQL programmers, database administrators and analysts. Supports all popular databases: MySQL, PostgreSQL, SQLite, Oracle, DB2, SQL Server, Sybase, MongoDB, etc

dplyR resources

A must watch dplyr package video:

Fast and easy data munging, with dplyr

http://blog.revolutionanalytics.com/2014/01/fast-and-easy-data-munging-with-dplyr.html

RRRR: Relevant R-Related References

R_in_Eclipse1_quantmod
you can see this & more by running “demo(chartSeries, package = “quantmod”, ask = TRUE)” w/o quotes
(install.packages(“quantmod”) if you haven’t got that package)
 

Why use R

Pro’s: http://www.inside-r.org/why-use-r
Cons (when Matlab / Scilab are better): http://zoonek2.free.fr/UNIX/48_R/01.html (and even then, I would use non-R tools for prototyping only)

Start here:

Installation:

RStudio: (++installs in one simple step, ++RMarkdown notebooks, ++actively developed, ++no java dependency, –a bit more rigid IDE than Eclipse)

[1] Get R: http://cran.r-project.org/
[2] Get RStudio:http://www.rstudio.com/

Update: I switched from Eclipse to RStudio since I posted this.

Eclipse + StatET: (++extremely flexible IDE, –java dependency, –long first set-up time 20-min-to-1-hour, –one-person-project, –few updates)

[1] Get R (same link as [1] above): http://cran.r-project.org/
[2] Get rj package from within R command line interface: http://www.walware.de/it/rj/installation.mframe?jump=rpkg-installation
[3] http://www.eclipse.org/downloads/ (Eclipse: most flexible IDE, version recommended for R users: “Eclipse IDE for Java Developers”)
[4] http://www.walware.de/goto/statet (StatET: Eclipse R plugin, install within R!)
[5] Set up “Run Configuration” as described

The R Commander:

[1] This is worth having a look at if you need a simple yet powerful GUI: http://socserv.mcmaster.ca/jfox/Misc/Rcmdr/#menu
[2] Get it here: http://socserv.mcmaster.ca/jfox/Misc/Rcmdr/

Running R demos (many packages have them):

Run the following command after installing R:
demo(graphics, package = “graphics”, ask = TRUE)
To see all available demos, run
demo()
or
demo(package = .packages(all.available = TRUE))

Using R / Quick Intro(s) to R:

http://faculty.washington.edu/gyollin/AMATH463.php

On colors / graphical parameters

[1] http://research.stowers-institute.org/efg/R/Color/Chart/index.htm
[2] http://www.statmethods.net/advgraphs/parameters.html

Getting Around Eclipse StatET

Opening Multiple R Graphics Panes:
AdditionalRGraphView1

Then you need to know the following dev.xxx() functions to choose which window (device) to use to plot your graphics. Only one device is the active device. This is the device in which all graphics operations occur. Most of the following are self explanatory (or use the “?command_name” to get help).

dev.cur()
dev.list()
dev.next(which = dev.cur())
dev.prev(which = dev.cur())
dev.off()  #shuts down the specified (by default the current)
dev.off(which = dev.cur())
dev.set(which = dev.next())  #makes the specified device the active device
graphics.off() #shuts down all open graphics devices.

Graph Generation Via Automated StatET’s Support of GGPlot2:
Menu: [ R ] -> [ New Graph (‘ggplot2’)” ]
StatET automatically generates appropriate R code based on the following forms.
ggplot2_automation1

R Tips and Tricks

Tip: If R is not your first programming language, a very fast way of getting to know functions of ANY package is just typing a name of a function and running it. The console will display the code for that function.

Organizing R Source Code: http://stackoverflow.com/questions/1266279/how-to-organize-large-r-programshttp://stackoverflow.com/questions/2284446/organizing-r-source-code

How to include (source) R script in other scripts: http://stackoverflow.com/questions/6456501/how-to-include-source-r-script-in-other-scripts

Google’s R Style Guide: https://google-styleguide.googlecode.com/svn/trunk/Rguide.xml

Writing R Extensions:  http://cran.r-project.org/doc/manuals/R-exts.pdf

Dirty Tricks (book): http://zoonek2.free.fr/UNIX/48_R/02.html#17

Sourcing files using a relative path: http://stackoverflow.com/questions/12048436/r-sourcing-files-using-a-relative-path?rq=1

R References & Resources

Stackoverflow covers most (if not all the topics, incl. references to other sites): http://stackoverflow.com/tags/r/info

must-read intro: http://cran.r-project.org/doc/manuals/r-release/R-intro.html

important excerpt from the intro: http://cran.r-project.org/doc/manuals/r-release/R-intro.html#Object-orientation

this is huge: http://zoonek2.free.fr/UNIX/48_R/01.html

R-inside community: http://www.inside-r.org/

Using R for Time Series Analysis: http://a-little-book-of-r-for-time-series.readthedocs.org/en/latest/src/timeseries.html

Robust workflow for replicability and reliability with Eclipse + StatET https://web.stanford.edu/~messing/ComputationalSocialScienceWorkflow.html

Interactive graphics

http://www.rosuda.org/iPlots/
http://www.ggobi.org/
http://www.statmethods.net/advgraphs/interactive.html
 (includes some of the above links)

R-Related Blogs

http://onertipaday.blogspot.com.tr/2007/06/r-number-output-format.html

http://your-new-head.com/2013/12/02/best-ide-for-r-rstudio-vs-statet/ (StatET is better for working with Shiny)

Why Color Matters

Why Engineers and Scientists Should Be Worried About Color:
http://www.research.ibm.com/people/l/lloydt/color/color.HTM

Color Schemes Appropriate for Scientific Data Graphics:
http://geog.uoregon.edu/datagraphics/color_scales.htm

Quick reference: R colors by name or by index in the colors() vector:
http://research.stowers-institute.org/efg/R/Color/Chart/index.htm

GGobi: Exploring High-Dimensional Data

GGobi is an open source visualization program for exploring high-dimensional data. It provides highly dynamic and interactive graphics such as tours, as well as familiar graphics such as the scatterplot, barchart and parallel coordinates plots. Plots are interactive and linked with brushing and identification.

http://www.ggobi.org/

ggobi1

http://www.ggobi.org/book/

ggobi2bk