Monday, October 12, 2015

R Programming: Class Notes

Unit Testing Programming Assignments


If you, like me, are a professional software developer taking Coursera's R Programming, you want to write unit tests for your programming assignments. Heck, if you are any good, you will do TDD. RUnit and testthat are the packages you will need.

Execute R as root:
$ sudo R

Install RUnit:
> install.packages('RUnit', repos='http://cran.us.r-project.org')

Install testthat:
> install.packages('testthat', repos='http://cran.us.r-project.org')

A nice introduction to unit testing for R can be found here.

Install CRAN Packages Used in the Course


Install swirl:
> install.packages('swirl', repos='http://cran.us.r-project.org')

Sunday, October 11, 2015

The Data Scientist’s Toolbox: Class Notes

Types of Data Analysis

 

Here's a summary based on Wikipedia + lectures from The Data Scientist's Toolbox.
  • Descriptive: Summarize the sample using metrics such as central tendency (including the mean, median, and mode) and dispersion (including the range and quantiles of the data-set, and measures of spread such as the variance and standard deviation).
  • Exploratory: Approach to analyzing data sets (sample) to summarize their main characteristics and find relationships between variables (correlations), often with visual methods.
  • Inferential: Infers properties about the whole population from a sample (the population is assumed to be larger than the observed data set; in other words, the observed data is assumed to be sampled from a larger population), this includes testing hypotheses and deriving estimates.
  • Predictive: Statistical techniques (such as modeling, machine learning, and data mining) that analyze current and historical facts to make predictions about future.
  • Causal: Finds out what happens to one variable when you change another.
  • Mechanic: Understand the exact changes in variables that lead to changes in other variables for individual objects (Physics, Engineering).

Experimental Design Best Practices

 

  • First formulate the question you want to answer. 
  • Apply inferential analysis avoiding confounding or spurious correlations by blocking the variable (either by fixing it, i.e., making it a constant, or stratifying it, i.e., using data for all possible values of the given variable) or randomizing it.
  • Apply data dredging without being misled by apparently significant results. Automatically testing huge numbers of hypotheses about a single data set by exhaustively searching for combinations of variables that might show a correlation makes virtually certain that some false correlation appear statistically significant, since almost every data set with any degree of randomness is likely to contain some spurious correlations. Tests of statistical significance are based on the probability that an observation arose by chance and necessarily accept some risk of mistaken test results.

How to Share Data Online

 




The Data Scientist’s Toolbox: Install R & RStudio on Ubuntu 12.04

Here are instructions for preparing your development environment for Coursera's The Data Scientist's Toolbox.


Install R's Latest Version on Ubuntu 12.04

 

If you already have an older version installed:
$ sudo apt-get remove r-base-core  

Add the following line to /etc/apt/sources.list:
$ deb http://cran.rstudio.com/bin/linux/ubuntu precise/  

Add the R development repository:
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9  
$ sudo add-apt-repository ppa:marutter/rdev  
$ sudo apt-get update  
$ sudo apt-get upgrade 

Install R:

$ sudo apt-get install r-base  

Install CRAN Packages

 

Install the dependencies on Ubuntu:
$ sudo apt-get install php5-curl  
$ sudo apt-get install libcurl4-openssl-dev  
$ sudo apt-get install libxml2-dev  

Execute R as root:
$ sudo R

Install devtools:
> install.packages('devtools', repos='http://cran.us.r-project.org')  

Install slidify:
> library(devtools)  
> install_github('slidify', 'ramnathv')  
> install_github('slidifyLibraries', 'ramnathv')  


Install biocLite packages



Source the biocLite repository:
> source('http://bioconductor.org/biocLite.R')

Install biocLite base packages:
> biocLite() 

Install GenomicFeatures and AnnotationDbi:
> biocLite(c('GenomicFeatures', 'AnnotationDbi'))

List Available Packages

 

> options(repos=structure(c(CRAN='http://cran.us.r-project.org')))
> available_packages = available.packages() 
> head(rownames(available_packages), 10) 

Install RStudio

 

Download the debian install file from here and open it with Ubuntu Software Center.