library(StratTourn)
library(xtable)
library(ggplot2)
library(reshape2)
library(googleVis)
library(dplyr)
library(tidyr)
library(lattice)
#setwd("D:/libraries/StratTourn")

#setwd("D:/libraries/StratTourn/studies")
setwd("E:/!Data/!Daten/Work/Promotion/L - Lectures/Kooperation Spieltheorie/WS 2015-16/StratTourn/studies")


tourn = load.tournament("Tourn_research.agreement_20151110_133937.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","s"))

# 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("strat","u","s"))
rd <- rd %>%
  group_by(strat, other.strat,i) %>%
  mutate(seen.s = lag(other.s))
sd <- summarise(group_by(rd,strat,other.strat, know.how, seen.s), share=mean(s))
sd <- mutate(sd,share.perc=share/know.how,share.abs=know.how-share)
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)

#Start Block "Slighty change value of sd from those strats where all values are the same"
#The levelplot function does not react well defined in those cases

strat.combs <- expand.grid(strats,strats, stringsAsFactors = FALSE)

no.variance <- sapply(1:nrow(strat.combs), FUN=function(x){
  to.test <- (sd[sd$strat==strat.combs[x,1]&sd$other.strat==strat.combs[x,2],]$seen.s)
  if(all(to.test[!is.na(to.test)][1]==to.test, na.rm=TRUE)){
    return(list(value=to.test[!is.na(to.test)][1],no.variance=TRUE))
  } else {
    return(list(value=NA,no.variance=FALSE))
  }
})

no.variance.combs <- strat.combs[which(unlist(no.variance["no.variance",])),]

if(nrow(no.variance.combs)>=1){
  for(i in 1:nrow(no.variance.combs)){
    new.val <- sd$seen.s[sd$strat==no.variance.combs[i,1]&sd$other.strat==no.variance.combs[i,2]]
    new.val <- new.val + runif(length(new.val),0,1e-5)
    sd$seen.s[sd$strat==no.variance.combs[i,1]&sd$other.strat==no.variance.combs[i,2]] <- new.val
  }
}

#End Block "Slighty change value of sd from those strats where all values are the same"

Shared knowledge by know how

levelplot(share.perc~know.how*seen.s|other.strat+strat, sd,col.regions=heat.colors(1000), cuts=1000-1, xlab="know.how", ylab="share of lower strat")
cat("\n")

The plot shows the shared knowledge in percent given the know how of the upper strategy (green) and the observed share of the lower strategy (red) of the last period.

Not shared know how

levelplot(share.abs~know.how*seen.s|other.strat+strat, sd,col.regions=heat.colors(1000), cuts=1000-1, xlab="know.how", ylab="share of lower strat")
cat("\n")

The plot shows the not shared knowledge given the know how of the upper strategy (green) and the observed share of the lower strategy (red) of the last period.



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