Title: | Revealed Preferences and Microeconomic Rationality |
---|---|
Description: | Computation of (direct and indirect) revealed preferences, fast non-parametric tests of rationality axioms (WARP, SARP, GARP), simulation of axiom-consistent data, and detection of axiom-consistent subpopulations. Rationality tests follow Varian (1982) <doi:10.2307/1912771>, axiom-consistent subpopulations follow Crawford and Pendakur (2012) <doi:10.1111/j.1468-0297.2012.02545.x>. |
Authors: | Julien Boelaert <[email protected]> |
Maintainer: | Julien Boelaert <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.4.1 |
Built: | 2024-11-09 06:25:52 UTC |
Source: | CRAN |
Computation of (direct and indirect) revealed preferences, fast non-parametric tests of rationality axioms (WARP, SARP, GARP), simulation of axiom-consistent data, and detection of axiom-consistent subpopulations. Rationality tests follow Varian (1982) <doi:10.2307/1912771>, axiom-consistent subpopulations follow Crawford and Pendakur (2012) <doi:10.1111/j.1468-0297.2012.02545.x>.
This package is meant for the analysis of (quantity, price) data, eg. of bundles of goods and corresponding prices. It features fast algorithms that make the analysis of large datasets feasible.
Functions directPrefs
and indirectPrefs
compute revealed preferences.
Functions checkWarp
, checkSarp
, checkGarp
perform fast non-parametric tests of rationality using the corresponding rationality axioms.
Functions simWarp
, simSarp
, simGarp
and simPrefs
generate simulated data consistent with a rationality axiom or with a given preference matrix.
Functions cpLower
and cpUpper
generate Crawford-Pendakur type bounds on the number of subpopulations and provide the corresponding clusterings.
Julien Boelaert <[email protected]>
Maintainer: Julien Boelaert <[email protected]>
Varian, H. R. (1982) The Nonparametric Approach to Demand Analysis, Econometrica, 50(4):945-973.
Varian, H. R. (1984) Microeconomic Analysis. New York/London: Norton, 2nd edition, pp 141-143.
Crawford, I. and Pendakur, K. (2013). How many types are there? The Economic Journal, 123(567):77-95.
See directPrefs for computation of preferences, checkGarp for rationality tests, simGarp
for data generation, and cpUpper for clustering of data into non-violating subsets.
# Compute preferences and check rationality on a GARP-violating dataset: data(noGarp) indirectPrefs(noGarp$x, noGarp$p) checkGarp(noGarp$x, noGarp$p) # Cluster dataset into GARP-consistent subpopulations: cpUpper(noGarp$x, noGarp$p)
# Compute preferences and check rationality on a GARP-violating dataset: data(noGarp) indirectPrefs(noGarp$x, noGarp$p) checkGarp(noGarp$x, noGarp$p) # Cluster dataset into GARP-consistent subpopulations: cpUpper(noGarp$x, noGarp$p)
Functions for non-parametric tests of compliance with rationality axioms.
Functions checkWarp
, checkSarp
and checkGarp
perform exact tests of the Weak Axiom of Revealed Preferences (WARP), the Strong Axiom of Revealed Preferences (SARP) and the Generalized Axiom of Revealed Preferences (GARP) respectively, to check whether the given data are consistent with utility maximization.
checkWarp(x, p, afriat.par= 1) checkSarp(x, p, afriat.par= 1, method= c("deep", "floyd")) checkGarp(x, p, afriat.par= 1, method= c("floyd")) ## S3 method for class 'axiomTest' print(x, ...) ## S3 method for class 'axiomTest' summary(object, ...)
checkWarp(x, p, afriat.par= 1) checkSarp(x, p, afriat.par= 1, method= c("deep", "floyd")) checkGarp(x, p, afriat.par= 1, method= c("floyd")) ## S3 method for class 'axiomTest' print(x, ...) ## S3 method for class 'axiomTest' summary(object, ...)
x |
data frame or matrix containing the observed quantities, where each row corresponds to an observation and the columns are types of goods, or an object of class |
p |
data frame or matrix (of same dimensions as x) containing the corresponding prices, |
afriat.par |
the Afriat parameter, real number in [0,1], which allows a certain level of error in the optimization of choices; default is 1, ie. no optimization error allowed, |
method |
character string: |
object |
an object of class |
... |
additional arguments passed to the |
Rationality axioms can be summarized as follows:
WARP: if X directly prefered to Y and X is not equal to Y, then Y cannot be directly prefered to X (WARP is a necessary condition for the existence of a single-valued utility-maximizing demand function consistent with the data).
SARP: if X (in)directly prefered to Y and X is not equal to Y, then Y cannot be (in)directly prefered to X (SARP is a necessary and sufficient condition for the existence of a single-valued utility-maximizing demand function consistent with the data).
GARP: if X (in)directly prefered to Y, then Y cannot be strictly directly prefered to X (GARP is a necessary and sufficient condition for the existence of a (possibly multiple-valued) utility-maximizing demand function consistent with the data).
If WARP or GARP are violated, then SARP is also violated.
Testing of WARP is straightforward by pairwise comparison of revealed preferences. GARP is tested using the Floyd-Warshall algorithm to find the transitive closure of the direct preference relationship. SARP can be tested either using the Floyd-Warshall algorithm, or using a depth-first search that systematically explores the preference relationship in search of a violating cycle.
Functions checkWarp
, checkSarp
and checkGarp
return an object of class axiomTest
which may contain the following elements:
violation |
logical value, |
path |
last path taken during depth-first search, |
path.strict |
(for |
violators |
vector of indices of axiom-violating observations (only the first violators that were found are reported, this is not a complete list), |
strict |
vector of logical values indicating whether the preferences between reported violators (or path) are strict or not, |
direct.violation |
logical value, |
type |
the violated or non-violated rationality axiom, |
method |
method used for the non-parametric test, |
afriat.par |
Afriat parameter used in the algorithm. |
Julien Boelaert [email protected]
Varian, H. R. (1982) The Nonparametric Approach to Demand Analysis, Econometrica, 50(4):945-973.
Varian, H. R. (1984) Microeconomic Analysis. New York/London: Norton, 2nd edition, pp 141-143.
# Check axioms for GARP-violating data: data(noGarp) summary(checkGarp(noGarp$x, noGarp$p)) # Check axioms for SARP-consistent data: data(okSarp) summary(checkSarp(okSarp$x, okSarp$p))
# Check axioms for GARP-violating data: data(noGarp) summary(checkGarp(noGarp$x, noGarp$p)) # Check axioms for SARP-consistent data: data(okSarp) summary(checkSarp(okSarp$x, okSarp$p))
The cpLower
function computes a Crawford-Pendakur type lower bound on the number of GARP-consistent subpopulations by creating a set of pairwise GARP-violating observations.
cpLower(x, p, times= 1, afriat.par= 1) ## S3 method for class 'lowerBound' print(x, ...) ## S3 method for class 'lowerBound' summary(object, ...)
cpLower(x, p, times= 1, afriat.par= 1) ## S3 method for class 'lowerBound' print(x, ...) ## S3 method for class 'lowerBound' summary(object, ...)
x |
data frame or matrix containing the observed quantities, where each row corresponds to an observation and the columns are types of goods, or an object of class |
p |
data frame or matrix (of same dimensions as x) containing the corresponding prices, |
times |
number of times the algorithm is run (the final result is the best of |
afriat.par |
the Afriat parameter, a real number in [0,1], which allows a certain level of error in the optimization of choices ; default is 1, ie. no optimization error allowed, |
object |
object of class |
... |
additional arguments passed to the |
For each run of the algorithm, a random permutation of the observations is drawn, and one by one each observation is pairwise-tested against all previously found violators. If the current observation is found pairwise-inconsistent with all previously found violators it is added to the set of violators.
cpLower
returns an object of class lowerBound
which contains the following elements:
violators |
numeric vector containing the indices of observations that are pairwise GARP-inconsistent, |
n.clust |
lower bound on the number of types, |
hist.n.types |
numeric vector containing the history of numbers of types found during multiple runs of the algorithm. |
n.types |
lower bound on the number of types, |
afriat.par |
Afriat parameter used in the algorithm. |
Julien Boelaert [email protected]
Crawford, I. and Pendakur, K. (2013). How many types are there? The Economic Journal, 123(567):77-95.
See cpUpper for the upper bound on the number of types.
# Lower bound for GARP-violating data: data(noGarp) cp.low <- cpLower(noGarp$x, noGarp$p) cp.low cp.low$violators
# Lower bound for GARP-violating data: data(noGarp) cp.low <- cpLower(noGarp$x, noGarp$p) cp.low cp.low$violators
The cpUpper
function computes a Crawford-Pendakur type upper bound on the number of GARP-consistent subpopulations, and performs clustering of the data.
cpUpper(x, p, times= 1, afriat.par= 1, method= c("fastfloyd", "floyd")) ## S3 method for class 'upperBound' print(x, ...) ## S3 method for class 'upperBound' summary(object, ...)
cpUpper(x, p, times= 1, afriat.par= 1, method= c("fastfloyd", "floyd")) ## S3 method for class 'upperBound' print(x, ...) ## S3 method for class 'upperBound' summary(object, ...)
x |
data frame or matrix containing the observed quantities, where each row corresponds to an observation and the columns are types of goods, or an object of class |
p |
data frame or matrix (of same dimensions as x) containing the corresponding prices, |
times |
number of times the algorithm is run (the final result is the best of |
afriat.par |
the Afriat parameter, a real number in [0,1], which allows a certain level of error in the optimization of choices ; default is 1, ie. no optimization error allowed, |
method |
character string: |
object |
an object of class |
... |
additional arguments passed to the |
For each run of the algorithm, a random permutation of the observations is drawn, and one by one each observation is associated with the biggest cluster that can include it while preserving consistency with the GARP rationality axiom. If no cluster is compatible with a given observation a new cluster is created to accomodate it.
Three methods are available:
"fastfloyd"
(default) uses an iterative variant of the Floyd-Warshall algorithm, in which the check of consistency of the current observation with a given cluster is done in a single step of the Floyd-Warshall algorithm. Much faster than "floyd"
.
"floyd"
uses the algorithm described in Crawford and Pendakur (2013): at each step the complete Floyd-Warshall algorithm is run to check whether each cluster can accomodate the current observation.
cpUpper
returns an object of class upperBound
which contains the following elements:
clustering |
numeric vector with length equal to number of observations, containing the cluster number of each observation, |
cluster.pop |
numeric vector containg the numbers of observations allocated to each cluster, |
hist.n.types |
numeric vector containing the history of numbers of clusters found during multiple runs of the algorithm. |
n.types |
upper bound on the number of types, |
afriat.par |
Afriat parameter used in the algorithm. |
Warning: cpUpper
can be very slow for large datasets (eg. more than 1000 observations).
Julien Boelaert [email protected]
Crawford, I. and Pendakur, K. (2013). How many types are there? The Economic Journal, 123(567):77-95.
See cpLower for the lower bound on number of types.
# Cluster GARP-violating data: data(noGarp) cp.up <- cpUpper(noGarp$x, noGarp$p) cp.up$clustering
# Cluster GARP-violating data: data(noGarp) cp.up <- cpUpper(noGarp$x, noGarp$p) cp.up$clustering
The directPrefs
function computes direct revealed preferences, the indirectPrefs
function computes indirect revealed preferences.
directPrefs(x, p, afriat.par= 1) indirectPrefs(x, p, afriat.par= 1)
directPrefs(x, p, afriat.par= 1) indirectPrefs(x, p, afriat.par= 1)
x |
data frame or matrix containing the observed quantities, where each row corresponds to an observation and the columns are types of goods. |
p |
data frame or matrix (of same dimensions as x) containing the corresponding prices. |
afriat.par |
the Afriat parameter, real number in [0,1], which allows a certain level of error in the optimization of choices; default is 1, ie. no optimization error allowed. |
Direct preferences are directly computed from matrix multiplication of prices and quantities. Indirect preferences are computed using a variant of the Floyd-Warshall algorithm.
A matrix of direct or indirect revealed preferences:
prefs[i , j] = 0
|
if bundle |
prefs[i , j] = 1
|
if bundle |
prefs[i , j] = 2
|
if bundle |
Julien Boelaert [email protected]
Varian, H. R. (1984) Microeconomic Analysis. New York/London: Norton, 2nd edition, pp 141-143.
# Compute direct and indirect preferences of SARP-violating data: data(noSarp) directPrefs(noSarp$x, noSarp$p) indirectPrefs(noSarp$x, noSarp$p)
# Compute direct and indirect preferences of SARP-violating data: data(noSarp) directPrefs(noSarp$x, noSarp$p) indirectPrefs(noSarp$x, noSarp$p)
Toy examples to test for consistency with rationality axioms.
data(noGarp) data(noWarp) data(noSarp) data(okSarp) data(noAxiom)
data(noGarp) data(noWarp) data(noSarp) data(okSarp) data(noAxiom)
Each dataset is a list of two matrices, named x and p, that contain quantities and prices, respectively. Each row is an observation, each column is a type of good.
Data in noAxiom
violate WARP, GARP and SARP.
Data in noWarp
violate WARP and SARP, but not GARP.
Data in noGarp
violate GARP and SARP, but not WARP.
Data in noSarp
violate SARP, but not WARP or GARP.
Data in okSarp
are consistent with WARP, SARP and GARP.
Julien Boelaert [email protected]
data(noWarp) checkWarp(noWarp$x, noWarp$p)
data(noWarp) checkWarp(noWarp$x, noWarp$p)
Functions for generating random data (prices and quantities) consistent with the chosen rationality axiom.
simWarp(nobs, ngoods, afriat.par= 1, maxit= 10 * nobs, qmin= 0, qmax= 1, pmin= 0, pmax= 1) simSarp(nobs, ngoods, afriat.par= 1, maxit= 10 * nobs, qmin= 0, qmax= 1, pmin= 0, pmax= 1) simGarp(nobs, ngoods, afriat.par= 1, maxit= 10 * nobs, qmin= 0, qmax= 1, pmin= 0, pmax= 1)
simWarp(nobs, ngoods, afriat.par= 1, maxit= 10 * nobs, qmin= 0, qmax= 1, pmin= 0, pmax= 1) simSarp(nobs, ngoods, afriat.par= 1, maxit= 10 * nobs, qmin= 0, qmax= 1, pmin= 0, pmax= 1) simGarp(nobs, ngoods, afriat.par= 1, maxit= 10 * nobs, qmin= 0, qmax= 1, pmin= 0, pmax= 1)
nobs |
the desired number of observations (number of rows in the quantities and prices matrices), |
ngoods |
the number of goods in the dataset (number of columns in the quantities and prices matrices), |
afriat.par |
the Afriat parameter, a real number in [0,1], which allows a certain level of error in the optimization of choices; default is 1, ie. no optimization error allowed, |
maxit |
maximum number of iterations (default to 10 times |
qmin |
minimum quantities for each good, |
qmax |
maximum quantities for each good, |
pmin |
minimum prices for each good, |
pmax |
maximum prices for each good. |
The data are iteratively incremented: at each iteration a new random observation (prices and quantities) is generated, and is accepted only if it is consistent with the previously accepted data, in which case it is added to the data. The random observations (price-quantities couples) are independently generated from uniform distributions in the support defined by qmin
, qmax
, and pmin
, pmax
.
For GARP and SARP the depth-first search method is used to check for consistency (a recursive search using only the new candidate observation as starting point), for WARP the candidate observation is pairwise checked against all previously accepted data.
The algorithm stops if the desired number of observations nobs
is reached. If the desired number of observations nobs
is not reached in maxit
iterations, a warning is issued and the function returns the largest dataset attained.
x |
numeric matrix of generated quantities, |
p |
numeric matrix of generated prices, |
iter |
number of iterations before the algorithm stopped, |
nobs |
number of generated observations. |
Julien Boelaert [email protected]
Varian, H. R. (1982) The Nonparametric Approach to Demand Analysis, Econometrica, 50(4):945-973.
Varian, H. R. (1984) Microeconomic Analysis. New York/London: Norton, 2nd edition, pp 141-143.
See checkGarp for rationality tests.
# Generate 100 WARP-consistent observations of 5 goods simdata <- simWarp(100, 5) summary(checkWarp(simdata$x, simdata$p)) summary(checkGarp(simdata$x, simdata$p))
# Generate 100 WARP-consistent observations of 5 goods simdata <- simWarp(100, 5) summary(checkWarp(simdata$x, simdata$p)) summary(checkGarp(simdata$x, simdata$p))
Function for generating random data (prices and quantities) consistent with a given direct preferences matrix.
simPrefs(pref.mat, ngoods, afriat.par= 1, qmin= 0, qmax= 1, pmin= 0, pmax= 1, maxit= 100, verbose= FALSE)
simPrefs(pref.mat, ngoods, afriat.par= 1, qmin= 0, qmax= 1, pmin= 0, pmax= 1, maxit= 100, verbose= FALSE)
pref.mat |
the desired matrix of direct preferences (must be a square matrix, see details), |
ngoods |
the number of goods in the dataset (number of columns in the quantities and prices matrices), |
afriat.par |
the Afriat parameter, a real number in [0,1], which allows a certain level of error in the optimization of choices; default is 1, ie. no optimization error allowed, |
qmin |
minimum quantities for each good, |
qmax |
maximum quantities for each good, |
pmin |
minimum prices for each good, |
pmax |
maximum prices for each good, |
maxit |
maximum number of iterations of the optimization algorithm (default to 100), |
verbose |
logical value: if |
The input pref.mat
must be a square matrix, with number of rows equal to the number of desired observations. All entries must be either 0, 1, or 2. The interpretation of the matrix is the same as in function directPrefs
:
pref.mat[i, j] = 0
if bundle i
is not revealed prefered to bundle j
pref.mat[i, j] = 1
if bundle i
is revealed prefered to bundle j
pref.mat[i, j] = 2
if bundle i
is strictly revealed prefered to bundle j
.
All diagonal entries of pref.mat
must be 1 (each bundle is revealed prefered to itself), except when afriat.par
is strictly less than 1.
The simulated data (quantities and prices) are obtained by particle swarm optimization (of package pso
). Fitness must reach 0 for the data to be consistent with the preference matrix. If optimization fails, a warning is issued.
x |
numeric matrix of generated quantities, or |
p |
numeric matrix of generated prices, or |
Julien Boelaert [email protected]
Varian, H. R. (1982) The Nonparametric Approach to Demand Analysis, Econometrica, 50(4):945-973.
Varian, H. R. (1984) Microeconomic Analysis. New York/London: Norton, 2nd edition, pp 141-143.
See directPrefs for computation of preferences.
# Generate 3 observations of 5 goods, according to a given preference matrix pref.mat <- matrix(c(1,0,0,2,1,0,2,2,1), 3) simdata <- simPrefs(pref.mat = pref.mat, ngoods = 5)
# Generate 3 observations of 5 goods, according to a given preference matrix pref.mat <- matrix(c(1,0,0,2,1,0,2,2,1), 3) simdata <- simPrefs(pref.mat = pref.mat, ngoods = 5)