B.3 Resources

ds4psy: Datasets

B.3.1 Data in base R

As R includes a datasets package, every version of R comes with a collection of datasets. To learn which datasets exist and obtain basic information about them, call

library(help = "datasets") 

To obtain information about any particular dataset x, call ?x. Throughout this book, we use quite a few of the datasets in examples and exercises.

# Info on datasets:
?anscombe 
?cars
?sleep
?Titanic

# Check dimensions:
dim(ChickWeight)
dim(iris)
dim(sleep)     # Student's Sleep Data
dim(Titanic)   # see also dim(FFTrees::titanic)

As the datasets are included to illustrate particular types of data or tasks, they vary widely in size and shape. For instance, the Titanic data is stored as a 4-dimensional array (but can easily be transformed into a data frame by as.data.frame(Titanic)). By contrast, the Nile dataset contains a single time series with measurement values of the annual flow of the river Nile from the years 1871 to 1970:

# ?Nile
length(Nile)
#> [1] 100
typeof(Nile)
#> [1] "double"

plot(Nile, col = unikn::Seeblau, lwd = 3)

B.3.2 Data in R packages

Many R packages contain datasets for demonstration purposes. For instance, this book primarily uses a variety of datasets — some real ones, but also smaller tables that were generated to highlight or practice particular aspects or tasks — that come with the ds4psy package (Neth, 2023).

Including data in packages has both benefits and costs. It makes the corresponding tables easily accessible, but this convenience comes at the price that students no longer learn to retrieve and load real data sets that often require extensive pre-processing. To somewhat alleviate this dilemma, we store some datasets in a variety of formats on a web server (at http://rpository.com/ds4psy/, see Chapter 6 on Importing data).

The R packages of the tidyverse (Wickham, 2023) also contain many datasets. For instance, we can explore and use the following datasets for practice and illustration purposes:

  • ggplot2: diamonds, economics, mpg, msleep (see Chapter 2)

  • dplyr: starwars, band_members, band_instruments, nasa, storms, etc. (see Chapters 3, 4, 5, and 8)

  • tidyr: table1table5, billboard, construction, fish_encounters, population, smiths, us_rent_income, who, world_bank_pop (see Chapter 7)

  • stringr: words, sentences (see Chapter 9)

  • lubridate: lakers (see Chapter 10)

Other packages with many small and large data sets include:

This list is incidental and only guaranteed to be incomplete. See Rdatasets for a more systematic collection of over 2000 data sets distributed through R and its packages.

B.3.3 Online sources

The web is full of data, of course, but most of it needs sound data science and a sound dose of skepticism to be of any use. Nevertheless, here are some good starting points for finding free data:

Collections of datasets

Economic datasets

  • The AER package provides many datasets for Applied Econometrics with R (Kleiber and Zeileis, 2008)

  • FRED provides mostly time series data on economic trends

  • IPUMS provides census and survey data on various issues from around the world

  • Using survey data of the Pew Research Center requires a free account

  • UC DATA provides data in the areas of political, social and health sciences.

Specific datasets

References

Friendly, M. (2023). HistData: Data sets from the history of statistics and data visualization. Retrieved from https://friendly.github.io/HistData/
Horst, A., Hill, A., & Gorman, K. (2022). Palmerpenguins: Palmer archipelago (antarctica) penguin data. https://doi.org/10.5281/zenodo.3960218
James, G., Witten, D., Hastie, T., & Tibshirani, R. (2013). An introduction to statistical learning (Vol. 112). Retrieved from http://faculty.marshall.usc.edu/gareth-james/ISL/
Neth, H. (2023). ds4psy: Data science for psychologists. https://doi.org/10.5281/zenodo.7229812
Phillips, N. D. (2017). yarrr: A companion to the e-Book "YaRrr!: The Pirate’s Guide to R". Retrieved from www.thepiratesguidetor.com
Phillips, N. D., Neth, H., Woike, J., & Gaissmaer, W. (2023). FFTrees: Generate, visualise, and evaluate fast-and-frugal decision trees. Retrieved from https://CRAN.R-project.org/package=FFTrees
Venables, W. N., & Ripley, B. D. (2002). Modern applied statistics with S (4th ed.). Retrieved from http://www.stats.ox.ac.uk/pub/MASS4
Wickham, H. (2023). tidyverse: Easily install and load the ’tidyverse’. Retrieved from https://tidyverse.tidyverse.org
Yu, A. Z., Ronen, S., Hu, K., Lu, T., & Hidalgo, C. A. (2016). Pantheon 1.0, a manually verified dataset of globally famous biographies. Scientific Data, 3(1), 1–16. https://doi.org/10.1038/sdata.2015.75