################################################################################ ## Function: pass <- garp (p, x, e) ## Inputs: p >> 0 is a (k by t) matrix of prices, x >= 0 is a (k by t) matrix ## of consumption bundles, 0 << e <= 1 is a (1 by t) vector of efficiency ## levels, k >= 2 is the number of goods, t >= 1 is the number of observations ## Outputs: pass = 0, 1 is a pass/fail indicator ## Description: returns a pass/fail indicator which represents the outcome of a ## GARP test at some efficiency vector ################################################################################ garp <- function (p, x, e) { # number of observations t <- length (e) # construct direct revealed preference relations e.p.x.i <- matrix (e * apply (p * x, 2, sum), t, t) p.x.j <- t(p) %*% x R0 <- 1 * (e.p.x.i >= p.x.j) P0 <- 1 * (e.p.x.i > p.x.j) # compute transitive closure R <- warshall (R0) # check for strict cycles cycles <- 1 * all (R + t(P0) < 2) # clean and return result result <- cycles remove (cycles, e, e.p.x.i, p, p.x.j, P0, R, R0, t, x) return (result) }