Yunkyu Sohn
November 9, 2017
Research Associate, Department of Politics
This work is licensed under a Creative Commons Attribution 3.0 Unported License.
Party Polarization in United States Congress
Simulate parliamentary votes using the most famous model in political science:
\[ \text{Vote } \begin{cases} \text{Yea }, & \text{if } U(x_i,b_j) > U(x_i,s_j)\\ \text{Nay }, & \text{if } U(x_i,b_j) < U(x_i,s_j) \end{cases} \]
vote1 <- function(x,b,s){
Ub <- -(x-b)^2 ## U for choosing b
Us <- -(x-s)^2 ## U for choosing s
outcome <- (Ub>Us) ## Check if Ub is larger than Us
return(outcome) ## Output: whether b is selected instead of s
}
vote1(0.2,0.3,0.4)
vote1(0.2,0.5,0.4)
vote2 <- function(x,b,s){
N <- length(x) ## Number of legislators
J <- length(b) ## Number of Bills
Ub <- Us <- matrix(0,N,J) ## N by J
outcome <- matrix(0,N,J) ## N by J
#### ACTUAL COMPUTATIONS ####
return(outcome)} ## Output
for(i in c(1:N)){ ## Loop through legislators
for(j in c(1:J)){ ## Loop through bills
Ub[i,j] <- -(x[i]-b[j])^2 ## U for choosing b
Us[i,j] <- -(x[i]-s[j])^2 ## U for choosing s
outcome[i,j] <- (Ub[i,j] > Us[i,j]) ## Check if Ub > Us
}}
vote2 <- function(x,b,s){
N <- length(x) ## Number of legislators
J <- length(b) ## Number of Bills
Ub <- Us <- matrix(0,N,J) ## N by J
outcome <- matrix(0,N,J) ## N by J
for(i in c(1:N)){
for(j in c(1:J)){
Ub[i,j] <- -(x[i]-b[j])^2 ## U for choosing b
Us[i,j] <- -(x[i]-s[j])^2 ## U for choosing s
outcome[i,j] <- (Ub[i,j] > Us[i,j]) ## Check if Ub > Us
}}
return(outcome)} ## Output
## Run below many times
vote2(c(2:4)/10,c(1:5)/10,c(3,3,3,3,3)/10)
At this point you should have:
\[ \text{Vote } \begin{cases} \text{Yea }, & \text{if } U(x_i,b_j) - U(x_i,s_j) > 0\\ \text{Nay }, & \text{if } U(x_i,b_j) - U(x_i,s_j) < 0 \end{cases} \]
\[ \text{Vote } \begin{cases} \text{Yea }, & \text{with Probability } F[U(x_i,b_j) - U(x_i,s_j)]\\ \text{Nay }, & \text{with Probability } 1 - F[U(x_i,b_j) - U(x_i,s_j)] \end{cases} \]
\[ \text{Vote } \begin{cases} \text{Yea }, & \text{with Probability } F[U(x_i,b_j) - U(x_i,s_j)]\\ \text{Nay }, & \text{with Probability } 1 - F[U(x_i,b_j) - U(x_i,s_j)] \end{cases} \]
\[ \text{Vote } \begin{cases} \text{Yea }, & \text{if } U(x_i,b_j) - U(x_i,s_j) > 0\\ \text{Nay }, & \text{if } U(x_i,b_j) - U(x_i,s_j) < 0 \end{cases} \]
Specification of \( F(x) \)
pnorm(q, mean = 0, sd = 1)
How would you RELAIZE the probablistic events?
runif(n, min = 0, max = 1)
runif
to realize voting outcomes ## Compare how likely you will get TRUE
(pnorm(rep(10, 10)) > runif(10))
(pnorm(rep(0, 10)) > runif(10))
(pnorm(rep(-10, 10)) > runif(10))
Recap
vote2(x,b,s)
vote2 <- function(x,b,s){
N <- length(x) ## Number of legislators
J <- length(b) ## Number of Bills
Ub <- Us <- matrix(0,N,J) ## N by J
outcome <- matrix(0,N,J) ## N by J
for(i in c(1:N)){
for(j in c(1:J)){
Ub[i,j] <- -(x[i]-b[j])^2 ## U for choosing b
Us[i,j] <- -(x[i]-s[j])^2 ## U for choosing s
###### ONLY THIS LINE SHOULD BE MODIFIED!!! ######
outcome[i,j] <- (Ub[i,j] > Us[i,j]) ## Check if Ub > Us
###### ###### ###### ###### ###### ###### ######
}}
return(outcome)} ## Output
vote3 <- function(x,b,s){
N <- length(x) ## Number of legislators
J <- length(b) ## Number of Bills
Ub <- Us <- matrix(0,N,J) ## N by J
outcome <- matrix(0,N,J) ## N by J
for(i in c(1:N)){
for(j in c(1:J)){
Ub[i,j] <- -(x[i]-b[j])^2 ## U for choosing b
Us[i,j] <- -(x[i]-s[j])^2 ## U for choosing s
###### ###### ###### ###### ###### ###### ######
outcome[i,j] <- (pnorm(Ub[i,j]-Us[i,j]) > runif(1))
###### ###### ###### ###### ###### ###### ######
}}
return(outcome)} ## Output
## Compare vote2 and vote 3 by running them multiple times
vote3(c(1:3)/10,c(1:5)/10,c(3,3,3,3,3)/10)
vote2(c(1:3)/10,c(1:5)/10,c(3,3,3,3,3)/10)
At this point you should have:
runif()
Please fill out this survey so we know how we can improve the workshop
113th Senator Ideal Points
RCV <- read.csv("113RCV.csv")
View(RCV)
plot(RCV$ideology1,RCV$ideology2,col=RCV$party)
bill(J,DM,RM)
function using leading dimensional estimates (ideology1)
bill <- function(J,DM,RM){
###### ACTUAL COMPUTATIONS ######
result <- list(b=b,s=s)
return(result)}
b <- c(rep(DM,J/2),rep(RM,J/2)) ## Bill locations
b <- c(rep(DM,J/2),rep(RM,J/2)) + rnorm(J, mean = 0, sd = 0.1) ## add Gaussian-shaped noise
s <- b + rnorm(J,mean = 0, sd = 0.2) ## Status quos
bill(J,DM,RM)
function
bill <- function(J,DM,RM){
b <- c(rep(DM,J/2),rep(RM,J/2)) + rnorm(J, mean = 0, sd = 0.1) ## Bill locations
s <- b + rnorm(J,mean = 0, sd = 0.4) ## Status quos
result <- list(b=b,s=s)
return(result)}
DM <- mean(RCV$ideology1[which(RCV$party=='D')])
RM <- mean(RCV$ideology1[which(RCV$party=='R')])
proposals <- bill(2000,DM,RM)
out3 <- vote3(RCV$ideology1,proposals$b,proposals$s)
same <- out3 %*% t(out3) + (1-out3) %*% t(1-out3) # Number of votes casted same
dim(same)
same
matrix by party labelsDsame <- same[which(RCV$party=='D'),which(RCV$party=='D')]
Dsame <- Dsame[lower.tri(Dsame, diag = FALSE)]
Rsame <- same[which(RCV$party=='R'),which(RCV$party=='R')]
Rsame <- Rsame[lower.tri(Rsame, diag = FALSE)]
DRsame <- same[which(RCV$party=='R'),which(RCV$party=='D')]
par(mfrow=c(1,3));
hist(Dsame, prob = TRUE, main="Dem", xlab="# Votes",xlim = c(900,1200))
abline(v = median(Dsame), col = "red", lwd = 2)
hist(Rsame, prob = TRUE, main="Rep", xlab="# Votes",xlim = c(900,1200))
abline(v = median(Rsame), col = "red", lwd = 2)
hist(DRsame, prob = TRUE, main="{Dem, Rep}", xlab="# Votes",xlim = c(900,1200))
abline(v = median(DRsame), col = "red", lwd = 2)
Email List: Send an email to listserv@lists.princeton.edu with “Subscribe COMPASSWORKSHOPS” in the body and all other lines blank, including the subject