This page contains R code I’ve written that I thought others might find useful. Comments regarding bugs or suggestions for improvement are very welcome.

**Dynamic Group-Level IRT Models**

`dgirt`

: An R package for estimating dynamic group-level item response theory (DGIRT) models. Developed in collaboration with James Dunham and Chris Warshaw. For related work see Caughey & Warshaw (2015), "Dynamic Estimation of Latent Opinion Using a Hierarchical Group-Level IRT Model".

**Nonparametric Combination**

`NPC`

: An R package for performing nonparametric combination of multiple dependent hypothesis tests (Pesarin and Salmaso 2010). Developed for my paper with Allan Dafoe and Jason Seawright, “Global Tests of Complex Hypotheses: A Nonparametric Framework for Testing Elaborate Theories.”

**Sensitivity Analysis for Unmatched Data**

I have contributed the following two functions to the R package rbounds, maintained by Luke Keele:

`SumTestSens`

: An R function for implementing the method of sensitivity analysis for comparing two unmatched groups described in Section 4.6 of Paul Rosenbaum’s “Observational Studies” (2nd Ed., 2002). It is designed to be used for sum statistics, such as Wilcoxon's rank sum statistic, which are appropriate for ordered or continuous data.

`FisherSens`

: An R function for sensitivity analysis of Fisher's exact test for count (binary) data from two unmatched groups. It is based on Section 4.4 of Paul Rosenbaum’s “Observational Studies” (2nd Ed., 2002).

**Bandwidth Selection for RD Estimation**

`OptBandCV`

: An R function for selecting the optimal bandwidth for local linear regression estimation in a regression-discontinuity (RD) context. Following the advice of Imbens & Lemieux (2008, Sec. 5), this function performs one-sided cross-validation so as to mimic the goal in RD, which is boundary estimation. It also employs a “triangular” or “edge” kernel, which has been shown to be optimal for boundary estimation (Cheng, Fan & Marron 1997). As of 12 April 2011, this function is a lot faster than it was previously. Modified on 12 June 2011 thanks to a suggestion from Andy Eggers.

`rdoptband_catch`

: An R function for optimal bandwidth calculation in RD, derived from the algorithm suggested by Imbens & Kalyanaraman (for details, see Guido Imbens’s software page). This function is much faster than OptBandCV. Unlike Imbens & Kalyanaraman’s Stata program rdob, my R function returns conventional standard errors. For a more realistic sense of the uncertainty of the estimate, I recommend bootstrapping it. In June 2011, I changed the function to allow the user to choose whether to implement the “catch” suggested by Imbens & Kalyanaraman (February 2009, p. 10, equation 4.11), which was dropped from latter versions of their paper but as of June 2011 was still used in rdob. In June 2012, I added an option to base the estimate of the third derivative on a subset of the data, which yields results closer to those provided by the Imbens-Kalyanaraman software (h/t Ian Gow).