Task view: Statistics for the Social Sciences

Last updated on 2020-12-11 by John Fox

Social scientists use a wide range of statistical methods, most of which are not unique to the social sciences. Indeed, most statistical data analysis in the social sciences is covered by the facilities in the base and recommended packages, which are part of the standard R distribution. In the package descriptions below, I identify base and recommended packages on first mention; packages that are not specifically identified as "R-base" or "recommended" are contributed packages.

Other Relevant Task Views:

Beyond the base and contributed packages, many of the methods commonly employed in the social sciences are covered extensively in other CRAN task views, including the following. I will try to minimize duplicating information present in these other task views, given here in alphabetical order.

  • Bayesian: Methods of Bayesian inference in a variety of settings of interest to social scientists, including mixed-effects models.
  • Econometrics and Finance: In addition to methods of specific interest to economists and financial analysts, these task views covers a variety of commonly used regression models and methods, instrumental-variables estimation, models for panel data, and some time-series models.
  • MetaAnalysis: Methods of meta analysis for combining results from primary studies. If data on individuals in each study are available, meta analysis can be performed using mixed-effects models.
  • Multivariate: A broad, if far from exhaustive, catalog of methods implemented in R for analyzing multivariate data, from data visualization to statistical modeling, and including correspondence analysis for multivariate categorical data.
  • OfficialStatistics: Covers not only official statistics but also methods for collecting and analyzing data from complex sample surveys, such as the survey package.
  • Psychometrics: Extensively covers methods of scale construction, including item-response theory, multidimensional scaling, and classical test theory, along with other topics of interest in the social sciences, such as structural-equation modeling.
  • Spatial: Methods for managing, visualizing, and modeling spatial data, including spatial regression analysis.
  • SpatioTemporal: Methods for representing, visualizing, and analyzing data with information both on time and location.
  • Survival: Methods for survival analysis (often termed "event-history analysis" in the social sciences), beyond the basic and standard methods, such as for Cox regression, included in the recommended survival package.
  • TimeSeries: Methods for representing, manipulating, visualizing, and modeling time-series data, including time-series regression methods.

It is noteworthy that this enumeration includes about a third of the CRAN task views. Moreover, there are other task views of potential interest to social scientists (such as the Graphics task view on statistical graphics); I suggest that you look at the list of all task views on CRAN.

Linear and Generalized Linear Models:

Univariate and multivariate linear models are fit by the lm function, generalized linear models by the glm function, both in the R-base stats package. Beyond summary and plot methods for lm and glm objects, there is a wide array of functions that support these objects.

  • The generic anova function in the stats package constructs sequential ("Type-I") analysis of variance and analysis of deviance tables, and can also compute F and chisquare likelihood-ratio tests for nested models. (It is typical for other classes of statistical models in R to have anova methods as well, along with methods for other standard generics, such as coef, for returning regression coefficients; vcov for the coefficient covariance matrix; residuals; and fitted for fitted values of the response.) The generic Anova function in the car package (associated with Fox and Weisberg, An R Companion to Applied Regression, Second Edition, Sage, 2011) constructs so-called "Type-II" and "Type-III" partial tests for linear, generalized linear, and many other classes of regression models.
  • F and chisquare Wald tests for a variety of hypotheses are available from the coeftest and waldtest functions in the lmtest package, and the linearHypothesis function in the car package. All of these functions permit the use of heteroscedasticity and heteroscedasticity/autocorrelation-consistent covariance matrices, as computed, e.g., by functions in the sandwich and car packages. Also see the glh.test function in the gmodels package. Nonlinear functions of parameters can be tested via the deltaMethod function in the car package. The multcomp package includes functions for multiple comparisons. The vuong function in the pscl package tests non-nested hypotheses for generalized linear and some other models. Also see the rms package for tests on linear and generalized linear models.
  • The standard R distribution has excellent basic facilities for linear and generalized linear model "diagnostics," including, for example, hat-values and deletion statistics such as studentized residuals and Cook's distances (hatvalues, rstudent, and cooks.distance, all in the stats package). These are augmented by other packages: several functions in the car package, which emphasizes graphical methods, e.g., crPlots for component-plus-residual plots and avPlots for added-variable plots (among others), in addition to numerical diagnostics, such vif for (generalized) variance-inflation factors; the dr package for dimension reduction in regression, including SIR, SAVE, and pHd; and the lmtest package, which implements a variety of diagnostic tests (e.g., for heteroscedasticity, nonlinearity, and autocorrelation). Diagnostics may also be found in the rms package. See the influence.ME package for influential-data diagnostics for mixed-effects models.
  • Several packages contain functions that are useful for interpreting linear and generalized linear models that have been fit to data: The qvcalc packages computes "quasi variances" for factors in linear and generalized linear models (and more generally). The effects package constructs effect displays, including, e.g., "adjusted means," for linear, generalized linear, and many other regression models; diagnostic partial-residual plots are available for linear and generalized linear models. Similar, if somewhat less general, plots are available in the visreg package. The lsmeans implements so-called "least-squares means" for linear, generalized linear, and mixed models, and includes provisions for hypothesis tests.

Analysis of Categorical and Count Data:

Binomial logit and probit models, as well as Poisson-regression and loglinear models for contingency tables (including models for "over-dispersed" binomial and Poisson data), can be fit with the glm function in the stats package. For over-dispersed data, see also the aod package, the dispmod package, and the glm.nb function in the recommended MASS package (associated with Venables and Ripley, Modern Applied Statistics in S, Fourth Ed., Springer, 2002), which fits negative-binomial GLMs. The pscl package includes functions for fitting zero-inflated and hurdle regression models to count data. The multinomial logit model is fit by the multinom function in the recommended nnet package, and ordered logit and probit models by the polr function in the MASS package. Also see the mlogit for the multinomial logit model, the MNP package for the multinomial probit model, and the multinomRob package for the analysis of overdispersed multinomial data. The VGAM package is capable of fitting a very wide variety of fixed-effect regression models within a unified framework, including models for ordered and unordered categorical responses and for count data.

There are other noteworthy facilities for analyzing categorical and count data.

  • The table function in the R-base base package and the xtabs and ftable functions in the stats package construct contingency tables.
  • The chisq.test and fisher.test functions in the stats package may be used to test for independence in two-way contingency tables.
  • The loglm and loglin functions in the MASS package fit hierarchical loglinear models to contingency tables, the former as a front end to glm, the latter by iterative proportional fitting.
  • See the brglm and logistf packages for bias-reduction in binomial-response GLMs (useful, e.g., in cases of complete separation); the exactLoglinTest package for exact tests of loglinear models; the clogit function in the survival package for conditional logistic regression; and the vcd package for graphical displays of categorical data, including mosaic plots.
  • The gnm package estimates generalized nonlinear models, and can be used, e.g., to fit certain specialized models to mobility tables. Also see the catspec package for estimating various special models for square tables.
  • As previously mentioned, the Multivariate task view covers correspondence analysis of multivariate categorical data.
  • See the betareg package for beta regression of data on rates and proportions, a topic closely associated with categorical data.

Other Regression Models:

It is possible to fit a very wide variety of regression models with the facilities provided by the base and recommended packages, and an even wider variety of models with contributed packages, in addition to those covered extensively in other task views.

  • Nonlinear regression: The nls function in the stats package fits nonlinear models by least-squares. The nlstools includes several functions for assessing models fit by nls.
  • Mixed-effects models: The recommended nlme package, associated with Pinheiro and Bates, Mixed-Effects Models in S and S-PLUS (Springer, 2000), fits linear (lme) and nonlinear (nlme) mixed-effects models, commonly used in the social sciences for hierarchical and longitudinal data. Generalized linear mixed-effects models may be fit by the glmmPQL function in the MASS package, or (preferably) by the glmer function in the lme4 package. The lme4 package also largely supersedes nlme for linear mixed models, via its lmer function. Unlike lme, lmer supports crossed random effects, but does not support autocorrelated or heteroscedastic individual-level errors. Also see the lmeSplines, lmm, and MCMCglmm packages.
  • Generalized estimating equations: The gee and geepack packages fit marginal models by generalized estimating equations; see the multgee package for GEE estimation of models for correlated nominal or ordinal multinomial responses.
  • Nonparametric regression analysis: This is one of the conspicuous strengths of R. The standard R distribution includes several functions for smoothing scatterplots, including loess.smooth and smooth.spline, both in the stats package. The loess function, also in the stats package, fits simple and multiple nonparametric-regression models by local polynomial regression. Generalized additive models are covered by several packages, including the recommended mgcv package and the gam package, the latter associated with Hastie and Tibshirani, Generalized Additive Models (Chapman and Hall, 1990); also see the VGAM package. Some other noteworthy contributed packages in this area are gss, which fits spline regressions; locfit, for local-polynomial regression (and also density estimation) (Loader, Local Regression and Likelihood, Springer, 1999); sm, for a variety of smoothing techniques, including for regression (Bowman and Azzalini, Applied Smoothing Techniques for Data Analysis, Oxford, 1997); np, which implements kernel smoothing methods for mixed data types; and acepack for ACE (alternating conditional expectations) and AVAS (additivity and variance stabilization) nonparametric transformation of the response and explanatory variables in regression.
  • Quantile regression: Methods for linear, nonlinear, and nonparametric quantile regression are extensively provided by the quantreg package.
  • Regression splines: Parametric regression splines (as opposed to nonparametric smoothing splines), supported by the base-R splines package, can be used by lm, glm, and other statistical modeling functions that employ model formulas. See the bs (B-spline) and ns (natural spline) functions.
  • Very large data sets: The biglm package can fit linear and generalized linear models to data sets too large to fit in memory.

Other Statistical Methods:

Here is a brief survey of implementations in R of other statistical methods commonly used by social scientists.

  • Missing Data: Several packages implement methods for handling missing data by multiple imputation, including the (conspicuously aging) mix, norm, and pan packages associated with Shafer, Analysis of Incomplete Multivariate Data (Chapman and Hall, 1997), and the newer and more actively maintained Amelia, mi, mice, and mitools packages (the latter for drawing inferences from multiply imputed data sets). There are also some facilities for missing-data imputation in the general Hmisc package, which is described below, under "Collections". Some of the structural-equation modeling software discussed in the Psychometrics taskview is capable of maximum-likelihood estimation of regression models with missing data. The VIM package has functions for visualizing missing and imputed values.
  • Bootstrapping and Other Resampling Methods: The recommended package boot, associated with Davison and Hinkley, Bootstrap Methods and Their Application (Cambridge, 1997), has excellent facilities for bootstrapping and some related methods. Also notable is the bootstrap package, associated with Efron and Tibshirani, An Introduction to the Bootstrap (Chapman and Hall, 1993), which has functions for bootstrapping and jackknifing. In addition, see the functions Boot and bootCase in the car package, and nlsBoot in the nlstools package, along with the simpleboot package.
  • Model Selection: The step function in the stats package and the more broadly applicable stepAIC function in the MASS package perform forward, backward, and forward-backward stepwise selection for a variety of statistical models. The regsubsets function in the leaps package performs all-subsets regression. The BMA package performs Bayesian model averaging. The standard AIC and BIC functions are also relevant to model selection. Beyond these packages and functions, see the MachineLearning task view.
  • Social Network Analysis: There are several packages useful for social network analysis, including sna for sociometric analysis of networks (e.g., blockmodeling), network for manipulating and displaying network objects, latentnet for latent position and cluster models for networks, ergm for exponential random graph models of networks, and the "metapackage" statnet, all associated with the statnet project. Also see the RSiena and PAFit packages for longitudinal social network analysis; and the multiplex package, which implements algebraic procedures for the analysis of multiple social networks.
  • Propensity Scores and Matching: See the Matching, MatchIt, optmatch, and PSAgraphics packages, and the matching function in the arm package (associated with Gelman and Hill,Data Analysis Using Regression and Multilevel/Hierarchical Models, Cambridge, 2007).
  • Demographic methods: The demography package includes functions for constructing life tables, for analyzing mortality, fertility, and immigration, and for forecasting population.

Collections of Functions:

There are some packages that are so heterogeneous that they are difficult to classify, yet contain functions (typically in multiple domains) that are of interest to social scientists:

  • I have already made several references to the recommended MASS package, which is associated with Venables and Ripley's Modern Applied Statistics With S. Other recommended packages associated with this book are nnet, for fitting neural networks (but also, as mentioned, multinomial logistic-regression models); spatial for spatial statistics; and class, which contains functions for classification.
  • I've also mentioned the car package, associated with Fox and Weisberg, An R Companion to Applied Regression, Second Edition, which has a variety of functions supporting regression analysis, data exploration, and data transformation.
  • The Hmisc and rms packages (both mentioned above), associated with Harrell, Regression Modeling Strategies, Second Edition (Springer, 2015), provide functions for data manipulation, linear models, logistic-regression models, and survival analysis, many of them "front ends" to or modifications of other facilities in R.


Jangman Hong contributed to the general revision of this task view, as did other individuals who made a variety of specific suggestions.

If I have omitted something of importance not covered in one of the other task views cited, or if a new package or function should be mentioned here, please let me know.

Compilation of this task view was partly supported by grants from the Social Sciences and Humanities Research Council of Canada.


acepack — 1.4.1

ACE and AVAS for Selecting Multiple Regression Transformations

Amelia — 1.7.6

A Program for Missing Data

aod — 1.3.1

Analysis of Overdispersed Data

arm — 1.11-2

Data Analysis Using Regression and Multilevel/Hierarchical Models

betareg — 3.1-4

Beta Regression

biglm — 0.9-2.1

Bounded Memory Linear and Generalized Linear Models

BMA — 3.18.14

Bayesian Model Averaging

boot — 1.3-27

Bootstrap Functions (Originally by Angelo Canty for S)

bootstrap — 2019.6

Functions for the Book "An Introduction to the Bootstrap"

brglm — 0.7.1

Bias Reduction in Binomial-Response Generalized Linear Models

car — 3.0-10

Companion to Applied Regression

catspec — 0.97

Special models for categorical variables

class — 7.3-18

Functions for Classification

demography — 1.22

Forecasting Mortality, Fertility, Migration and Population Data

dispmod — 1.2

Modelling Dispersion in GLM

dr — 3.0.10

Methods for Dimension Reduction for Regression

effects — 4.2-0

Effect Displays for Linear, Generalized Linear, and Other Models

ergm — 3.11.0

Fit, Simulate and Diagnose Exponential-Family Models for Networks

exactLoglinTest — 1.4.2

Monte Carlo Exact Tests for Log-linear models

gam — 1.20

Generalized Additive Models

gee — 4.13-20

Generalized Estimation Equation Solver

geepack — 1.3-2

Generalized Estimating Equation Package

gmodels — 2.18.1

Various R Programming Tools for Model Fitting

gnm — 1.1-1

Generalized Nonlinear Models

gss — 2.2-2

General Smoothing Splines

Hmisc — 4.5-0

Harrell Miscellaneous

influence.ME — 0.9-9

Tools for Detecting Influential Data in Mixed Effects Models

latentnet — 2.10.5

Latent Position and Cluster Models for Statistical Networks

leaps — 3.1

Regression Subset Selection

lme4 — 1.1-26

Linear Mixed-Effects Models using 'Eigen' and S4

lmeSplines — 1.1-10

Add smoothing spline modelling capability to nlme.

lmm — 1.3

Linear Mixed Models

lmtest — 0.9-38

Testing Linear Regression Models

locfit — 1.5-9.4

Local Regression, Likelihood and Density Estimation

logistf — 1.24

Firth's Bias-Reduced Logistic Regression

lsmeans — 2.30-0

Least-Squares Means

MASS — 7.3-53.1

Support Functions and Datasets for Venables and Ripley's MASS

Matching — 4.9-7

Multivariate and Propensity Score Matching with Balance Optimization

MatchIt — 4.1.0

Nonparametric Preprocessing for Parametric Causal Inference

MCMCglmm — 2.30

MCMC Generalised Linear Mixed Models

mgcv — 1.8-34

Mixed GAM Computation Vehicle with Automatic Smoothness Estimation

mi — 1.0

Missing Data Imputation and Model Checking

mice — 3.13.0

Multivariate Imputation by Chained Equations

mitools — 2.4

Tools for Multiple Imputation of Missing Data

mix — 1.0-10

Estimation/Multiple Imputation for Mixed Categorical and Continuous Data

mlogit — 1.1-1

Multinomial Logit Models

MNP — 3.1-1

Fitting the Multinomial Probit Model

multcomp — 1.4-16

Simultaneous Inference in General Parametric Models

multgee — 1.7.0

GEE Solver for Correlated Nominal or Ordinal Multinomial Responses

multinomRob — 1.8-6.1

Robust Estimation of Overdispersed Multinomial Regression Models

multiplex — 2.9.4

Algebraic Tools for the Analysis of Multiple Social Networks

network — 1.16.1

Classes for Relational Data

nlme — 3.1-152

Linear and Nonlinear Mixed Effects Models

nlstools — 1.0-2

Tools for Nonlinear Regression Analysis

nnet — 7.3-15

Feed-Forward Neural Networks and Multinomial Log-Linear Models

norm — 1.0-9.5

Analysis of multivariate normal datasets with missing values

np — 0.60-10

Nonparametric Kernel Smoothing Methods for Mixed Data Types

optmatch — 0.9-13

Functions for Optimal Matching

PAFit —

Generative Mechanism Estimation in Temporal Complex Networks

pan — 1.6

Multiple Imputation for Multivariate Panel or Clustered Data

PSAgraphics — 2.1.1

Propensity Score Analysis Graphics

pscl — 1.5.5

Political Science Computational Laboratory

quantreg — 5.85

Quantile Regression

qvcalc — 1.0.2

Quasi Variances for Factor Effects in Statistical Models

rms — 6.1-1

Regression Modeling Strategies

RSiena — 1.2-23

Siena - Simulation Investigation for Empirical Network Analysis

sandwich — 3.0-0

Robust Covariance Matrix Estimators

simpleboot — 1.1-7

Simple Bootstrap Routines

sna — 2.6

Tools for Social Network Analysis

spatial — 7.3-13

Functions for Kriging and Point Pattern Analysis

statnet — 2019.6

Software Tools for the Statistical Analysis of Network Data

survival — 3.2-7

Survival Analysis

survey — 4.0

Analysis of Complex Survey Samples

sm — 2.2-5.6

Smoothing Methods for Nonparametric Regression and Density Estimation

vcd — 1.4-8

Visualizing Categorical Data

VGAM — 1.1-5

Vector Generalized Linear and Additive Models

VIM — 6.1.0

Visualization and Imputation of Missing Values

visreg — 2.7.0

Visualization of Regression Models

Task view list