rgamer: Learn Game Theory Using R (2024)

Overview

The goal of rgamer is to help students learn Game Theory using R. The functions prepared by the package not only solve basic games such as two-person normal-form games but also provides the users with visual displays that highlight some aspects of the games — payoff matrix, best response correspondence, etc. In addition, it suggests some numerical solutions for games of which it is difficult — or even seems impossible — to derive a closed-form analytical solution.

Installation

You can install the development version from GitHub with:

# install.packages("remotes")remotes::install_github("yukiyanai/rgamer")

or

# install.packages("devtools")devtools::install_github("yukiyanai/rgamer")

Examples

library(rgamer)

Example 1

An example of a normal-form game (prisoner’s dilemma).

  • Player: Kamijo, Yanai
  • Strategy: (Stays silent, Betrays), (Stays silent, Betrays)
  • Payoff: (-1, 0, -3, -2), (-1, -3, 0, -2)

First, you define the game by normal_form():

game1 <- normal_form( players = c("Kamijo", "Yanai"), s1 = c("Stays silent", "Betrays"),  s2 = c("Stays silent", "Betrays"),  payoffs1 = c(-1, 0, -3, -2),  payoffs2 = c(-1, -3, 0, -2))

You can specify payoffs for each cell of the game matrix as follows.

game1b <- normal_form( players = c("Kamijo", "Yanai"), s1 = c("Stays silent", "Betrays"),  s2 = c("Stays silent", "Betrays"),  cells = list(c(-1, -1), c(-3, 0), c( 0, -3), c(-2, -2)), byrow = TRUE)

Then, you can pass it to solve_nfg() function to get the table of the game and the Nash equilibrium.

s_game1 <- solve_nfg(game1, show_table = FALSE)#> Pure-strategy NE: [Betrays, Betrays]
s_game1$table

Yanai

strategyStays silentBetrays
KamijoStays silent-1, -1-3, 0^
Betrays0^, -3-2^, -2^

Example 2

An example of a coordination game.

  • Player: Kamijo, Yanai
  • Strategy: (Stag, Hare), (Stag, Hare)
  • Payoff: (10, 8, 0, 7), (10, 0, 8, 7)

Define the game by normal_form():

game2 <- normal_form( players = c("Kamijo", "Yanai"), s1 = c("Stag", "Hare"),  s2 = c("Stag", "Hare"),  payoffs1 = c(10, 8, 0, 7),  payoffs2 = c(10, 0, 8, 7))

Then, you can pass it to solve_nfg() function to get NEs. Set mixed = TRUE to find mixed-strategy NEs well.

s_game2 <- solve_nfg(game2, mixed = TRUE, show_table = FALSE)#> Pure-strategy NE: [Stag, Stag], [Hare, Hare]#> Mixed-strategy NE: [(7/9, 2/9), (7/9, 2/9)]#> The obtained mixed-strategy NE might be only a part of the solutions.#> Please examine br_plot (best response plot) carefully.

For a 2-by-2 game, you can plot the best response correspondences as well.

s_game2$br_plot

rgamer: Learn Game Theory Using R (1)

Example 3

An example of a normal-form game:

  • Player:
  • Strategy:
  • Payoff:

You can define a game by specifying payoff functions as character vectors using normal_form():

game3 <- normal_form( players = c("A", "B"), payoffs1 = "-x^2 + (28 - y) * x", payoffs2 = "-y^2 + (28 - x) * y", par1_lim = c(0, 30), par2_lim = c(0, 30), pars = c("x", "y"))

Then, you can pass it to solve_nfg(), which displays the best response correspondences by default.

s_game3 <- solve_nfg(game3)#> approximated NE: (9.3, 9.3)#> The obtained NE might be only a part of the solutions.#> Please examine br_plot (best response plot) carefully.

rgamer: Learn Game Theory Using R (2)

Example 4

An example of a normal-form game:

  • Player:
  • Strategy:
  • Payoff:

You can define a normal-form game by specifying payoffs by R functions.

f_x <- function(x, y, a, b) { -x^a + (b - y) * x}f_y <- function(x, y, s, t) { -y^s + (t - x) * y}game4 <- normal_form( players = c("A", "B"), payoffs1 = f_x, payoffs2 = f_y, par1_lim = c(0, 30), par2_lim = c(0, 30), pars = c("x", "y"))

Then, you can approximate a solution numerically by solve_nfg(). Note that you need to set the parameter values of the function that should be treated as constants by arguments cons1 and cons2, each of which accepts a named list. In addition, you can suppress the plot of best responses by plot = FALSE.

s_game4 <- solve_nfg( game = game4, cons1 = list(a = 2, b = 28), cons2 = list(s = 2, t = 28), plot = FALSE)#> approximated NE: (9.3, 9.3)#> The obtained NE might be only a part of the solutions.#> Please examine br_plot (best response plot) carefully.

You can increase the precision of approximation by precision, which takes a natural number (default is precision = 1).

s_game4b <- solve_nfg( game = game4, cons1 = list(a = 2, b = 28), cons2 = list(s = 2, t = 28), precision = 3)#> approximated NE: (9.333, 9.333)#> The obtained NE might be only a part of the solutions.#> Please examine br_plot (best response plot) carefully.

rgamer: Learn Game Theory Using R (3)

You can extract the best response plot with NE marked as follows.

s_game4b$br_plot_NE

rgamer: Learn Game Theory Using R (4)

Example 5

You can define payoffs by R functions and evaluate them at some discretized values by setting discretize = TRUE. The following is a Bertrand competition example:

func_price1 <- function(p, q) { if (p < q) { profit <- p } else if (p == q) { profit <- 0.5 * p } else { profit <- 0 } profit}func_price2 <- function(p, q){ if (p > q) { profit <- q } else if (p == q) { profit <- 0.5 * q } else { profit <- 0 } profit}game5 <- normal_form( payoffs1 = func_price1, payoffs2 = func_price2, pars = c("p", "q"), par1_lim = c(0, 10), par2_lim = c(0, 10), discretize = TRUE)

Then, you can examine the specified part of the game.

s_game5 <- solve_nfg(game5, mark_br = FALSE)

Player 2

strategy0246810
Player 100, 00, 00, 00, 00, 00, 0
20, 01, 12, 02, 02, 02, 0
40, 00, 22, 24, 04, 04, 0
60, 00, 20, 43, 36, 06, 0
80, 00, 20, 40, 64, 48, 0
100, 00, 20, 40, 60, 85, 5

Example 6

You can draw a tree of an extensive form game.

game6 <- extensive_form( players = list("Yanai",  rep("Kamijo", 2), rep(NA, 4)), actions = list(c("stat", "game"), c("stat", "game"), c("stat", "game")), payoffs = list(Yanai = c(2, 0, 0, 1), Kamijo = c(1, 0, 0, 2)), direction = "right")

rgamer: Learn Game Theory Using R (5)

And you can find the solution of the game by solve_efg().

s_game6 <- solve_efg(game6)#> backward induction: [(stat), (stat, game)]

Then, you can see the path played under a solution by show_path().

show_path(s_game6)

rgamer: Learn Game Theory Using R (6)

rgamer: Learn Game Theory Using R (2024)

FAQs

What is the best response method in game theory? ›

A best response is a best strategy given what you think the other player will do. A dominant strategy is one that is a best response to all possible strategies. When players are mutually best responding, we have a Nash equilibrium.

Is game theory a lot of math? ›

This is because game theory is an applied mathematical discipline, and therefore its determining side is the real-life phenomena it tries to model. The secondary, nonetheless essential side is of course mathematics.

How to get better at game theory? ›

One of the best ways to improve your game theory skills is to solve problems that test your understanding and application of the concepts and methods. You can find problems from textbooks, online platforms, or competitions that challenge you to analyze and solve different scenarios involving strategic interactions.

How do you study game theory? ›

You can find many online tutorials, videos, and books that explain these concepts in an intuitive and accessible way, such as the ones by Khan Academy, Coursera, or MIT OpenCourseWare. Taking a Game Theory course changed the way I make decisions and predict actions of others.

What is the optimal strategy for a game theory? ›

An optimal strategy is one that provides the best payoff for a player in a game. Optimal Strategy = A strategy that maximizes a player's expected payoff. Games are of two types: cooperative and noncooperative games.

What is a strongly dominant strategy in game theory? ›

What is Dominant Strategy? The dominant strategy in game theory refers to a situation where one player has superior tactics regardless of how their opponent may play. Holding all factors constant, that player enjoys an upper hand in the game over the opposition.

What level of math is needed for game theory? ›

Students must know basics of linear algebra (matrix multiplication, geometric interpretation of vectors), analysis (continuity, closed sets), and probability theory (expected value, conditional probability, independence of random events).

What is the hardest theory in math? ›

1. Riemann Hypothesis. The Riemann Hypothesis, proposed by Bernhard Riemann in 1859, is a central problem in number theory, and discusses the distribution of prime numbers. The hypothesis focuses on the zeros of the Riemann zeta function.

What is a real life example of game theory? ›

Another excellent example of game theory in the real world is when employees negotiate a strike or other union action. The prisoner's dilemma may also be used to demonstrate the game theory. It is a decision paradox where two players motivated by self-interest fail to achieve optimal outcomes.

What should I learn before game theory? ›

Before we understand Game Theory, we must understand what is a Game in terms of mathematics. A Game is an ecosystem/situation/environment with rules & regulations, involving multiple stakeholders (players) where each player takes a certain decision/follow some strategy to reach an ultimate goal.

What are the three basics of game theory? ›

The three basic elements of any game are: A set of participants, or "players." The moves, or "actions," that each player may make. The scores, or "payoffs," that each player earns at the end of the game.

What is the game theory where everyone wins? ›

In the Nash equilibrium, each player's strategy is optimal when considering the decisions of other players. Every player wins because everyone gets the outcome that they desire. The prisoner's dilemma is a common game theory example and one that adequately showcases the effect of the Nash equilibrium.

What is the nutshell game theory? ›

In short, game theory is the mathematical study of strategy and decision making where multiple players make choices that affect each other's outcomes. It involves the analysis of various scenarios where the payoff of a player's decision depends not only on their own actions but also on the actions of other players.

Who is the father of game theory? ›

John von Neumann, whom people called Johnny, was a brilliant mathematician and physicist who also made three fundamental contributions to economics. The first is a 1928 paper written in German that established von Neumann as the father of game theory.

Who's taking over game theory? ›

The remaining channels will be passed down to the editors and creative heads that the Theorist channels previously had. Lee Collins will be taking over Film Theory, Amy Roberts will be hosting Style Theory, Santiago Massa will be hosting culinary adventures of Food Theory, and Tom Robison will be the writer and host of ...

What is the best reply function? ›

A best-reply function is just that function which describes the best-reply for the player as a function of the actions taken by the other players. Nash equilibria are then combinations of strategies which are mutually best replies to one another.

What is the best response dynamics? ›

Best response dynamics is a dynamic process in which the frequency of a strategy increases only if it is a best response to the present strategy distribution. Gilboa and Matsui (Econometrica 59 (1991), 859–867) proposed a stability concept directly derived from this dynamic process.

What is the best outcome in game theory? ›

Nash equilibrium is a concept in game theory where the game reaches an optimal outcome. This is a state that gives individual players no incentive to deviate from their initial strategy.

What is a best response curve? ›

... the best response curve x i (y i ) in region B has zero slope at x i = y i , is strictly increasing for x i > y i and strictly decreasing for x i < y i . Substituting x i = y i in equation (4) we get, Figure 4 describes a typical best response curve as a function of effective competitor frequency.

Top Articles
All You Need to Know About the Whole30 Diet
Whole30 Diet Made Simple — Food List and Rules for Beginners
Funny Roblox Id Codes 2023
Golden Abyss - Chapter 5 - Lunar_Angel
Www.paystubportal.com/7-11 Login
Joi Databas
DPhil Research - List of thesis titles
Shs Games 1V1 Lol
Evil Dead Rise Showtimes Near Massena Movieplex
Steamy Afternoon With Handsome Fernando
Which aspects are important in sales |#1 Prospection
Detroit Lions 50 50
18443168434
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
Grace Caroline Deepfake
978-0137606801
Nwi Arrests Lake County
Justified Official Series Trailer
London Ups Store
Committees Of Correspondence | Encyclopedia.com
Pizza Hut In Dinuba
Jinx Chapter 24: Release Date, Spoilers & Where To Read - OtakuKart
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
Free Online Games on CrazyGames | Play Now!
Sizewise Stat Login
VERHUURD: Barentszstraat 12 in 'S-Gravenhage 2518 XG: Woonhuis.
Jet Ski Rental Conneaut Lake Pa
Unforeseen Drama: The Tower of Terror’s Mysterious Closure at Walt Disney World
Ups Print Store Near Me
C&T Wok Menu - Morrisville, NC Restaurant
How Taraswrld Leaks Exposed the Dark Side of TikTok Fame
University Of Michigan Paging System
Dashboard Unt
Access a Shared Resource | Computing for Arts + Sciences
Black Lion Backpack And Glider Voucher
Gopher Carts Pensacola Beach
Duke University Transcript Request
Lincoln Financial Field, section 110, row 4, home of Philadelphia Eagles, Temple Owls, page 1
Jambus - Definition, Beispiele, Merkmale, Wirkung
Netherforged Lavaproof Boots
Ark Unlock All Skins Command
Craigslist Red Wing Mn
D3 Boards
Jail View Sumter
Nancy Pazelt Obituary
Birmingham City Schools Clever Login
Thotsbook Com
Funkin' on the Heights
Vci Classified Paducah
Www Pig11 Net
Ty Glass Sentenced
Latest Posts
Article information

Author: Pres. Carey Rath

Last Updated:

Views: 5641

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Pres. Carey Rath

Birthday: 1997-03-06

Address: 14955 Ledner Trail, East Rodrickfort, NE 85127-8369

Phone: +18682428114917

Job: National Technology Representative

Hobby: Sand art, Drama, Web surfing, Cycling, Brazilian jiu-jitsu, Leather crafting, Creative writing

Introduction: My name is Pres. Carey Rath, I am a faithful, funny, vast, joyous, lively, brave, glamorous person who loves writing and wants to share my knowledge and understanding with you.