Package 'TUvalues'

Title: Tools for Calculating Allocations in Game Theory using Exact and Approximated Methods
Description: The main objective of cooperative games is to allocate a good among the agents involved. This package includes the most well-known allocation rules, i.e., the Shapley value, the Banzhaf value, the egalitarian rule, and the equal surplus division value. In addition, it considers the point of view of a priori unions (situations in which agents can form coalitions). For this purpose, the package includes the Owen value, the Banzhaf-Owen value, and the corresponding extensions of the egalitarian rules. All these values can be calculated exactly or estimated by sampling.
Authors: Maria D. Guillen [cre, aut] , Juan Carlos Gonçalves [aut]
Maintainer: Maria D. Guillen <[email protected]>
License: AGPL (>= 3)
Version: 0.1.0
Built: 2025-01-09 06:57:44 UTC
Source: CRAN

Help Index


Banzhaf value

Description

Calculate the Banzhaf value

Usage

banzhaf(
  characteristic_func,
  method = "exact",
  n_rep = 10000,
  n_players = 0,
  replace = FALSE
)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players.

method

Method used to calculate the Banzhaf value. Valid methods are: exact for the exact calculation or appro for approximated polynomial calculation based on sampling.

n_rep

Only used if method is appro. The number of iterations to perform in the approximated calculation

n_players

Only used if characteristic_func is a function. The number of players in the game.

replace

should sampling be with replacement?

Value

The Banzhaf value for each player

Examples

n <- 10
v <- function(coalition) {
if (length(coalition) > n/2) {
   return(1)
 } else {
   return(0)
 }
}
banzhaf(v, method = "exact", n_players = n)
banzhaf(v, method = "appro", n_rep = 4000, n_players = n, replace = TRUE)

v<-c(0,0,0,1,2,1,3)
banzhaf(v, method = "exact")
banzhaf(v, method = "appro", n_rep = 4000, replace = TRUE)

Banzhaf Index (approximated)

Description

Calculate the approximated Banzhaf Index based on sampling

Usage

banzhaf_appro(characteristic_func, n_players, n_rep, replace = TRUE)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players

n_players

Only used if value_func is a function. The number of players in the game

n_rep

The number of iterations to perform in the approximated calculation

replace

should sampling be with replacement?

Value

The Banzhaf Index for each player


Banzhaf Index (approximation)

Description

Calculate the approximated Banzhaf Index based on sampling

Usage

banzhaf_appro_func(value_func, n_rep, n_players, replace = TRUE)

Arguments

value_func

The valued function defined on the subsets of the number of players

n_rep

The number of iterations to perform in the approximated calculation

n_players

Only used if value_func is a function. The number of players in the game.

replace

should sampling be with replacement?

Value

The Banzhaf Index for each player


Banzhaf Index (approximated)

Description

Calculate the approximated Banzhaf Index based on sampling

Usage

banzhaf_appro_vector(value_func, n_rep)

Arguments

value_func

The valued function defined on the subsets of the number of players

n_rep

The number of iterations to perform in the approximated calculation

Value

The Banzhaf Index for each player


Banzhaf Index (exact)

Description

Calculate the approximated Banzhaf Index

Usage

banzhaf_exact(characteristic_func, n_players)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players

n_players

The number of players in the game.

Value

The Banzhaf Index for each player


Banzhaf-Owen value

Description

Calculate the Banzhaf-Owen value

Usage

banzhaf_owen(
  characteristic_func,
  union,
  method = "exact",
  n_rep = 10000,
  n_players = 0,
  replace = TRUE
)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players

union

List of vectors indicating the a priori unions between the players

method

Method used to calculate the Owen value. Valid methods are: exact for the exact calculation or appro for approximated polynomial calculation based on sampling.

n_rep

Only used if method is appro. The number of iterations to perform in the approximated calculation

n_players

Only used if characteristic_func is a function. The number of players in the game.

replace

should sampling be with replacement?

Value

The Banzhaf-Owen value for each player

Examples

characteristic_func <- c(0,0,0,0,30,30,40,40,50,50,60,70,80,90,100)
union <- list(c(1,3),c(2),c(4))
banzhaf_owen(characteristic_func, union)
banzhaf_owen(characteristic_func, union, method = "appro", n_rep = 4000)

Banzhaf-Owen Value

Description

Calculate the approximated Banzhaf-Owen value

Usage

banzhaf_owen_appro(characteristic_func, union, n_players, n_rep, replace)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players

union

List of vectors indicating the a priori unions between the players

n_players

The number of players

n_rep

Only used if method is appro. The number of iterations to perform in the approximated calculation.

replace

should sampling be with replacement?

Value

The Banzhaf-Owen Index for each player


Banzhaf-Owen Value

Description

Calculate the approximated Banzhaf-Owen value

Usage

banzhaf_owen_exact(characteristic_func, union, n_players)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players

union

List of vectors indicating the a priori unions between the players

n_players

The number of players in the game.

Value

The Banzhaf Index for each player


coalitions

Description

Create all the possible coalitions given the number of players

Usage

coalitions(n_players)

Arguments

n_players

Number of players

Value

A list containing a data.frame of the binary representation of the coalitions and a vector of the classical representation (as sets) of the coalitions


Egalitarian value

Description

Calculate the egalitarian value

Usage

egalitarian(characteristic_func, n_players = 0)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players

n_players

Only used if characteristic_func is a function. The number of players in the game.

Value

The egalitarian value for each player

Examples

n <- 10
v <- function(coalition) {
  if (length(coalition) > n/2) {
    return(1)
  } else {
    return(0)
  }
}
egalitarian(v,n)

Equal Surplus Division value

Description

Calculate the equal surplus division value

Usage

equal_surplus_division(characteristic_func, n_players = 0)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players

n_players

Only used if characteristic_func is a function. The number of players in the game.

Value

The equal surplus division value for each player

Examples

n <- 10
v <- function(coalition) {
  if (length(coalition) > n/2) {
    return(1)
  } else {
    return(0)
  }
}
equal_surplus_division(v,n)

Owen value

Description

Calculate the Owen value

Usage

owen(
  characteristic_func,
  union,
  method = "exact",
  n_rep = 10000,
  n_players = 0
)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players.

union

List of vectors indicating the a priori unions between the players.

method

Method used to calculate the Owen value. Valid methods are: exact for the exact calculation or appro for approximated polynomial calculation based on sampling.

n_rep

Only used if method is appro. The number of iterations to perform in the approximated calculation.

n_players

The number of players in the game.

Value

The Owen value for each player.

Examples

n <- 10
v <- function(coalition) {
  if (length(coalition) > n/2) {
    return(1)
  } else {
    return(0)
  }
}
u <- lapply(1:(n/2), function(i) c(2*i - 1, 2*i))
owen(v, union = u, method = "appro", n_rep = 4000, n_players = n)

characteristic_func <- c(1,1,2,1,2,2,2)
union <- list(c(1,2),c(3))
owen(characteristic_func, union)
owen(characteristic_func, union, method = "appro", n_rep = 4000)

Owen value (approximation)

Description

Calculate the approximated Owen value based on sampling

Usage

owen_appro(characteristic_func, union, n_players, n_rep)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players

union

List of vectors indicating the a priori unions between the players

n_players

The number of players

n_rep

The number of iterations to perform in the approximated calculation

Value

The Owen value for each player


Owen value (exact)

Description

Calculate the exact Owen

Usage

owen_exact(characteristic_func, union, n_players = NULL)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players

union

List of vectors indicating the a priori unions between the players

n_players

The number of players

Value

The Owen value for each player


Predecessor

Description

Given a permutation 0 of players and a player i, calculate the set of predecessors of the player i in the order 0

Usage

predecessor(permutation, player, include_player = FALSE)

Arguments

permutation

A permutation of the players

player

Number of the player i

include_player

Whether the player i is included as predecessor of itself or not

Value

The set of predecessors of the player i in the order 0


Shapley value

Description

Calculate the Shapley value

Usage

shapley(characteristic_func, method = "exact", n_rep = 10000, n_players = 0)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players.

method

Method used to calculate the Shapley value. Valid methods are: exact for the exact calculation or appro for approximated polynomial calculation based on sampling.

n_rep

Only used if method is appro. The number of iterations to perform in the approximated calculation.

n_players

Only used if characteristic_func is a function. The number of players in the game.

Value

The Shapley value for each player.

Examples

n <- 3
v <- c(1,1,2,1,2,2,2)
shapley(v, method = "exact")
shapley(v, method = "appro", n_rep = 4000)

Shapley value (approximation)

Description

Calculate the approximated Shapley value based on sampling

Usage

shapley_appro(characteristic_func, n_players, n_rep)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players

n_players

The number of players

n_rep

The number of iterations to perform in the approximated calculation

Value

The Shapley value for each player


Shapley value (exact)

Description

Calculate the exact Shapley value

Usage

shapley_exact(characteristic_func, n_players)

Arguments

characteristic_func

The valued function defined on the subsets of the number of players

n_players

The number of players

Value

The Shapley value for each player