This content is from the fall 2016 version of this course. Please go here for the most recent version.

Overview

Due before class Wednesday October 26th.

Basic goal of the assignment:

Fork the hw04 repository

Go here to fork the repo for homework 04.

How do I do this?

The easiest approach uses the example pipeline as a template for your own assignment. You can get fancier if you want (e.g. create a Bash shell script that runs the pipeline, rather than another .R script), but you don’t have to go overboard with it.

What data should I use?

Whatever you want! The important thing is that the entire analysis is reproducible. That is, I will clone your repository on my computer, I will run the script that “rules them all”, and it should reproduce your results and analysis without any errors.1

I’m not creative and I can’t think of anything to analyze!

Okay, then analyze one of the datasets we’ve used before.

Download the data

Download the raw data. For example, using gapminder:

  • Option 1: via an R script using downloader::download or RCurl::getURL.

    downloader::download("https://raw.githubusercontent.com/jennybc/gapminder/master/inst/gapminder.tsv")
    cat(file = "gapminder.tsv",
      RCurl::getURL("https://raw.githubusercontent.com/jennybc/gapminder/master/inst/gapminder.tsv"))
  • Option 2: in a shell script using curl or wget.

    curl -O https://raw.githubusercontent.com/jennybc/gapminder/master/inst/gapminder.tsv
    wget https://raw.githubusercontent.com/jennybc/gapminder/master/inst/gapminder.tsv

Perform exploratory analysis

  • Bring the data in as data frame.
  • Save a couple descriptive plots to file with highly informative names.
  • Reorder the continents based on life expectancy. You decide the details.
  • Sort the actual data in a deliberate fashion. You decide the details, but this should at least implement your new continent ordering.
  • Write the Gapminder data to file(s), for immediate and future reuse.

Perform statistical analysis

  • Import the data created in the first script.
  • Make sure your new continent order is still in force. You decide the details.
  • Fit a linear regression of life expectancy on year within each country. Write the estimated intercepts, slopes, and residual error variance (or sd) to file.
  • Find the 3 or 4 “worst” and “best” countries for each continent. You decide the details.
  • Write the linear regression info for just these countries to file.

Generate figures

Create a figure for each continent, including data only for the 6-8 “extreme” countries, and write to file. One file per continent, with an informative name. The figure should give scatterplots of life expectancy vs. year, facetting on country, fitted line overlaid.

Automate the pipeline

Identify and test a method of running your pipeline non-interactively.

You could write a master R script that simply source()s the three scripts, one after the other. Tip: you will probably want a second “clean up / reset” script that deletes all the output your scripts leave behind, so you can easily test and refine your strategy, i.e. without repeatedly deleting stuff “by hand”. You can run the master script or the cleaning script from a shell with Rscript.

Provide a link to a page (oh hey there README.md) that explains how your pipeline works and links to the remaining files. Your peers and myself should be able to go to this landing page and re-run your analysis quickly and easily.

Aim higher!

Submit the assignment

Your assignment should be submitted as a set of R scripts, R Markdown documents, data files, figures, etc. Follow instructions on homework workflow. As part of the pull request, you’re encouraged to reflect on what was hard/easy, problems you solved, helpful tutorials you read, etc.

Rubric

Check minus: Cannot run the pipeline. Scripts require interactive coding to fix. Markdown documents are not generated. Graphs and tables don’t have appropriate labels or formatting.

Check: Solid effort. Hits all the elements. No clear mistakes. Easy to follow (both the code and the output). Nothing spectacular, either bad or good.

Check plus: Repository contains a detailed README.md explaining how the pipeline works. Displays innovative data analysis or coding skills. Graphs and tables are well labeled. Analysis is insightful. I walk away feeling I learned something.

Acknowledgments


  1. Okay, if I get an error because you used a package that I don’t already have, that’s my fault. But you know what I mean.

This work is licensed under the CC BY-NC 4.0 Creative Commons License.