R - the tool

Ilya Kashnitsky

15 December 2016

Что еще за R?

Rlogo

  • R - это язык и программная среда для статистических вычислений и визуализации
  • Open source
  • Самый популярный статистический пакет в мире
  • Потрясающее поличество разработчиков

Кто использует R?

  • Исследователи
  • Аналитики (Data analysts)
  • Программисты
  • Журналисты
  • Web дизайнеры
  • В академическом мире R de-facto стал главным инструментом

Иллюстрация

http://blog.revolutionanalytics.com/2014/05/companies-using-r-in-2014.html

Почему R?

“R offers a breadth and depth in statistical computing beyond what is available in commercial closed source products. Yet R remains, primarily, a programming language for the highly skilled statistician, and out of the reach of many.”

Williams, G. J. (2009). Rattle: A Data Mining GUI for R. The R Journal, 1/2, 45-55.

PRO

  • Open source
  • Reproducible
  • Удобен для работы с большими массивами данных
  • Главное: R способен с легкостью заменить ВСЕ программы, необходимые исследователю

CONTRA

  • Steep learning curve
  • Не идеален для сложных данных социологических опросов (metadata)

Примеры визуализации

https://ourworldindata.org

https://jschoeley.shinyapps.io/hmdexp

Election 2016: Exit Polls

http://www.nytimes.com/interactive/2016/11/08/us/politics/election-exit-polls.html

A Day in the Life of Americans

http://flowingdata.com/2015/12/15/a-day-in-the-life-of-americans

Where People Run in Major Cities

http://flowingdata.com/2014/02/05/where-people-run/

https://youtu.be/aOtQyfbRMQY

Reproducible research

Reproducibility

  • Воспроизводимость научных результатов - одна из ключевых проблем современного академического мира
  • Collaboration, Open Science (2015). Estimating the reproducibility of psychological science. Science, 349(6251), aac4716. https://doi.org/10.1126/science.aac4716
  • Из 100 статей удалось воспроизвести только 39

Literate programming

  • Идея literate programming зародилась в середине 80-х
  • Суть: код, комментарии, и результаты должны находиться в одном документе.

R notebooks

http://www.danielwells.me/human-lifespan-limit/

https://ikashnitsky.github.io/doc/misc/application-rostock-retreat/application-ik.nb.html

Tidyverse

Самый влиятельный R разработчик современности

Hadley Wickham

hadley

tidyverse

https://blog.rstudio.org/2016/09/15/tidyverse-1-0-0/

tidy data

Wickham, H. (2014). Tidy Data. Journal of Statistical Software, 59(10). Retrieved from http://www.jstatsoft.org/v59/i10

Tidy data is a standard way of mapping the meaning of a dataset to its structure.

A dataset is messy or tidy depending on how rows, columns and tables are matched up with observations, variables and types.

In tidy data:

  1. Для каждой переменной - свой стобец.
  2. Для каджого наблюдения - строка.
  3. Each type of observational unit forms a table.

Примеры и упражнения

  • Please follow me on the R script "examples-tidyverse.R"
  • Then proceed to "exercises.R"

Еще немного мотивации

http://qz.com/316906/the-dude-map-how-american-men-refer-to-their-bros

Visualizing life tables

http://flowingdata.com/2016/01/19/how-you-will-die

https://www.r-bloggers.com/pisa-2015-how-to-readprocessplot-the-data-with-r

American schools

http://www.nytimes.com/interactive/2016/04/29/upshot/money-race-and-success-how-your-school-district-compares.html

http://www.global-migration.info

http://www.demogr.mpg.de/papers/working/wp-2015-008.pdf

http://www.oeaw.ac.at/fileadmin/subsites/Institute/VID/dataexplorer/index.html

https://twitter.com/revodavid/status/808405998985740289
https://twitter.com/albertocairo/status/805944911010918400
https://twitter.com/rettungstweet/status/801012883026898945
https://twitter.com/bill_easterly/status/799988679439548416
https://twitter.com/simongerman600/status/799006705808003076
https://twitter.com/MaxCRoser/status/798525588835213312
https://twitter.com/rettungstweet/status/794479395163533312
https://twitter.com/dgoldenberg/status/783785617532395520
https://twitter.com/ikashnitsky/status/802310186560081920
https://twitter.com/ikashnitsky/status/785973218775478273

http://toddwschneider.com/posts/ballr-interactive-nba-shot-charts-with-r-and-shiny

Встроенные учебные датасеты

https://vincentarelbundock.github.io/Rdatasets/datasets.html

Пример

ggplot(airquality)+
        stat_ecdf(aes(x = Temp, color = factor(Month)), size=1)+
        scale_color_viridis(option = "B", discrete = T, end = .8)+
        theme_minimal()+ theme(legend.position = c(.1,.8))

Дополнительные пакеты для получения данных

The data packages

gapminder
eurostat
wpp2015
HMDHFDplus
OECD
WDI
acs

Russian data (Boris Demeshev)

http://bdemeshev.github.io/r_cycle/cycle_files/23_load_rus_data.html

gapminder

https://www.gapminder.org

Exercise

  • Compare e0 distributions in 1957, 1982, and 2007

eurostat

Как найти необходимые данные?

http://ec.europa.eu/eurostat/data/database
http://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing

wpp2015

https://esa.un.org/unpd/wpp/

HMDHFDplus

Human Mortality Database

http://www.mortality.org

Упражнение

Воспроизведем график
https://twitter.com/ikashnitsky/status/802310186560081920

https://gist.github.com/ikashnitsky/872d3a97390a60d26eeb64f0f5600067

Что дальше?

swirl

http://swirlstats.com

Coursera: Data Science

https://www.coursera.org/specializations/jhu-data-science

R-bloggers

https://www.r-bloggers.com

Я уверен, что написание магистерской диссертации - удобный момент, чтобы освоить R

Спасибо за внимание!