library(StratTourn)
library(xtable)
library(ggplot2)
library(reshape2)
library(googleVis)
library(dplyr)
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,]
}
end.t = 10
start.t = 1
rd = add.other.var(rd,c("cost","type"))
rd$cost.pair = paste0(rd$type,"_",rd$other.type)

Performance of strategies for different cost types

library(tidyr)
total = summarise(group_by(rd,strat), u=round(mean(u),2))
total$cost.pair ="all"

sd = summarise(group_by(rd,cost.pair,strat), u=round(mean(u),2))
sd = ungroup(sd)
sd = rbind(total,sd)
sd$cost.pair = paste0("u_",sd$cost.pair)
d = spread(ungroup(sd),key = cost.pair,value = u)
d = arrange(d, -u_all)

view(as.data.frame(d))

Average payoffs assuming strategies have equal shares.

Performance over time for different cost types

td = summarise(group_by(rd,strat,cost.pair,t), u=mean(u), num.obs = length(t))
t.seq = 1:min(max(td$t),end.t)
tsd = do(group_by(td, strat, cost.pair),
         get.smoothed.vals(.,xout=t.seq, xvar="t",yvar="u", wvar="num.obs", spar=0.2))

# Order strategies according to their rank
rank.strats = rank.dt$strat
tsd$strat = factor(tsd$strat, rank.strats, ordered=TRUE)

mean.u = mean(rd$u)

qplot(data=tsd, x=t, y=u, color=strat, group=strat, size=I(1), geom="line") + facet_grid(cost.pair~strat) + geom_hline(yintercept=I(mean.u), size=0.5, col="black",alpha=0.5)
cat("\n")

The plot shows the average payoffs of the column strategy against the row strategy as a function of the period t.



skranz/StratTourn documentation built on May 30, 2019, 2:02 a.m.