8 Some notes on useful packages

8.1 The tidyverse family

"The tidyverse is an opinionated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures." The tidyverse family of R packages provides a comprehensive framework for many useful tools we need: from reading in data with readr [csv, tsv etc.] and haven [SPSS, Stata, SAS], wrangling it into the shape one desires with dplyr (mostly so called tidy-data) to visualization with ggplot2. These packages are not necessary to use R efficiently, but have a large following in the R community and often provide a more comfortable way to perform tedious tasks. A comprehensive guide to the tidyverse is provided in Hadley Wickham’s book R for Data Science.

8.2 Tidymodels

A set of modeling packages built on the tidyverse architecture that can be used for a multitude of tasks. https://www.tidymodels.org/

8.3 lmtest

"A collection of tests, data sets, and examples for diagnostic checking in linear regression models. Furthermore, some generic tools for inference in parametric models are provided."

8.4 MASS

Collection of many useful functions that originated as a support package for a book on applied statistics with S (the predecessor language of R). One example is its function mvrnorm that enables its user to draw from a multivariate normal with a given mean vector and covariance matrix.

library(MASS)
my_sample <-mvrnorm(n = 100, mu = c(0,0), Sigma = matrix(data = c(1,0.5,0.5,1), nrow = 2, byrow = T))
head(my_sample)
##             [,1]       [,2]
## [1,] -1.04001110 -1.1489202
## [2,] -1.16540797 -1.8931664
## [3,]  1.57256382  1.2056979
## [4,]  1.09718163 -0.8066595
## [5,] -0.02958764  0.5466597
## [6,]  0.96342122  0.2601426

8.5 AER - “Applied Econometrics with R”

Provides many useful function in the context of applied Econometrics. One prominent example is the function ivreg used for IV-estimation.

8.6 knitr

Formally an engine for dynamic report generation, knitr can be especially useful in your studies, if you want to use R in conjunction with markdown and output to different files. For example. this introduction is created from a bunch of Rmd files [R Markdown]. It can also be used to utilize R in a similar way to a Jupyter notebook, intermingling code and text freely.

8.7 Shiny

Used to build interactive web-aps with R. Somewhat more advanced, but very cool.

8.8 Faster Code

You might want to look at these packages:

  • Rcpp
  • parallel
  • data.table
  • future & future.apply

These can get complicated very quickly, so beware.