# dynIRT: Dynamic IRT estimation via Variational Inference In emIRT: EM Algorithms for Estimating Item Response Theory Models

## Description

`ordIRT` estimates an dynamic IRT model with two response categories per item, over several sessions. Ideal points over time follow a random walk prior, and the model originates from the work of Martin and Quinn (2002). Estimation is conducted using the variational EM algorithm described in the reference paper below. The algorithm will produce point estimates that are comparable to those of `MCMCdynamicIRT1d`, but will do so much more rapidly and also scale better with larger data sets.

## Usage

 `1` ``` dynIRT(.data, .starts = NULL, .priors = NULL, .control = NULL) ```

## Arguments

 `.data` a list with the following items. `rc` A (N x J) matrix of observed votes. ‘1’ and ‘-1’ are the yea and nay codes, while ‘0’ is a missing data code. `startlegis` An (N x 1) matrix indicating the first session that each legislator serves. Justices are assumed to serve in all terms between (and including) ‘startlegis’ to ‘endlegis’. Terms start at term 0, and end at term T - 1. `endlegis` An (N x 1) matrix indicating the last session that each legislator serves. Justices are assumed to serve in all terms between (and including) ‘startlegis’ to ‘endlegis’. Terms start at term 0, and end at term T - 1. `bill.session` A (J x 1) matrix of integers indicating the session each bill occurred in. Session count begins at 0, so the maximum value of bill.session is T - 1. `T` integer, indicating total number of consecutive terms in the data. Count starts from 1, so the maximum values of startlegis/endlegis/bill.session is T - 1, since they start from term 0. `.starts` a list containing several matrices of starting values for the parameters. The list should contain the following matrices: `alpha` A (J x 1) matrix of starting values for the item difficulty parameter α_j. `beta` A (J x 1) matrix of starting values for the item discrimination parameter β_j. `x` An (N x T) matrix of starting values for the respondent ideal points x_{it}, with rows indicating the legislator and columns indicating the session. Although not strictly necessary, it is generally good practice here to set the start values for legislators who are not serving in a particular session to 0, as that is what the point estimate for them will return. `.priors` list, containing several matrices of starting values for the parameters. The list should contain the following matrices: `x.mu0` A (N x 1) prior means matrix for respondent ideal points c_{i0}. These are generally set to be somewhat informative to resolve the standard rotational invariance problem in ideal point models. `x.sigma0` A (N x 1) prior variance matrix for respondent ideal points C_{i0}. `beta.mu` A (2 x 1) prior means matrix for all bill parameters α_j and β_j. `beta.sigma` A (2 x 2) prior covariance matrix for all bill parameters α_j and β_j. `omega2` A (N x 1) matrix with the evolutionary variance for each legislator ω^2_{ix}. `.control` list, specifying some control functions for estimation. Options include the following: `threads` integer, indicating number of cores to use. Default is to use a single core, but more can be supported if more speed is desired. `verbose` boolean, indicating whether output during estimation should be verbose or not. Set FALSE by default. `thresh` numeric. Algorithm will run until all parameters correlate at 1 - thresh across consecutive iterations. Set at 1e-6 by default. `maxit` integer. Sets the maximum number of iterations the algorithm can run. Set at 500 by default. `checkfreq` integer. Sets frequency of verbose output by number of iterations. Set at 50 by default.

## Value

An object of class `dynIRT`.

 `means` list, containing several matrices of point estimates for the parameters corresponding to the inputs for the priors. The list should contain the following matrices. `x` A (N x T) matrix of point estimates for the respondent ideal points x_{it}, with rows indicating respondent and columns indicating session of the estimated ideal point. Estimates will equal exactly 0 for legislator/period combinations in which the legislator did not serve. `alpha` A (J x 1) matrix of point estimates for the item difficulty parameter α_j. `beta` A (J x 1) matrix of point estimates for the item discrimination parameter β_j. `vars` list, containing several matrices of variance estimates for parameters corresponding to the inputs for the priors. Note that these variances are those recovered via variational approximation, and in most cases they are known to be far too small and generally unusable. Better estimates of variances can be obtained manually via the parametric bootstrap. The list should contain the following matrices: `x` A (N x T) matrix of variance estimates for the respondent ideal points x_{it}, with rows indicating respondent and columns indicating session of the estimated ideal point. Estimates will equal exactly 0 for legislator/period combinations in which the legislator did not serve. `alpha` A (J x 1) matrix of variance estimates for the item difficulty parameter α_j. `beta` A (J x 1) matrix of variance estimates for the item discrimination parameter β_j. `runtime` A list of fit results, with elements listed as follows:
• `iters` integer, number of iterations run.

• `conv` integer, convergence flag. Will return 1 if threshold reached, and 0 if maximum number of iterations reached.

• `threads` integer, number of threads used to estimated model.

• `tolerance` numeric, tolerance threshold for convergence. Identical to thresh argument in input to .control list.

 `N` Number of respondents in estimation, should correspond to number of rows in roll call matrix. `J` Number of items in estimation, should correspond to number of columns in roll call matrix. `T` Number of time periods fed into the estimation, identical to argument input from .data list. `call` Function call used to generate output.

## Author(s)

Kosuke Imai [email protected]

James Lo [email protected]

Jonathan Olmsted [email protected]

## References

Original model and the example is based off of Andrew Martin and Kevin Quinn, “Dynamic Ideal Point Estimation via Markov Chain Monte Carlo for the U.S. Supreme Court, 1953-1999.” Political Analysis 10(2) 134-153. Also see http://mqscores.berkeley.edu.

Variational model is described in Kosuke Imai, James Lo, and Jonathan Olmsted “Fast Estimation of Ideal Points with Massive Data.” Working Paper. Available at http://imai.princeton.edu/research/fastideal.html.

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28``` ```### Replication of Martin-Quinn Judicial Ideology Scores ### Based on July 23, 2014 (2014 Release 01) release of the Supreme Court Database ### Start values and priors based on replication code provided by Kevin Quinn data(mq_data) ## Estimate dynamic variational model using dynIRT() lout <- dynIRT(.data = mq_data\$data.mq, .starts = mq_data\$cur.mq, .priors = mq_data\$priors.mq, .control = {list( threads = 1, verbose = TRUE, thresh = 1e-6, maxit=500 )}) ## Extract estimate from variational model ## Delete point estimates of 0, which are justices missing from that session vi.out <- c(t(lout\$means\$x)) vi.out[vi.out==0] <- NA vi.out <- na.omit(vi.out) ## Compare correlation against MCMC-estimated result ## Correlates at r=0.93 overall, and 0.96 when excluding Douglas cor(vi.out, mq_data\$mq_mcmc) cor(vi.out[mq_data\$justiceName != "Douglas"], mq_data\$mq_mcmc[mq_data\$justiceName != "Douglas"]) ```