Learn R Programming

TUvalues (version 1.1.1)

banzhaf: Banzhaf value

Description

Calculate the Banzhaf value

Usage

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

Value

The Banzhaf value for each player

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.

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

replace

Should sampling be with replacement?

echo

Only used if method is appro. Show progress of the approximated calculation.

Examples

Run this code
n <- 8
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 = 2000, n_players = n, replace = TRUE)

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

Run the code above in your browser using DataLab