library(StratTourn) library(xtable) library(ggplot2) library(reshape2) library(googleVis) library(dplyr) library(tidyr)
setwd("D:/libraries/StratTourn") setwd("D:/libraries/StratTourn/studies") tourn = load.tournament("Tourn_trade_20141123_082001.tou") # Data for each match md = tourn$dt md = add.other.var(md,c("strat","u")) md$delta.u = md$u - md$other.u # Names of all strategies strats = unique(md$strat) rank.dt = strat.rank.from.matches(md) # Data for each round file = tourn$rs.file rd = fread(file) rd = as.tbl(as.data.frame(rd)) rd = add.other.var(rd,c("strat","u")) # Names of all strategies strats = unique(rd$strat) # Perhaps select a subset of strategies used.strats = strats ard = rd if (!identical(used.strats,strats)) { rows = rd$strat %in% used.strats & rd$other.strat %in% used.strats rd = ard[rows,] }
rd = add.other.var(rd,c("x","cost","type")) rd$cost.pair = paste0(rd$type,"_",rd$other.type) rd <- mutate(rd, agreed = x+other.x<=100) sd <- summarise(group_by(rd,strat,other.strat, cost.pair), perc.agree=round(mean(agreed)*100,2)) rank.strats = rank.dt$strat sd$strat = factor(sd$strat, rank.strats, ordered=TRUE) sd$other.strat = factor(sd$other.strat, rank.strats, ordered=TRUE)
tbld <- summarise(group_by(sd,strat,other.strat), agree=mean(perc.agree)) tbld <- dcast(strat~other.strat, data=tbld, value.var="agree") tbld <- mutate(tbld,avrg=rowMeans(tbld[,2:ncol(tbld)]) ,rank=match(strat,rank.strats)) max.row =max.col(t(tbld[,-c(1,ncol(tbld))])) tbld[,-c(1,ncol(tbld))] <- sapply(2:(ncol(tbld)-1),FUN=function(x){ tbld[,x] <- round(tbld[,x],2) tbld[max.row[x-1],x] <- paste0(tbld[max.row[x-1],x],"*") return(tbld[,x]) }) view(as.data.frame(tbld))
Percentage of agreements between strategy pairs. The column "avrg" shows the average agreement rate given equal shares.
ggplot(data=sd, aes(cost.pair, fill=strat, y=perc.agree)) + geom_bar(stat="identity") +facet_grid(other.strat~strat) cat("\n")
The plot shows the percentage of rounds where an agreement was reached for the cost distributions High/High, High/Low, Low/High, Low/Low respectively for each strategy pair.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.