Skip to main content

Illustrating Statistical Data

  • Chapter
  • First Online:
Illustrating Finance Policy with Mathematica

Abstract

Scholarship uses graphics to demonstrate relations and emphasize points. This chapter showcases a few effective examples from recent scholarship.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

eBook
USD 16.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 99.00
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 99.00
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    F. J. Anscombe, Graphs in Statistical Analysis, 27 Am. Stat. 17 (1973).

  2. 2.

    The notion that causation is practically indistinguishable from correlation is espoused by some contemporary philosophers; see, e.g., Judea Pearl, Causality: Models, Reasoning, and Inference (2d ed. 2009). Causation has posed enormous problems for philosophy, with philosophers taking positions ranging from the notion that causation is a fundamental concept that cannot be reduced to an explanation (the “primitivism” view) to that causation does not exist (the “eliminativist” view); see Jonathan Schaffer, The Metaphysics of Causation, in The Stanford Encyclopedia of Philosophy (Edward N. Zalta, ed., Fall 2016 Edition), https://plato.stanford.edu/archives/fall2016/entries/causation-metaphysics/ [perma.cc/MTL2-GXBX].

  3. 3.

    John J. Donohue III & Steven D. Levitt, The Impact of Legalized Abortion on Crime, 116 Q.J. Econ. 379–420 (2001).

  4. 4.

    John R. Allison, Mark A. Lemley, Kimberly A. Moore, & R. Derek Trunkey, Valuable Patents, 92 Geo. L.J. 435 (2004).

  5. 5.

    Jonathan Klick & Joshua D. Wright, Grocery Bag Bans and Foodborne Illness (November 2, 2012; U of Penn, Inst for Law & Econ Research Paper No. 13-2), SSRN https://ssrn.com/abstract=2196481.

  6. 6.

    For example, consider that the list baglinebef has its elements in pairs of month and hospitalizations, and that the list bagerrbef has its elements in pairs of month and error values. Create a list adding the error:

    befpluserr = Table[         {baglinebef[[j, 1]],          baglinebef[[j, 2]] + bagerrbef[[j, 2]]}         , {j, Length@baglinebef}];

    Also create a list subtracting the errors from the means, using the same method.

  7. 7.

    Assuming the two lists are befminuserr and befpluserr , join them, reverse the second, and make the depth consistent using Flatten [ list, 1] :

    polygonbef=Flatten[{befminuserr,Reverse@befpluserr},1];

    The same process produces a set of coordinates to use for creating a polygon for after the change.

  8. 8.

    For example:

    Graphics[{GrayLevel[.75],         Polygon@polygonbef,Polygon@polygonaft,         Black,Thick,         Line@baglinebef,Line@baglineaft },Axes- > True,AspectRatio- > .5,AxesOrigin- > {-10,0}, Ticks- > {Range[-10,10,5],Range[0,80,20]}]

  9. 9.

    The code stores the regression in a variable called gpaprob —the data are in the variable bon1 . By using g and l as the name of the variables and using the same variable names, we can later apply the formula that the probit regression produces through the command Normal :

    gpaprob = ProbitModelFit[bon1, {g, l}, {g, l}]

  10. 10.

    The code uses g for GPA values, uses l for LSAT values and uses the command Normal on the regression, gpaprob . Mathematica offers several ways to manipulate the appearance of the surface; here, the code makes it white by placing white sources of light above it. Also, Mathematica draws a box by default around its three-dimensional figures, and avoiding it requires the option Boxed set to False .

    carpet = Plot3D[Normal[gpaprob],         {g, 2.2, 4}, {l, 139, 170},         Boxed - > False,         BoxRatios - > {1, 1, .5},         Lighting - > {          {“Point”, White, {0, 150, 10}},          {“Point”, White, {0, 150, 2}},          {“Point”, White, {4, 170, 2}}}]

  11. 11.

    The Select command relies on a pure function that checks the third element of each datapoint for passage or failure:

    passing = Select[bon1,#[[3]] ==1&];

    failing = Select[bon1,#[[3]] ==0&];

  12. 12.

    The corresponding code first raises all points a little so they are more visible, by zboost . Then it sets the ratios of the dimensions of the ellipsoids through elratios . The results of the probit regression go into two functions, one not raised and one raised by zboost . Then the Table command produces a list of the ellipsoids corresponding to each student. The iterator, at the end of each Table command, is i and runs from one to the length of each list. Rather than just producing an ellipsoid, a GrayLevel appears before each. The color of each point is varied a little, by setting its GrayLevel at a random level using the command Random[Real, range] , with the range being .8 to .95 for the light gray passing students and 0 to .15 for the dark, failing ones. The ellipsoid radii come from the multiplication of the ratios (in elratios ) by a small number that gets the appropriate size.

    zboost = .01; elratios = {1.7, 30, 2}; probit[x_, y_]: = Normal[gpaprob]/.{g- > x, l- > y} probitzboost[x_, y_]: = zboost  +  probit[x, y] passrandomgrayspheres = Table[  {GrayLevel[Random[Real, {.8, .95}]],   Ellipsoid[{passing[[i, 1]], passing[[i, 2]],    probitzboost[passing[[i, 1]], passing[[i, 2]]]},  elratios .012]} , {i, Length@passing}]; failrandomblackspheres  =  Table[  {GrayLevel[Random[Real, {0, .15}]],   Ellipsoid[{failing[[i, 1]], failing[[i, 2]],    probitzboost[failing[[i, 1]], failing[[i, 2]]]},  elratios .011]}, {i, Length@failing}];

  13. 13.

    The code equates each variable to the value of x by applying to x the rule that FindRoot produces. The minima appear where the LSAT has a value of 139. The maxima appear whenre the LSAT has a value of 170 but only for the 50th and 95th percentiles. For the 5th percentile, the appropriate LSAT for the maximum end of the line comes from the minimum GPA:

    gpa95pcmax = x/.FindRoot[probit[x,170] ==.95,{x,2.8}]; gpa50pcmax = x/.FindRoot[probit[x,170] ==.5,{x,2.8}]; lsat05pcmax = x/.FindRoot[probit[2.3,x] ==.05,{x,140}]; gpa95pcmin = x/.FindRoot[probit[x,139] ==.95,{x,2.8}]; gpa50pcmin = x/.FindRoot[probit[x,139] ==.5,{x,2.8}]; gpa05pcmin = x/.FindRoot[probit[x,139] ==.05,{x,2.8}];

  14. 14.

    Each line has the corresponding GPA, LSAT, and probability as the coordinates of each end of the line:

    percentilelines = {  Line[{{gpa50pcmax,170,probit[gpa50pcmax,170]},   {gpa50pcmin,139,probit[gpa50pcmin,139]}}],  Line[{{gpa95pcmax,170,probit[gpa95pcmax,170]},     {gpa95pcmin,139,probit[gpa95pcmin,139]}}],   Line[{{2.3, lsat05pcmax,probit[2.3,lsat05pcmax]},     {gpa05pcmin,139,probit[gpa05pcmin,  139]}}]}

  15. 15.

    The basic code would be:

    Verse

    Verse Show[carpet,Graphics3D[{         passrandomgrayspheres,         failrandomblackspheres,         percentilelines}]]

  16. 16.

    Which means inserting at the last position of the Show command:

    ,PlotRange - > All,

    Axes - > True,

    AxesEdge - > {{-1, -1}, {1, -1}, {-1, -1}}

  17. 17.

    Thus, before the passing spheres, the code is:

    Lighting - > ”Neutral”, Specularity[White, 50],

    Whereas before the dark spheres the code makes them less shiny:

    Specularity[White, 20],

  18. 18.

    The complex function is part of the notebook’s initialization:

    text3D[str_, location_: {0, 0, 0},    scaling : {_?NumericQ, _?NumericQ} : { 1, 1},    longitude : _?NumericQ : 0, elevation : _?NumericQ : 0,    tilt : _?NumericQ : 0, opt : OptionsPattern[]] : =  Module[{mesh  =   DiscretizeGraphics[    Text[Style[str, opt, FontFamily - >  ”Times”,       FontSize - >  12(*don’t scale with ftsz*)]], _Text,     MaxCellMeasure - >  0.04],   rotmatrx  =    RotationMatrix[     longitude, {0, 0, 1}].RotationMatrix[-elevation, {0, 1,         0}].RotationMatrix[tilt, {1, 0, 0}]},    Join[{EdgeForm[]},     MeshPrimitives[mesh,   2] /. {x_?NumberQ,   y_?NumberQ} : >  (rotmatrx.(scaling ~ Join ~ {1} {x, y, 0}) +  location)]]

    Then the text3D function can be deployed in the command creating the graph.

  19. 19.

    See generally Howell E. Jackson & Mark J. Roe, Public and Private Enforcement of Securities Laws: Resource-Based Evidence, 93 J. Fin. Econ. 207 (2009).

  20. 20.

    See, e.g., Tom Ryan, Modern Regression Methods (1997); John Neter, William Wasserman, & Michael H. Kutner, Applied Linear Statistical Models (3rd ed. 1990); Normal R. Draper & Harry Smith, Applied Regression Analysis (3rd ed. 1998); R. Dennis Cook & Sanford Weisberg, Residuals and Influence in Regression (1982); David A. BelsleyEdwin Kuh, & Roy E. Welsch, Regression Diagnostics (1980); and Paul F. Velleman & Roy E. Welsch, Efficient Computing of Regression Diagnostics, 35 Am. Stat. 234–42 (1981).

  21. 21.

    Accordingly, for the horizontal axis, the variable to go on the horizontal axis must go last and the dependent variable must be absent. For example, assume the data is stored in the list datapts and corresponds to a judicial efficiency score, the staffing value, a wealth value and a value for the firms per population. The new list needs to take each element of datapts and have its first element, its third element, and its second element, in that sequence. The corresponding command uses the abbreviation for Take , the double square brackets, and the double semicolon to span over all elements of datapts ; then, in the second position inside the square brackets is the list of elements of each datapoint to take to form the new list of data:

    horizdata = datapts[[;;,{1,3,2}]]

    The data for running the regression for the vertical axis, then, needs to have the dependent variable in the last position and must omit the second item of each datapoint, the number of firms:

    vertdata = datapts[[;;,{1,3,4}]]

  22. 22.

    To wit:

    hrgn=LinearModelFit[horizdata,{x1, x2},{x1,x2}]

    vrgn=LinearModelFit[vertdata, {x1, x2},{x1,x2}]

  23. 23.

    The residuals are the actual values minus the predicted values:

    pltpts=Table[{  horizdata[[j,3]]-Normal[hrgn]/.   {x1- > horizdata[[j,1]],x2- >  horizdata[[j,2]]},  vertdata[[j,3]]-Normal[vrgn]/.   {x1- > vertdata[[j,1]],x2- > vertdata[[j,2]]}  },{j,Length@horizdata}]

  24. 24.

    Namely,

    nline = LinearModelFit[pltpts,x,x]

    As a matter of verification, the slope produced by this regression must match the coordinate of the corresponding variable in the regression of the dependent variable against all the independent variables.

  25. 25.

    The corresponding command forms the line using the Table command and having the iterator j take only two specific values: the minimum and the maximum of the x-coordinates in pltpts :

    Graphics[{         Point@pltpts,         Line@Table[          {j,Normal[nline]/.x- > j},          {j,{Min@pltpts[[;;,1]],Max@pltpts[[;;,1]]}}] },Axes- > True]

  26. 26.

    The corresponding option could be:

    AxesOrigin- > {-1,-1.5}

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Nicholas L. Georgakopoulos .

Rights and permissions

Reprints and permissions

Copyright information

© 2018 The Author(s)

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Georgakopoulos, N.L. (2018). Illustrating Statistical Data. In: Illustrating Finance Policy with Mathematica. Quantitative Perspectives on Behavioral Economics and Finance. Palgrave Macmillan, Cham. https://doi.org/10.1007/978-3-319-95372-4_7

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-95372-4_7

  • Published:

  • Publisher Name: Palgrave Macmillan, Cham

  • Print ISBN: 978-3-319-95371-7

  • Online ISBN: 978-3-319-95372-4

  • eBook Packages: Economics and FinanceEconomics and Finance (R0)

Publish with us

Policies and ethics