Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction into R for historians (part 1: introduction)

316 views

Published on

Introduction into R for the European Historical Population Sample summerschool, Cluj-Napoca, Romana, 2015. Aimed at a public of historians with little quantitative skills

Published in: Data & Analytics
  • Be the first to comment

Introduction into R for historians (part 1: introduction)

  1. 1. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Introduction into R Richard L. Zijdeman 28 May 2015 Richard L. Zijdeman Introduction into R
  2. 2. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio 1 Quantitave research methods 2 Statistical Software 3 Introducing R vocabulary 4 Getting help 5 Installing R and RStudio Richard L. Zijdeman Introduction into R
  3. 3. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Quantitave research methods Richard L. Zijdeman Introduction into R
  4. 4. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Why To answer descriptive and explanatory questions on populations Richard L. Zijdeman Introduction into R
  5. 5. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Workflow: PTE problem (research question) theory (hypothesis) empirical test . . . with loops between T-E and P-T-E Richard L. Zijdeman Introduction into R
  6. 6. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Research Questions descriptive (to what extent. . . ) comparative (comparing two entities) trend (comparison over time) explanatory (focus on mechanism at hand) Richard L. Zijdeman Introduction into R
  7. 7. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Theory deductive reasoning explanans general mechanism condition explanandum (hypothesis) Richard L. Zijdeman Introduction into R
  8. 8. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Empirical test sample vs. population random vs. stratified samples testing technique, e.g.: T-test, correlation, regression Software required for faster analysis Richard L. Zijdeman Introduction into R
  9. 9. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Statistical Software Richard L. Zijdeman Introduction into R
  10. 10. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio The dangers of analysing with spreadsheets (e.g. MS Excel) tempting to input and clean data in the same sheet difficult to track cleaning rules defaults mess up your data (e.g. 01200 -> 1200) Richard L. Zijdeman Introduction into R
  11. 11. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Why use syntax (scripting) Efficiency (really) Quality (error checking) Replicatability Communication Richard L. Zijdeman Introduction into R
  12. 12. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio R R is open source, which is good and bad: anybody can contribute (check, improve, create code) free of charge but: R depends on collective action cannot ‘demand’ support sprawl of packages Richard L. Zijdeman Introduction into R
  13. 13. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio RStudio browser for R provides easy access to: scripts data plots manual Richard L. Zijdeman Introduction into R
  14. 14. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Introducing R vocabulary Richard L. Zijdeman Introduction into R
  15. 15. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio R script * series of commands to manipulate data * always save your script, NEVER change your data original data + script = reproducable research Richard L. Zijdeman Introduction into R
  16. 16. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio R Session * contains scripts, data, functions * can be saved 'workspace image' * prefer not to: + sessions are usually cluttered + only useful if running script takes time Richard L. Zijdeman Introduction into R
  17. 17. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Assignment * 'attach' values to an object (e.g. a variable) x <- 5 y <- 4 z <- x*y print(z) ## [1] 20 Richard L. Zijdeman Introduction into R
  18. 18. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Assignment II Try and imagine the potential of assignment x <- c(4, 3, 2, 1, 0, 27, 34, 35) # 'c' for concatenate values y <- -1 z <- x*y print(z) ## [1] -4 -3 -2 -1 0 -27 -34 -35 Richard L. Zijdeman Introduction into R
  19. 19. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Data.frame basically a table contains columns (variables) contains rows (cases) “flat table” in Kees’ terminology my.df <- data.frame(x,z) str(my.df) # show STRucture ## 'data.frame': 8 obs. of 2 variables: ## $ x: num 4 3 2 1 0 27 34 35 ## $ z: num -4 -3 -2 -1 0 -27 -34 -35 Richard L. Zijdeman Introduction into R
  20. 20. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Packages and libraries base R (core product) additional packages CRAN repository spread through ‘mirrors’ choose a local, but active mirror Github packages not on CRAN development versions of CRAN libraries Richard L. Zijdeman Introduction into R
  21. 21. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Getting help Richard L. Zijdeman Introduction into R
  22. 22. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Build-in help: “?” ?[function] / ?[package] e.g. “?plot” or “?graphics” check the index for user guides and vignettes Richard L. Zijdeman Introduction into R
  23. 23. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Cran website Manuals R FAQ R Journal Richard L. Zijdeman Introduction into R
  24. 24. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Online communities Stackoverflow Instance of Stackexchange Reputation based Q&A Specific lists for packages, e.g.: ggplot2 R-sig-mixed-models Richard L. Zijdeman Introduction into R
  25. 25. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Asking a question Getting an answer Search the web: others must have had this problem too If you raise a question: be polite be concise short background replicatable example debrief your efforts sofar Richard L. Zijdeman Introduction into R
  26. 26. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Installing R and RStudio Richard L. Zijdeman Introduction into R
  27. 27. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio Download R Instructions via http://www.r-project.org Choose a CRAN mirror http://cran.r-project.org/mirrors.html close, but active too! Romania hasn’t gone (yet!) Click on ‘Download R for Windows’ Follow usual installation procedure Double click on R You should now have a working session! Close the session, do not save workspace image Richard L. Zijdeman Introduction into R
  28. 28. Quantitave research methods Statistical Software Introducing R vocabulary Getting help Installing R and RStudio RStudio RStudio is found on http://www.rstudio.com Download the version for your OS (e.g. windows) http://www.rstudio.com/products/rstudio/download/ Install by double clicking on the downloaded file Start RStudio by double clicking on the icon You do not need to start R, before starting RStudio Richard L. Zijdeman Introduction into R

×