These illustrations are suggested in the endnotes of Political Games. This document sets up the code and implements all these analyses. You can replicate–or modify–any figure using the code fragments below.
First open R or Rstudio and install the hop package from github:
::install_github("macartan/hop") devtools
Then load it up:
library(hop)
Some normal form games: PD (#1), with and without equilibrium marked
<- matrix(c(2,3,0,1),2)
payoffs gt_bimatrix(payoffs, labels1=c("C","D"))
gt_bimatrix(payoffs, labels1=c("C","D"), nash=F, arrow1=F)
Chicken (#2): Pure strategy equilibriums marked
<- matrix(c(2,3,1,0),2)
payoffs gt_bimatrix(payoffs, labels1=c("C","D"))
Assurance (#3): Pure strategy equilibriums marked
<- matrix(c(3,2,0,1),2)
payoffs gt_bimatrix(payoffs, labels1=c("C","D"))
Illustrating the folk theorems (#4) for the Prisoner’s Dilemma:
<- matrix(c(2,3,0,1),2)
payoffs gt_folk(payoffs)
…and for the Assurance Game
<- matrix(c(3,2,0,1),2)
payoffs gt_folk(payoffs)
Condorcet Jury (#10): Gives an illustration of the law of large numbers
gt_jury(n_voters=7, probability_correct=.6)
Power indices (#13): Shows mapping between raw votes and power for two seemingly similar committees
gt_plot_banzhaf(weights = c(1, 1, 3,7,9,9), q_rule = .5)
gt_plot_banzhaf(weights = c(1, 1, 3,7,9,10), q_rule = .6)
Plott (#14): Illustrating the absence of stable points
<- matrix(c(0, 0, .5, 1, 1, 0), 2)
ideals gt_majority_phase(ideals)
<- matrix(c(.2, .2, .5, .9, 1, 0), 2)
ideals gt_majority_phase(ideals, raylengths=c(.5, .2))
Cycles (#15): Majority rule cycling
gt_cycles(n_voters = 3, n_motions = 25)
Legislative bargaining (#18): Returns equilibrium returns given recognition probabilities
<- c(.8,.2,0)
probabilities gt_leg_barg(probabilities)
## [1] "Anything goes: one of multiple equilibria selected"
## [1] "allocations: 0.796, 0.199, 0.005"
Cascades (#22): Where you end up after 50,000 random orderings
<- c(1,1,1,1,1,1,0,0,0)
signals <- replicate(50000, gt_cascade(sample(signals))$Declarations)
D mean(D[9,])
## [1] 0.89524
Nash bargaining (#27)
gt_nbs(u1 = function(x) x^.5, u2 = function (x) 1 - x)
Simple version with equilibrium only marked.
gt_nbs(solution_only = T)
Two Coase theorem illustrations (#31)
<- matrix(c(2,3,0,1),2)
payoffs gt_coase(payoffs, bargain = T, SQ = "minimax")
gt_coase(f=function(x) 1-x^2, bargain = T, SQ=c(0,1))
Clarke-Groves mechanism (#36). The circular indifference curves at the bottom right imply dominant strategies
gt_cgm (theta1 = .2, theta2 = .4)
Meltzer Richard (#40): Attitudes to taxes for a given endowment
gt_plot_mr(endowment = .5)
Evolutionary stability (#47)
gt_sss(error = 0, periods = 2)
Nash’s theorem illustration (best response functions) (#A3)
<- -matrix(c(0,1,.75,.25),2)
goalie_payoff gt_bimatrix(goalie_payoff, -goalie_payoff,
labels1=c("Left","Right"), P1="Goalie", P2="Shooter")
The best response graph – you can do one of these for any normal form game. In this case you can see that if the shooter plays left with probability 0.33, the goalie is willing to play any strategy (solid vertical line at 0.33); if the goalie plays left with probability 0.5, the shooter is willing to play any strategy (horizontal dotted line at 0.5).
gt_brgraph(goalie_payoff, -goalie_payoff,
labels1=c("Left", "Right"), P1="Goalie", P2="Shooter")
Extract the code used here: