Efficiency in Production and Consumption

Mathematica is a convenient computational engine for calculating measures of choice efficiency.

by Hal R. Varian

The standard economic models of firms and consumers emphasize optimizing behavior. Firms are assumed to minimize costs or maximize profits, whereas consumers are assumed to maximize utility. However, no one is perfect—even homo economicus. When analyzing real choice data it is necessary to allow for departures from this model of strict optimization. 

In this article we consider some measures of choice efficiency. In general an efficiency measure should have the property that a value of 1 corresponds to100 percent efficiency: full optimization. A value of 0 wouldcorrespond to behaviorthat is totally independent ofefficient choice. Values between 0 and 1 should be interpretable as partial efficiency.

It tums out that there are relatively natural ways to construct such measures for economic choices and that Mathematica is a convenient computational engine for this task.

COST MINIMIZATION

Consider a firm that chooses factor inputs to minimize costs. Let w be a vector of factor prices, x a vector of factor choices, f(x) a production function, and y a target level of output. Then the hypothesized model is:

(min_x) w x

such that f(x) ≥ y.

Suppose that we have n observations of firm choices ((w^t), (x^t), (y^t))) for t = 1, . . ., n.The followingWeak Axiom of Cost Minimization (WACM) is necessary and sufficient for the data to be consistent with the cost minimization model:

  WACM: (w^t) (x^t) ≤ (w^t) (x^s) for all s for which (y^s) ≥ (y^t)

This condition is rather intuitive; it says that the observed choice must cost no more than any other choice that generates at least as much output. See (Varian 1993) for further discussion.

If we have some data that violate WACM, we may want to see "how close" a specific observation t comes to satisfying WACM. A natural thing to do is to compute the following efficiency index:

(e^t) = (min_(((y )^s) ≥  (y^t))) (((w^t) (x^s))/((w^t) (x^t)))

If (e^t) < 1, then there is some observation that produces at least as much output as the tth observation and costs less than the tth observation. If (e^t) = 1, no such observation exists.

It is easy to compute this efficiency index using Mathematica. Suppose that we have n observations on k factors which we arrange in an array of dimensionn x × k. The following function measures the efficiency of observation i relative to observation j.

efficOf[i_,  j_,  w_,  x_]  :=  
      (w[[j]] . x[[i]])/(w[[j]] . x[[j]])

This function returns the list of n × k efficiency measures.

\(eff[w_, \ x_, \ y_]\  := \ 
      Map[Union, 
																			
        Table[If[y[\([i]\)]\  <= \ y\ [\([j]\)], 

            																			
            Min[efficOf[j, \ i, \ w, \ x], \ 1], \ 1], 

          																			{i, \ 1\ Length[y]}, 
          \ {j, \ 1, \ Length[y]}]]\)

Finally, the following function takes the minimum of the efficiency measures just computed to calculate the actual list of efficiencies.

costEfficiency[w_,  x_,  y_]  :=  Map[Min,  eff[w,  x,  y]]

EXAMPLE OF COST EFFICIENCY MEASUREMENT

<< cost.dat

Now we compute the efficiencies.

effAll  =  costEfficiency[w,  x,  y]

Note that the only thing that is controlled for in these efficiency measures is the factor prices. Nothing is done about type of hospital, patient mix, and so on. Clearly some of the observed "inefficiency" is likely to be due to such factors. 

We can use the same technique to measure efficiency with respect to a subset of the factor inputs. Here we extract just the labor inputs and measure the efficiencies with respect to those labor choices only.
	W

wlabor  =  
      Transpose[{Transpose[w][[1]],  Transpose[w][[2]]}];

xlabor  =  
      Transpose[{Transpose[x][[1]],  Transpose[x][[2]]}];

effLabor  =  costEfficiency[wlabor,  xlabor,  y]

The two series look fairly similar. We do a scatterplot to compare the two lists
of efficiency measures.

ListPlot[Transpose[{effAll, effLabor}]]

Note that the two series are very highly correlated; that is, firms that have low
labor efficiency also appear to have low overall efficiency.

UTILITY MAXIMIZATION

We now turn to consumer behavior. Consider a consumer who chooses a vector
of consumption goods x, facing a price vector p, and having income m so as to
maximize utility:

(min_x) u x

such that px ≥ m.

Define the direct revealed preference relation by (x^t)(R^D)(x^s) if and only if (p^t)(x^t) ≥
(p^t)(x^s). The terminology is rather intuitive: (x^t) is directly revealed preferred to (x^s) if
(x^t)  is purchased when (x^s) was affordable. The revealed preference relation R is de-
fined to be the transitive closure of the relation (R^D) . That is, (x^t)Rx if and only if there
is some chain of observations ((x^s), (x^r), . . ., (x^V)) such that (x^t)(R^D)(x^s), (x^s)(R^D)(x^r), . . ., (x^v)(R^D)x.
Finally, some observed choices ((p^t), (X^t)) are consistent with the utility maximiza-
tion model if and only if they satisfy the Generalized Axiom of Revealed Preference
(GARP):

GARP: If (x^t)(Rx^s), then it is not the case that (p^s)(x^s) > (p^s)(x^t).

In words: if (x^t) was chosen when (x^s) was affordable, then (x^s)cannot be chosen when (x^t)is affordable.

COMPUTING THE TRANSITIVE CLOSURE OF A PREFERENCE RELATION

As before we assume that the data come as two n × k matrices of prices and quantities.

The rdMatrix has a 1 in the (i, j) entry if observation i is directly revealed preferred to observation j.

\(rdMatrix[p_, \ x_]\  := \ 
      Module[{i, \ j, \ n}, 
																				
        n\  = \ Length[x]; 
																				
        Table[If[
            p[\([i]\)]\ .\ x[\([i]\)]\  >= 

              																					
              p[\([i]\)]\ .\ x[\([j]\)], \ 1, \ 0], 

          			\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ {i, \ 1, \ n}, \ {j, \ 1, \ n}]]\)

We need to compute the transitive closure of this matrix. A possible way to do this is to raise the matrix to the nth power and then look at the sign of each entry. It is not hard to see that the (i, j) entry of the nth power matrix will be positive if and only if there is some chain of entries connecting i to j in the original matrix that are positive. This is very simple to implement in Mathematica.

tClosure[m_]  :=  Sign[MatrixPower[m,  Length[m]]]

See the appendix for another way to compute the transitive closure.

EXAMPLE

Here is an example with three observations where the direct revealed preference relation involves no cycles, but the revealed preference relation does.

\(p\  = \ {{1, \ 2, \ 8}, \ {4, \ 1, \ 8}, \ {3, \ 1, \ 2}}; 

    x\  = \ {{2, \ 1, \ 3}, \ {3, \ 4, \ 2}, \ {2, \ 6, \ 2}}; \)

m  =  rdMatrix[p,  x]

tClosure[m]

CHECKING GARP

Once we compute the transitive closre, it is easy to check GARP. A convenient way to do this is to compute a "consupmtion efficiency index" analogous to the cost efficiency index we computed previously. Here is a function that returns the observations revealed preferred to observation i, given the revealed preference relation summarized by the matrix m.

ObsRP[i_,  m_]  :=  
      Complement [
        Table[If[m[[j,  i]]  >  0,  j,  i], 
           {j,  1,  Length[m]}],  {0}]

The function consEfficiency computes the minimum expenditure necessary to purchase an observed choice that is revealed preferred to a given observation.

\(consEfficiency[p_, \ x_]\  := 
	
      Module[{m, \ n}, \ m\  = \ tClosure[rdMatrix[p, \ x]]; \ 
        n\  = \ Length[x]; 
		
        Table[Min[
            x[\([ObsRP[i, \ m]]\)]\ .\ p[\([i]\)]/p[\([i]\)]\ .\ x[\([i]\)]], 
          \ {i, \ 1, \ n}]]\)

Here is an example of how this function is used.

\(p\  = \ {{1., \ 2.}, \ {2., \ 1.}}; 

    x\  = \ {{1., \ 2.}, \ {2., \ 1.}}; \)

consEfficiency[p,  x]

This shows that each of the two choices is onl 80% efficient.

THE TOKEN ECONOMY

Battalio et al. [Battalio 1973] collected a set of data on the consumption choices of 38 patients at Central Islip State Hospital. As part of their therapeutic treatment, the patients worked for tokens that could be retrieved for items  such as cigarettes, candy, milk, locker rental, clothes, admission to a dance, and the like. During a seven-week period, the relative prices of various groups of these goods were doubled or halved. Because the prices of some of the goods were halved some weeks and doubled other weeks, prices varied by a factor of four. Data were collected on how the expenditures of each individual responded to the price changes. These data have been examined by Battalio and Cox [Cox 1994] using revealed preference techniques.

Here are the prices and choices for subject number 8 in these experiments.

\(p\  = 
      \ {{1., \ 1., \ 1.}, \ {0.5, \ 2., \ 1.}, \ {1., \ 1., \ 1.}, 
        \ {2., \ 0.5, \ 1.}, \ {2., \ 0.5, \ 1.}, \ {1., \ 1., \ 1.}, 
        \ {1., \ 1., \ 1.}}; 

    x\  = \ {{30, \ 9, \ 9}, \ {34, \ 10, \ 0}, \ {10, \ 4, \ 0}, 
        \ {4, \ 8, \ 5}, \ {2, \ 15, \ 0}, \ {0, \ 15, \ 9}, 
        \ {4, \ 7, \ 12}}; \)

Here is the consumption efficiency of this consumer's choices.

consEfficiency[p,  x]

Most of the consumers in the Battalio study were quite efficient. There were 256 choices made during the seven-week experiment. Of the inefficient choices, 8 were 97-99% efficient, 4 were 93-96% efficient, 1 was 91% efficient, and one was 81% efficient.

AFRIAT'S EFFICIENCY INDEX

The preceding efficiency index measures the consumption efficiency of each observation. Afriat's efficiency index, described in [Afrait 1967], measures the overall efficiency of a set of consumption choices. Following Afriat, we say that an observation r is directly revealed preferred to an observation s at efficiency level e of (ep^r) (x^r)≥ (p^r) (x^s). (Although Afriat does not require it, we adopt the convention that it is always the case that (x^r) (R^D) (x^r); i.e., an observation is always directly revealed preferred to itself.) Obviously e = 1 is the standard revealed preference comparison and e = 0 is vacuous. For a given e we can construct the analogue of the direct revealed preference measure, compute its transitive closure (Subscript[R, e]), and then check the analog of (Subscript[GARP, e]): if (x^s)(Subscript[R, e])(x^t), then(ep^t)(x^t) < (p^t) (x^s).

The following function computes the diret revealed preference relation associated with efficiency level e:

\(rdEMatrix[p_, \ x_, \ e_]\  := \ 
      Module[{i, \ j, \ n}, 
		n\  = \ Length[p]; 
		
        Table[If[
            \((e\ p[\([i]\)]\ .x\ [\([i]\)]\  >= \ p[\([i]\)]\ .\ x[\([j]\)])
                \)\  || \ i\  == \ j, \ 1, \ 0], 
			{i, \ 1, \ n}, 
          \ {j, \ 1, \ n}]]\)

We can use the tClosure function defined earlier to compute the transitive closure of this matrix. We then check to see if GARP is satisfied (at the given efficiency level) using the function GARPOK. This function returns a matrix with a False  in the (i, j) entry if (x^i)R(x^j)  and(ep^j)(x^j) > (p^j) (x^i); otherwise, it returns True. If GARPOK returns all True entries, the data are consistent with GARP at efficiency level e.

GARPOK[p_,  x_,  m_,  e_]  :=  
      Module[{i,  j,  n},  n  =  Length[m];  
        Table[ If[
            m[[i,  j]]  ==  1  &&  
              (e p[[j]] . x[[j]]  >  p[[j]] . x[[i]])
                ,  False,  True],  {j,  1,  n},  {i,  1,  n}]]

We use the GARPOK function to define a couple of other useful functins. This function returns the list of observations that violate GARP (at efficiency level e).

\(ViolationList[p_, \ x_, \ e_]\  := 
	
      Module[{m}, \ m\  = \ tClosure[rdEMatrix[p, \ x, \ e]]; \ 
        Union[Flatten[Position[GARPOK[p, \ x, \ m, \ e], \ False]]]]\)

This function just counts the number of violations.

NumberViolations[p_,  x_,  e_]  :=  
      Length[ViolationList[p,  x,  e]]

We will try these functions on the example we used in the last section.

\(p\  = \ {{1., \ 2.}, \ {2., \ 1.}}; 

    x\  = \ {{1., \ 2.}, \ {2., \ 1.}}; \)

MatrixForm[GARPOK[p,  x,  tClosure[rdEMatrix[p,  x,  .81]],  .81]]

MatrixForm[GARPOK[p,  x,  tClosure[rdEMatrix[p,  x,  .79]],  .79]]

This shows that the Afriat efficiency measure is between .79 and .81. we can automate the process of finding the maximal value of e such that the data satisfy GARP by using the following binary search.

\(AfriatEfficiency[p_, \ x_, \ maxSteps_]\  := \ 
      Module[{step, \ e}, \ e\  = \ 1/2; 
		
        For[step\  = \ 1, \ step\  <= \ maxSteps, \ \(step++\), 
			
          If[NumberViolations[p, \ x, \ e]\  > \ 0, 
				
            e\  = \ e\  - \ 2^\((\(-\((step\  + \ 1)\)\))\), 
				
            e\  = \ e\  + \ 2^\((\(-\((step\  + \ 1)\)\))\)]; 
			
          Print[N[e]]]]\)

AfriatEfficiency[p,  x,  10]

As we saw before, these choices are about 80% efficient. 

Here are the Battalio et al. data for subject 8 again:

\(p\  = 
      \ {{1., \ 1., \ 1.}, \ {0.5, \ 2., \ 1.}, \ {1., \ 1., \ 1.}, 
        \ {2., \ 0.5, \ 1.}, \ {2., \ 0.5, \ 1.}, \ {1., \ 1., \ 1.}, 
        \ {1., \ 1., \ 1.}}; 

    x\  = \ {{30, \ 9, \ 9}, \ {34, \ 10, \ 0}, \ {10, \ 4, \ 0}, 
        \ {4, \ 8, \ 5}, \ {2, \ 15, \ 0}, \ {0, \ 15, \ 9}, 
        \ {4, \ 7, \ 12}}; \)

AfriatEfficiency[p,  x,  10]

It appears that subject 8 is about 97% efficient in her choices.

DRAWING BUDGET SETS

Here are some functions to draw a set of bedgets and illustrate the observations that violate revealed preference

DrawABudget[{p1_,  p2_},  {x1_,  x2_}]  :=  
      Module[{w,  t},  w  =  p1 x1  +  p2 x2;  
        Plot[w/p2  -  p1 t/p2,  {t,  0,  w/p1},  AspectRatio  ->  1, 
           DisplayFunction  ->  Identity]]

DrawBudgets[p_,  x_]  :=  
      Table[{DrawABudget[p[[i]],  x[[i]]],  
          Graphics[Point[x[[i]]]]},  {i,  1,  Length[p]}]

PlotViolations[p_,  x_]  :=  
      ListPlot[x[[ViolationList[p,  x,  1]]], AspectRatio  ->  1,  
        DisplayFunction  ->  Identity,  
        PlotStyle  ->  {Hue[0],  PointSize [.02]}]

DrawViolations[p_,  x_]  :=  
      Show[DrawBudgets[p,  x],  PlotViolations[p,  x],  
        Prolog  ->  PointSize[.02],  
        DisplayFunction  ->  $DisplayFunction]

EXAMPLE

To illustrate the use of DrawViolations, we examine some experimental data generated by Andreoni and Miller [Andreoni and Miller 1994]. They presented subjects with a choice between taking some money for themselves or donating money to a group. If the subjects chose to donate, the experimenters would match the donations at various rates, thereby changing the "price" of the donations. Andreoni and Miller were interested in whether the subjects' contributions varied with the price of contributions in the way predicted by the theory of economic choice.

Here is the choice behaviour exhibited by one of their subjects:

\(p = 
      \ {{1.0, \ 0.5}, \ {0.5, \ 1.0}, \ {2.0, \ 1.0}, \ {1.0, \ 2.0}, 
        \ {1.0, \ 1.0}, \ {1.0, \ 0.5}, {0.5, \ 1.0}, \ {2.0, \ 1.0}, 
        \ {1.0, \ 2.0}}; 

    x\  = \ {{30., \ 16.}, \ {76., \ 0.}, \ {22.5, \ 5.0}, \ {30.0, \ 10.0}, 
        \ {40.0, \ 10.0}, \ {40.0, \ 20.0}, \ {100.0, \ 0.0}, 
        \ {35.5, \ 5.1}, \ {60.8, \ 7.6}}; \)

DrawViolations[p,  x]

(The violations are illustrated in red on the screen but they come through as grey on the monochrome printed page.)

APPENDIX

In the text we computed the transitive closure of the direct revealed preference relation by computing the matrix power of the direct revealed preference matrix. We did this using the internal Mathematica function MatrixPower. Raising an n × n matrix to the power n would require (n^4) operations if done in the most
straightforward way. Another, seemingly more efficient, way to compute the
transitive closure is given by Warshall's algorithm [Warshall 1962].

\(Warshall[mat_]\  := \ 
      Module[{i, j, k, n, m}, 
m = mat; 
n = Length[m]; 

        For[k = 1, k <= n, \(k++\), 

          For[i = 1, i < \(--n\), \(i++\), 

            For[j = 1, j <= n, \(j++\), 
              If[m[\([i, k]\)]\  = \ 1\  && \ m[\([k, j]\)] == 1, 

                m[\([i, j]\)] = 1]]]]; m]\)

Note that Warshall's algorithm involves only (n^3) operations. Despite this, Warshall's algorithm is much slower than using the internal MatrixPower function.
For example, here is a random 10 × 10 matrix:

\(\(\(m\  = Table[Random[Integer, {0, 1}], {i, 1, 10}, {j, 1, 10}]; \)

    \)\)

Here is how long Warshall's algorithm takes to compute the transitive closure.

\(\(\(Timing[Warshall[m]]\)[\([1]\)]
\)\)

Here is how long MatrixPower takes:

\(\(\(Timing[tClosure[m]]\)[\([1]\)]
\)\)

This illustrates an important point about Mathematica programming: always use the built-in functions when possible.

SUMMARY

Calculating choice efficiency for consumption and production data is very easy using Mathematica. In addition the data can be graphed, manipulated, and analyzed in a variety of other ways.

ACKNOWLEDGEMENT

This article was originally printed in Computational Economics and Finance: Modeling and Analysis with Mathematica TELOS/Springer-Verlag,1996, and is reprinted with permission of the author and publisher.

REFERENCES

Afriat, S. 1967. "The Construction of a Utility Function From Expenditure Data." International Economic Review, 7, 67-77.

Andreoni, J. and Miller, J. H. 1994. "Giving According to GARP: An Experimental Study of Rationality and Altruism." CMU Working Paper.

Battalio, R. C. et al. 1973. "A Test of Consumer Demand theory Using Observations of Individual Consumer Purchases." Western Economic Journal, 11, 411-428.

Brooks, J. 1993. "Measuring Cost Efficiency in VA Hospital Pharmacies: An Applied Critique of the Methods." Ph.D. dissertation, University of Michigan.

Cox, J. C. 1994. "On Testing the Utility Hypothesis." Technical report, University of Arizona.

Houtman, M. and Maks, J. A. 1985. "Determining all Maximial Data Subsets Consistent With Revealed Preference." Kwantitatieve Methoden, 19, 89-104.

Warshall, S. 1962. "A Theorem on Boolean Matrices," Journal of the American Association of Computing Machiniery, 9, 11-12.

Varian, H. 1993. Microeconomic Analysis, 3rd ed. New York, W. W. Norton & Co.

ABOUT THE AUTHOR

Associate Editor Hal R. Varian is the Dean of the School of Information Management and Systems at the University of California at Berkeley. He is also a Professor in the Haas School of Business, a Professor in the Department of Economics, and holds the Class of 1944 Professorship. 

He received his S.B. degree from MIT in 1969 and his MA (mathematics) and Ph.D. (economics) from UC Berkeley in 1973. He has taught at MIT, Stanford, Oxford, Michigan and other universities around the world. 

Among his publications are: Economic and Financial Modeling with Mathematica 
(editor) A collection of articles showing how to use the computer language Mathematica for economic and financial applications. TELOS/Springer-Verlag, 1992. 
Computational Economics and Finance: Modeling and Analysis with Mathematica 
(editor) A collection of articles showing how to use the computer language Mathematica for economic and financial applications. TELOS/Springer-Verlag,1996. 

Hal R. Varian
University of California, Berkeley
hal@sims.berkeley.edu

Electronic Subscriptions

Încluded in the distribution for each electronic subscription is the file xxxnb, containing Mathematica code for the material described in this article.