Agreement scores and the scaling methods that place voters, judges or items on a line or in a plane.
Each section is one help page: what the function is for, the example
of its help page as it runs, and the plot of its result where the
package draws one. ?name gives the arguments and the value
in full.
votagr(): The share of the roll calls on which each pair
of legislators (judges, council members) voted the same way, over the
roll calls both took part in (Armstrong et al. 2021, section 3.2.2): the
similarity matrix that metric scaling of a chamber starts from.
# five judges on eight simulated cases
set.seed(1)
v <- matrix(rbinom(40, 1, 0.5), 5, 8)
v[2, 3] <- NA
votagr(v)$agree
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1.0000000 0.5714286 0.5000000 0.6250000 0.2500000
#> [2,] 0.5714286 1.0000000 0.4285714 0.4285714 0.7142857
#> [3,] 0.5000000 0.4285714 1.0000000 0.3750000 0.5000000
#> [4,] 0.6250000 0.4285714 0.3750000 1.0000000 0.1250000
#> [5,] 0.2500000 0.7142857 0.5000000 0.1250000 1.0000000amscal(): Recovers the positions of stimuli (parties,
candidates, courts) on one scale from respondents’ placements of them,
each respondent allowed an own shift and stretch of the scale: z_{ij} =
a_i + b_i z_j + epsilon_{ij}. The positions are the least-squares
solution of Aldrich and McKelvey (1977): with X_i = [1, z_i] and P_i the
projection onto its columns, z is the eigenvector of sum_i (I - P_i)
with the smallest eigenvalue orthogonal to the constant. Respondents
with a missing placement, or who place every stimulus at the same point,
are left out of that sum. The positions are standardised to mean 0 and
standard deviation 1, the first stimulus on the left. The respondent
intercepts and slopes are each respondent’s least-squares regression of
the placements on those positions (defined with two placements or more;
a slope of zero is set to 1e-10).
# 40 simulated respondents place five stimuli on a 1-7 scale
set.seed(1)
truth <- c(-1.2, -0.4, 0.1, 0.9, 1.5)
Z <- t(vapply(1:40, function(i) {
4 + rnorm(1, 0, 0.3) + runif(1, 0.6, 1.4) * truth + rnorm(5, 0, 0.3)
}, numeric(5)))
round(amscal(Z)$zhat, 2)
#> [1] -1.28 -0.59 -0.05 0.67 1.25
round((truth - mean(truth)) / sd(truth), 2)
#> [1] -1.30 -0.55 -0.08 0.68 1.24bbscal(): Recovers respondents’ positions from a
respondent-by-issue matrix of responses by the decomposition of Poole
(1998), X_0 = Psi W’ + J_n c’ + E_0 over the observed cells. Each
dimension starts from the sign-corrected respondent means (column
polarities from the pairwise correlations) and is refined by four
alternating least-squares sweeps on the residuals of the earlier
dimensions; up to five joint sweeps follow, stopping once the two
half-step error sums of squares differ by less than 0.01; the fitted Psi
W’ is then re-expressed by its singular value decomposition, Psi = U
D^{1/2}, W = V D^{1/2}. Respondents with fewer than
minscale responses are not scaled. The sign of each
dimension is arbitrary.
optcls(): Nonparametric ideal points from binary votes
in the spirit of Poole (2000): each vote’s cutting direction is the
unit-length difference of the mean positions of its yea and nay voters,
each legislator moves to the mean of the directions of the sides taken,
for maxit sweeps from each of nstart random
starts; the start with the fewest classification errors is kept. A vote
is split at the point of its direction that misclassifies fewest of its
voters, either side voting yea, so no vote has more errors than voting
with the majority.
ordocl(): Ordinal responses (a survey’s agree-disagree
items, a court’s graded outcomes) classified by item directions and
cutpoints in the spirit of Hare, Liu and Lupton (2018): respondents and
item directions start normal (seed 42, as set.seed() takes
it), the cutpoints of each item at equal steps on [-1, 1]; each sweep
moves every cutpoint to the median of the midpoints between neighbouring
respondents (in projection order) on either side of it, until the share
classified correctly stops changing.
dblctr(): B = - H D^{(2)} H with H = I - n^{-1} 1 1’ and
D^{(2)} the squared distances: the inner-product matrix of classical
scaling (Torgerson 1952).
cmdsf(): Torgerson scaling: the leading eigenvectors of
the double-centred squared distances (dblctr()), each
scaled by the square root of its eigenvalue (negative ones set to 0).
The fit is Mardia’s criterion, the kept positive eigenvalues over the
sum of all absolute ones; the stress is Kruskal’s stress-1 against the
positive distances. The sign of each dimension is arbitrary.
smacf(): Metric scaling by majorisation (de Leeuw 1977):
each step is the Guttman transform X arrow V^{+} B(X) X with V = (W 1) -
W, until the raw stress sum w_{ij} (d_{ij} - delta_{ij})^2 changes by
less than tol.
nmdsf(): Kruskal’s nonmetric scaling: at each step the
distances of the current configuration are fitted by a monotone
(isotonic, pool-adjacent- violators) regression on the order of the
dissimilarities, and one SMACOF step (smacf()) is taken
towards the fitted disparities, until no coordinate moves by
tol. The stress is Kruskal’s stress-1 of the last step. The
start is normal from seed 42, as set.seed() takes it.
mdsfit(): Mardia’s criterion: the share of each
dimension, its eigenvalue (0 when negative) over the sum of the absolute
values of all eigenvalues, and the cumulative shares.
indscl(): The weighted Euclidean model of Carroll and
Chang (1970): one stimulus space shared by every individual, each
individual weighting its dimensions. The configuration starts from
classical scaling of the mean dissimilarities; then the weights of each
individual and dimension (at least 0.01) and the stimulus coordinates
are updated in turn until the configuration changes by a relative
tol. The stress is the sum of squared differences between
each individual’s dissimilarities and the distances in its weighted
space.
unfstr(): The weighted sum of squared differences
between the distances from respondents to stimuli in a configuration and
the observed dissimilarities, over the observed cells.
mlsmu(): Unfolding of a respondent-by-stimulus matrix in
the alternating least-squares form of MLSMU6 (Poole 1984): respondents
and stimuli take gradient steps in turn against the row-centred
dissimilarities, each step scaled by the largest eigenvalue of the
gradient’s cross-product and both clouds centred, until the stress
(unfstr()) changes by a relative tol; of
nstart normal starts (seed 42, as set.seed()
takes it) the lowest stress is kept.
smunf(): Unfolding by majorisation: respondents and
stimuli are embedded in one space by SMACOF steps (smacf())
on the joint configuration with weight 1 between a respondent and a
stimulus and 0 within each set (Borg and Groenen 2005, chapter 14). The
start is normal from seed 42, as set.seed() takes it.
ipsrec(): In an unfolding the respondents’ coordinates
are their ideal points (Armstrong et al. 2021, section 4.5): the
respondent coordinates as a matrix.
procrs(): The orthogonal rotation (a proper rotation: no
reflection) that best carries the centred configuration X
onto the centred target in least squares, the target’s
centre added back (Gower and Dijksterhuis 2004).
nomutl(): The Gaussian utility of Poole and Rosenthal
(1985): legislator i gains U = beta (- sum_k w_k^2 (x_{ik} - z_{jk})^2)
from the outcome z_j; the probability of a yea is the logistic function
of the yea utility minus the nay utility.
nompr(): The probability of a yea of
nomutl() for one legislator and one vote.
nomll(): The log-likelihood of the observed votes under
the probabilities of nomutl() (clamped to [10^{-10}, 1 -
10^{-10}]) and gmp, the share of votes the model classifies
correctly.
dwnom(): A deterministic fixed-point fit in the
Gaussian-utility family of Poole and Rosenthal (1997): from normal
starts (seed 42, as set.seed() takes it), each vote’s
normal vector and midpoint follow the mean positions of its two sides,
and each legislator moves to the mean of the outcome locations (midpoint
plus or minus half the normal) of the sides taken, the cloud shrunk into
the unit ball, for maxit sweeps. The log-likelihood and the
share classified correctly use the probit of the Gaussian utility
difference with beta = 15 and equal dimension weights.
nombt(): Standard errors of ideal points by the
parametric bootstrap of Lewis and Poole (2004): votes are simulated from
the fitted logistic probabilities (beta = 15 times the projection minus
the cutpoint), absences kept, and each legislator re-estimated by 20
gradient steps from the fitted point plus normal noise of standard
deviation 0.1. Draws come from seed, as
set.seed() takes it.
irtlik(): The log-likelihood of the votes under the
probit item response model of Clinton, Jackman and Rivers (2004),
P(y_{ij} = 1) = Phi(beta_j’ x_i - alpha_j) (clamped to [10^{-10}, 1 -
10^{-10}]), with the share of votes classified correctly.
irtem(): The EM algorithm of Imai, Lo and Olmsted (2016)
for the probit model y^{ij} = alpha_j + beta_j’ x_i +
e{ij}, yea when y^_{ij} > 0, with priors x_i N(mu_x, s^2_x
I) and (alpha_j, beta_j) N(mu_b, s^2_b I). The E-step replaces y^* by
its truncated-normal mean (untruncated when absent); the M-step is the
pair of ridge regressions; the fixed point is the posterior mode. The
default start is alpha = beta = 0 and x from 50 steps of orthogonal
iteration on the cross-product of the column-centred +1/-1 votes.
irtpst(): Means, standard deviations and central 95%
intervals (R’s default quantile, type 7) of a chain of ideal points,
each draw first standardised dimension by dimension when
std is TRUE (location and scale are not
identified in IRT models; Jackman 2009).
cjrirt(): The probit ideal-point model P(y_{ij} = 1) =
Phi(beta_j’ x_i - alpha_j) with priors x_i N(0, I) and (alpha_j, beta_j)
N(0, v I) (Clinton, Jackman and Rivers 2004), by the Gibbs sampler of
Albert and Chib (1993): latent utilities from truncated normals, then
every (alpha_j, beta_j) and every x_i from its normal full conditional.
Every draw is an inverse normal of a uniform of Philox4x32-10 (Salmon et
al. 2011), sweep t on stream t of key seed, so a chain is
the same on every platform. The default start is the posterior mode of
irtem().
bamscl(): Respondent i places stimulus j at z_{ij} N(a_i
+ b_i z_j, 1 / (tau_i tau_j)): a respondent’s shift and stretch of the
common positions z, with noise whose precision factors into a respondent
and a stimulus part (Hare et al. 2015). Priors: a_i, b_i U(-100, 100),
tau_j G(0.1, 0.1), tau_i G(g_a, g_b) with g_a, g_b G(0.1, 0.1), and z
the standardised z^* N(0, 1), the polarity stimulus
restricted to the left. Gibbs sampling: a_i and b_i from truncated
normals, the precisions and g_b from conjugate gammas, g_a and each
z^*_j by slice sampling (Neal 2003). Draws come from seed,
as set.seed() takes it; rows with no placement are
dropped.
bmdsf(): Each observed dissimilarity is lognormal about
the distance between the two objects’ coordinates, delta_{ij} N(d_{ij},
1 / tau), with x_{ik} N(0, 10^2) and tau U(0, 10) (Bakker and Poole
2013). Coordinates are slice sampled one at a time (Neal 2003), tau
drawn from its truncated gamma; the chain starts from classical scaling
plus small normal noise. The likelihood is unchanged by translation,
rotation and reflection, so every draw is aligned (translation and
rotation) onto the posterior mean. Zero, negative or missing
dissimilarities are left out. Draws come from seed, as
set.seed() takes it.
bunfld(): The lognormal model of bmdsf()
for a respondent-by-stimulus matrix: delta_{ij} N(x_i - z_j , 1 / tau),
N(0, 10^2) priors on every coordinate and tau U(0, 10) (Bakker and Poole
2013). Feeling thermometers T on 0-100 enter as delta = (100 - T) / 50.
Given the stimuli the respondents are independent, and the other way
round, so each block is slice sampled at once, dimension by dimension;
draws are aligned on the stimuli. The chain starts from the singular
value decomposition of the centred matrix. Draws come from
seed, as set.seed() takes it.
anomin(): Legislator i votes yea on roll call j with
probability Phi(u_{ij}), u_{ij} = Q_{ij} + alpha (G_{ij} - Q_{ij}),
where Q is the quadratic and G the Gaussian utility difference of the
distances to the yea and nay outcomes, with weight 0.5 (Carroll et
al. 2013): alpha = 1 is Gaussian utility, alpha = 0 quadratic. beta has
a flat prior on (0, Inf), alpha on [0, 1]; coordinates carry the
hierarchical penalty -x’Sx/2 with S redrawn each sweep from an inverse
Wishart. Every coordinate, beta and alpha are slice sampled (Neal 2003:
width 8, at most 3 steps out); starts are uniform on (-1, 1), beta = 10,
alpha = 0.7. Each draw is then centred on its legislators and rotated
onto the posterior mean, the polarity legislator positive.
Roll calls whose minority side is below lop and legislators
with fewer than minvotes votes are dropped first. Draws
come from seed, as set.seed() takes it.
# 20 simulated legislators on a line, 30 roll calls, some votes flipped
set.seed(1)
x <- seq(-1, 1, length.out = 20)
V <- outer(x, runif(30, -0.7, 0.7), ">") * 1
flip <- sample(length(V), 30)
V[flip] <- 1 - V[flip]
f <- anomin(V, nsamp = 20, burn = 10, minvotes = 10, polarity = 20)
f$alpha
#> [1] 0.9071232ordirt(): Each ordinal response is a thresholded latent
normal, y^{ij} = lambda{j0} + lambda_j’ phi_i + e_{ij},
y_{ij} = c when gamma_{j,c-1} < y^_{ij} <= gamma_{j,c}, with
gamma_{j1} = 0, phi_i N(0, I), loadings lambda_j N(0, I / L_0) and a
flat prior on the free cutpoints (Quinn 2004). Each sweep updates the
free cutpoints of every item by the Metropolis-Hastings step of Cowles
(1996) with y^* integrated out (step sizes tuned during the burn-in
only), then draws y^*, the loadings and the ideal points from their full
conditionals. The chain starts from the leading principal components of
the mean-filled responses. Each draw is reflected so the first item
loads positively (rotated onto the first draw with several dimensions).
Draws come from seed, as set.seed() takes
it.
dynirt(): The one-dimensional dynamic item response
model of Martin and Quinn (2002), made for courts: a vote is cast when
z_{jk} = -alpha_k + beta_k theta_{j,t(k)} + {jk} > 0; the ideal
points follow a random walk, theta{j,0} N(e_0, E_0), theta_{j,t}
N(theta_{j,t-1}, tau^2_j); alpha_k N(a_0, 1/A_0), beta_k N(b_0, 1/B_0).
Each sweep draws the latent utilities, every case’s (alpha, beta), every
justice’s path by forward filtering and backward sampling and, when
c0 and d0 are positive, the evolution
variances from IG((c_0 + T)/2, (d_0 + SS)/2). A draw is reflected
whenever the anchor member’s mean ideal point is negative.
The chain starts from the first principal component of the votes. Draws
come from seed, as set.seed() takes it.
# 12 simulated justices over three terms of 15 cases
set.seed(7)
period <- rep(1:3, each = 15)
walk <- function(s) s + cumsum(c(0, rnorm(2, 0, 0.3)))
truth <- t(vapply(rnorm(12), walk, numeric(3)))
p <- pnorm(-rep(rnorm(45, 0, 0.5), each = 12) +
rep(rnorm(45, 1.5, 0.5), each = 12) * truth[, period])
V <- matrix(rbinom(length(p), 1, p), 12)
f <- dynirt(V, period, nsamp = 100, burn = 50)
cor(as.numeric(f$theta), as.numeric(truth))
#> [1] 0.9013526anchv(): Corrects self-ratings for differential item
functioning with anchoring vignettes, nonparametrically (King et
al. 2004): each respondent’s ratings of the vignettes, sorted, give that
respondent’s thresholds between categories, and the self-rating is
recoded as the number of thresholds at or below it. The spread of each
threshold across respondents measures the differential item
functioning.
scboot(): Standard errors and percentile intervals of
Aldrich-McKelvey stimulus positions (amscal()) or Basic
Space weights (bbscal(), first dimension, of the matrix or
of its transpose) by resampling respondents with replacement (Efron and
Tibshirani 1993). Draws come from seed, as
set.seed() takes it. The sign of a Basic Space dimension is
arbitrary, so its replicates are best compared after aligning them.
nrmvec(): Projects an outside measure (a judge’s party,
a legislator’s vote share) into an ideal-point space: the least-squares
regression of the measure on the coordinates, its slopes scaled to unit
length give the direction along which the measure rises, with its angle
and the R^2 (Armstrong et al. 2021, section 2.6).
cutlns(): The ends of each vote’s cutting line n_1 x +
n_2 y = c across the horizontal range xlim (or from -10 to
10 vertically when the line is vertical), its midpoint and the angle of
its normal: the lines of a Coombs mesh (Poole 2005). The plot itself is
not drawn here.
wrdfsh(): The Poisson scaling model of Slapin and
Proksch (2008), y_{ij} ((psi_i + alpha_j + beta_j omega_i)), for
documents (judgments, briefs, platforms) by their word counts:
alternating Newton steps on the document positions omega (standardised
after each sweep, the word parameters adjusted to keep the linear
predictor) and on the word parameters, from normal starts (seed 42, as
set.seed() takes it), until the positions change by a
relative tol. The sign of the scale is arbitrary.
set.seed(1)
wrdfsh(matrix(rpois(600, 5), 20), maxit = 20)$pos
#> [1] 1.15570659 0.25111445 0.01650556 -1.49106129 0.13088144 -1.07365520 1.05617759
#> [8] -0.83530154 -0.99936159 0.25353260 -0.31732379 -1.84826884 -0.20769336 1.06437931
#> [15] 1.98755859 0.68871590 0.01462927 -0.99868738 1.10180015 0.05035155