2x2対称ゲームの最適反応と混合戦略ナッシュ均衡をグラフ表示する関数.
引数は2x2のマトリックス.
MixedNash<-function(m) {
a<-m[1,1]-m[2,1]
b<-m[2,2]-m[1,2]
p<-b/(a+b)
if (p <= 0 && a + b >= 0) {
bestres1<-cbind(c(0,1),c(1,1))
bestres2<-cbind(c(1,1),c(0,1))
Nash<-cbind(c(1),c(1))
} else if (p <= 0 && a + b < 0) {
bestres1<-cbind(c(0,1),c(0,0))
bestres2<-cbind(c(0,0),c(0,1))
Nash<-cbind(c(0),c(0))
} else if (p > 0 && p <= 1 && a>=0 && b >= 0) {
bestres1<-cbind(c(0,p,p,1),c(0,0,1,1))
bestres2<-cbind(c(0,0,1,1),c(0,p,p,1))
Nash<-cbind(c(0,p,1),c(0,p,1))
} else if (p > 0 && p <= 1 && a<0 && b < 0) {
bestres1<-cbind(c(0,p,p,1),c(1,1,0,0))
bestres2<-cbind(c(1,1,0,0),c(0,p,p,1))
Nash<-cbind(c(0,p,1),c(1,p,0))
}
par(pty = "s")
plot(bestres1,type="l",col="red",lwd=2,
xlim=c(0,1),ylim=c(0,1),asp=1,ann=FALSE)
par(new=T)
plot(bestres2,type="l",col="blue",lwd=2,
xlim=c(0,1),ylim=c(0,1),asp=1,xlab="p1",ylab="p2")
points(Nash,pch=19,cex=1.5)
}
赤はプレイヤー1,青はプレイヤー2,点はナッシュ均衡.
# non PD
MixedNash(matrix(c(5,1,3,0),2,2))
# PD
MixedNash(matrix(c(3,5,0,1),2,2))
# cordination
MixedNash(matrix(c(5,3,0,1),2,2))
# chicken
MixedNash(matrix(c(3,5,1,0),2,2))