################################################### ### Preliminaries ################################################### options(prompt = "R> ", continue = "+ ", width = 70, useFancyQuotes = FALSE, digits = 5) ################################################### ### Section: Specification and estimation} ################################################### library("games") data("leblang2003", package = "games") names(leblang2003) table(leblang2003$outcome) ################################################### ### Subsection: Modeling player utilities ################################################### f1 <- list(u11 = y ~ x1, u13 = ~ 0, u14 = ~ x1 + x2, u24 = ~ x2) games:::checkFormulas(f1) ################################################### ### Subsection: Model fitting ################################################### leblang2003$attack <- as.numeric(leblang2003$outcome != "no attack") leblang2003$defend <- as.numeric(leblang2003$outcome == "defense") flb <- outcome ~ capcont + lreserves + overval + creditgrow + USinterest + service + contagion + prioratt - 1 | 1 | 1 | unifgov + lexports + preelec + postelec + rightgov + realinterest + capcont + lreserves flb1 <- as.Formula(flb) flb2 <- update(flb1, attack + defend ~ .) leb1 <- egame12(flb1, data = leblang2003, link = "probit", type = "private") leb2 <- egame12(flb2, data = leblang2003, link = "probit", type = "private") all.equal(coef(leb1), coef(leb2), check.attributes = FALSE) cbind(leb1$equations, leb2$equations) set.seed(42) # for reproducibility leb1 <- update(leb1, boot = 100) summary(leb1) ################################################### ### Subsubsection: Extensive-form models ################################################### leb3 <- egame12(outcome ~ lreserves + overval - 1 | 1 | 1 | preelec + realinterest, sdformula = ~ prioratt - 1, data = leblang2003, link = "probit", type = "private") summary(leb3) lebfixed <- egame12(outcome ~ ., data = leblang2003, fixedUtils = c(1, -1, 0, 1), link = "probit", type = "private") summary(lebfixed) ################################################### ### Subsubsection: The ultimatum model ################################################### data("student_offers", package = "games") ult1 <- ultimatum(offer + accept ~ gender1 | gender2, maxOffer = 100, data = student_offers, s2 = 3) summary(ult1) ################################################### ### Subsection: Convergence ################################################### stu1 <- ultimatum(offer + accept ~ gender1 | gender2, data = student_offers, maxOffer = 100, s2 = 1) profstu1 <- profile(stu1, which = 1:4) plot(profstu1) stu2 <- update(stu1, profile = profstu1) logLik(stu1) logLik(stu2) ################################################### ### Subsection: Reporting results ################################################### leb1cap <- paste("Replication of \\citeauthor{Leblang2003}'s", "\\citeyearpar{Leblang2003} results.") latexTable(leb1, caption = leb1cap, label = "tab:leb1", floatplace = "p") ################################################### ### Section: Analyzing fitted models ################################################### ### Subsection: Predicted probabilities ################################################### predleb1 <- predProbs(leb1, x = "lreserves", contagion = max(contagion)) par(mfrow = c(2, 2)) plot(predleb1) ################################################### ### Subsection: Non-nested model comparisons ################################################### lebagent <- update(leb1, type = "agent", boot = 0) vuong(leb1, lebagent) leblang2003$noattack <- 1 - leblang2003$attack logit1 <- glm(noattack ~ lreserves + overval + creditgrow + contagion + prioratt + rightgov + realinterest, data = leblang2003, family = binomial) vuong(model1 = leb1, outcome1 = 1, model2 = logit1)