HSS8005
  • Module plan
  • Materials
  • Resources
  • Data
  • Assessment
  • Canvas
  1. Week 5
  2. Coding
  • Weekly materials

  • Introduction
  • Week 1
    • Theory
    • Coding
    • Application
  • Week 2
    • Theory
    • Coding
    • Application
  • Week 3
    • Theory
    • Coding
    • Application
  • Week 4
    • Theory
    • Coding
    • Application
  • Week 5
    • Theory
    • Coding
    • Application
  • Week 6
    • Theory
    • Coding
    • Application
  • Week 7
    • Theory
    • Coding
    • Application
  • Week 8
    • Theory
    • Coding
    • Application
  • Conclusions
  1. Week 5
  2. Coding

Week 5 coding

Hierarchies: Hierarchical data structures and multilevel modelling

The application workshop will use functions from the following packages:

Package : : Function Purpose
survey::svydesign() The survey package provides tools for analysing data from complex surveys, such as functions for managing survey weights based on survey sampling characteristics. The svydesign() function allows us to specify a complete survey design, with arguments that allow specification of, for example, cluster IDs, cluster sampling probabilities, strata, weights, or finite population correction.
survey::svyglm() The svyglm() function fits generalised linear models to data from a complex survey design, with inverse-probability weighting and design-based standard errors. Design characteristics as obtained from the svydesign() can be specified using the design argument.
sandwich::vcovCL() The sandwich package provides functions for obtaining covariance matrix estimators of parameter estimates in statistical models where certain model assumptions have been violated (e.g., due to heteroscedasticity or a lack of independence). The vcovCL() function estimates clustered variance-covariance matrices.
lmtest::coeftest() The lmtest package provides a collection of functions for diagnostic checking in linear regression models, as well as some generic tools for inference in parametric models. The coeftest() function performs z and (quasi-)t Wald tests of estimated coefficients. A related function - coefci() - can compute the corresponding Wald confidence intervals for these coefficients. It allows specifying a corresponding covariance matrix using an argument called vcov., which accepts as input either a pre-computed covariance matrix object or a function to extract the matrix on the fly (for example, the vcovCL() function from the {sandwich} package).
fixest::feols() The fixest package provides a family of functions to perform estimations with multiple ‘fixed effects’ (i.e. indicator variables coding clusters/categories of a clustering/grouping variable). The feols() function fits fixed effects ordinary least squares models using the formula syntax familiar from the base-R stats::lm() function, but with an extension that allows specifying variables representing the ‘fixed effects’ after a | sign. It allows doing all the estimations in one step - as opposed to how coeftest() works, requiring an lm() model object as an input first -, while also automatically hiding the ‘fixed effects’ indicators, so we do not need to be troubled about potentially very long lists of coefficients that we are not directly interested in when requesting a model summary(). The function includes a vcov argument for specifying how we want to handle the standard errors, just like in the case of coeftest().
lme4::lmer() The lme4 package provides functions for fitting linear and generalized linear mixed-effects models. The lmer() function fits linear mixed-effects regression models via restricted (or residual, or reduced) maximum likelihood (REML) or maximum likelihood.

Explore the package websites for an overview of the purposes and the main functions of these packages.

Theory
Application