UNIVERSITY OF CALIFORNIA, LOS ANGELES
Department of Economics

Economics 143 (Cameron) - Applied RegressionAnalysis

Computing Lab Session #??:Understanding 3-Dimensional Surfaces: SurfacePlotter


Goals of this lab:
  1. Explore the "SurfacePlotter" java applet (by Yanto Suryono, http://yanto.home.ml.org)
  2. Use the applet to visualize non-linear three-dimensional surfaces
  3. Use the applet in conjunction with the results of a SHAZAM regression to visualize the shape of a fitted surface
Tasks:
  • A. Getting ready:
    1. If you would like an idea what you will find in the SurfacePlotter, take my Guided Tour.
    2. If you have finished the Guided Tour (or have decided you do not need it) load the SurfacePlotter.
    3. Note that it is capable of plotting two different surfaces. The first "dependent" variable is called z1; the second is called z2. We'll start with just z1 as a function of variables x and y. (It is unfortunate that Suryono is not an econometrician. You will just have to remember that y is not the dependent variable in SurfacePlotter...x is.)
    4. Start by adjusting the minimums and maximums, using either the (+/-) buttons on the right, or typing new values. Set all the minimums of the three variables to 0. Set all the maximums of the two variables to 5. This ensures that all three variables are positive numbers between 0 and 5. Note that most economic variables are positive-valued.
    5. For increased resolution, change the value of the "Divisions" parameters to 30 in both cases.
    6. Change the number of contours to 20


  • B. Try a linear function:
    1. For z1, type in the formula:
      1 + 0.5*x + 0.5*y
      (note that decimal fractions must be written 0.5, not just .5. The spaces are optional. Then click on the "Calculate" button on the top right. It may not, initially, look like a 3-D surface.
    2. So that you know what you are looking at, select "Options" on the top menu (click and hold). Drag down to "Show X-Y ticks." Repeat to reveal the Z ticks on the vertical axis ("Show Z ticks").
    3. Now set this linear (flat) surface in motion by clickin on the "Rotate" button near the top right. You can freeze the surface in any desired position by clicking on "Freeze" (which replaces "Rotate" when the picture is in motion. Stop and start the animation a few times, paying particular attention to the labels on the axes. (It takes a little practice to be able to put your finger on the (0,0,0) origin-point of the box.
    4. Now make the plot a little more interesting. Click on "Options" and select "Hidden Surface Elimination." Animate the surface using the "Rotate" button. What happens?
    5. Now enhance your ability to visualize the surface by clicking on "Options" and selecting "Color Spectrum Mode." It may help to think of the z variable as Temperature, with blue being "coldest" and red being "hottest." You may rotate the surface again, if you like.


  • C. Level Curves:
    1. The applet also allows you to see a "map" of the three-dimensional surface, with contours connecting X-Y locations of equal height in the Z dimension. (Remember that economists use contour lines of functions A LOT! These are what indifference curves are, and isoquants are contour lines of functions as well.) Here, the contour lines are not very interesting, because we are mapping a planar (flat) surface. However, the fact that the contour lines have different colors belies the fact that this flat surface is "tilted," with the low end near (x,y)=(0,0) and the high end near (x,y)=5. Here, however, the plan extends outside of the 3-D "box" before we get to (x,y)=(5,5), so no contour lines are available there.
    2. To see what happens to the contour lines if the plane we are mapping is not tilted, alter the function to just:
      1
      , and click on the "Calculate" button. What happens to the contour lines? Why? Verify by clicking on "Options" and reverting to "Surface Plot." Does this match your intuition?


  • D. A fully quadratic surface:
    1. Now make the z1 function more interesting. For starters, try the following quadratic function in the two variables, x and y:
      1 + 0.5*x + 0.5*y - 0.1*x*x - 0.1*y*y + 0.3*x*y
      Monitor the area just below the two equations to detect whether you have made any errors in entering your function. Set the surface in motion. Identify the (0,0,0) point in the plot. Note that this function is symmetric in y and x. Freeze the surface, go to "Options," and select "Contour Plot" to see the level curves of the surface. These would be the indifference curves or isoquants corresponding to the surface if this was a utility function or a production function, respectively. If this was a preference function defined over x=Dove Bars and y=broccoli, what are the properties of these preferences (think especially about the issue of satiation).
    2. Now explore the role of the interaction term in this function: Use
      - 0.3*x*y 
      instead of adding it. What happens to the surface plot? Now eliminate the last term from the function altogether by deleting the
      -0.3*x*y
      . What happens?
    3. Experiment with changing other aspects of the function. Check the surface plot and the associated contour plot until you are comfortable with their correspondence.


  • E. Adding a second surface:
    1. Click on the checkbox to activate the second function. Initially, set it to a constant value by entering the function as just
      2
      . Make sure you are in surface plot mode and click on "Calculate" to display this second function, and animate it with the "Rotate" button. (Only the first function's contour plot is shown, so there is not point in looking again.) Note that the intersection between the two surfaces occurs at the same height (i.e. 2) and the intersection occurs where the color of the surface is a light turqoise (or whatever color is displayed for a height of 2 units on your monitor).
    2. If we make z2=4, then the additional surface appears at the "yellow" height. The curved locus formed by the intersection of these two surfaces, when projected down to the floor of the space, is a contour line. Make sure you hone your intuition with this sort of thing.


  • F. Tricking the applet into doing budget constraints...
    1. To get an almost vertical plane that passes through the point (2.5,2.5,2.5), we can plot the following z2 function:
      z = -4997.5 + 1000*x + 1000*y
      . Why? This surface is not completely vertical, as it should be, but it is close. It has a slope of 1000 in each direction, and an extremely small z-intercept. Calculate the function and display both z1 and z2, and rotate them. Be aware that this extreme slope for z2 confuses the color spectrum a bit. You can switch the functions on and off using the checkboxes without stopping the animation.
    2. View the budget constraint in (x,y) space corresponding to the "vertical" plan z2 by clicking on the checkbox next to z1 to disable it, calculating z2 alone, and then switching to contour plot mode. You should see a budget constraint corresponding to identical prices for x and y.
    3. Now double the coefficient on x in the formula for z2 and recalculate the level curve for the surface. It should again be a straight line with virtually no thickness. What has happened to the relative prices? Activate both functions in "Surface Plot" mode and see if you can identify the point of constrained utility maximization.
    4. Play around with all of the parameters and see if you can improve your intuition about this very sophisticated piece of Web-based software.
  • Trudy Ann Cameron; Updated: 6:06 PM 8/28/98; Site Index