Learn R Programming

TUvalues (version 1.1.1)

shapley: Shapley value

Description

Calculate the Shapley value

Usage

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

Value

The Shapley 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 alculate the Shapley value. Valid methods are: exact for the exact calculation or appro for approximated polynomial calculation based on sampling proposed by Castro et al. (2009).

n_rep

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

echo

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

References

Castro, J., Gómez, D., & Tejada, J. (2009). Polynomial calculation of the Shapley value based on sampling. Computers & operations research, 36(5), 1726-1730.

Examples

Run this code
n <- 10
v <- function(coalition) {
if (length(coalition) > n/2) {
   return(1)
 } else {
   return(0)
 }
}
shapley(v, method = "appro", n_rep = 4000, n_players = n)

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

Run the code above in your browser using DataLab