UNIVERSITY OF CALIFORNIA, LOS ANGELES
Department of Economics
Economics 143 (Cameron) - Applied RegressionAnalysis
Computing Lab Session #6b: Visualizing 2-D Functions

Funded in part by a small grant from UCLA's Instructional Enhancement Initiative, I have enlisted Geoffrey Gerdes (a UCLA Economics Graduate student) to develop a Java applet that will help Economics 143 students (and others) understand the geometry of polynomial functions (especially quadratics) and a selection of other two-dimensional functions.  I have found, in the past, that many students have difficulty understanding how the mathematical formula for a quadratic function translates into the physical shape of the relationship between the two variables.

Goals of this lab:

  1. Explore the "2D Function Studio" Java applet (by Geoffrey Gerdes)


  2. Use the applet to visualize a number of bivariate relationships


  3. Use the applet in conjunction with the results of a SHAZAM regression to visualize, geometrically, the shape of a fitted regression function with one explanatory variable that enters in a nonlinear fashion (e.g. quadratic, cubic, quartic, hyperbolic, etc.)


Tasks:
  • A. Getting ready:


    1. Load the 2D Function Studio applet. It will be helpful, if your screen is large enough, to have two browser windows open at the same time. Most right-handed people will find it convenient to resize and move the windows until these lab instructions are on the left, and the 2D Function Studio window is on the right (or use the reverse, I suppose, if you are left-handed). [Load 2D Function Studio]


    2. Note that 2D Function Studio, when activated, produces two windows.  One window contains the "control buttons" that dictate what is plotted in the graph.  The other window contains the plot of the function.  (The default function will be a generic polynomial.)  Click on the "Large" button to enlarge the plot window, so it can be seen behind the control window, and drag the control and plot windows until both are clearly visible.


    3. Examine the control window.  All parameters are initially set to zero, so the equation display across the bottom will show "y = ", with no right hand side terms.  The parameters a through d are the coefficients of a polynomial that takes the form "y = a + b*x + c*x2 + d*x3."  (We hope that this is a much as you are ever likely to need in Economics 143.)  Most of the forms that will be of interest to us in the course will leave parameter d equal to zero.


    4. You can change the values of the parameters for this two-dimensional function, and the new function will be instantly plotted.  The current values of the parameters are displayed in the right-most column of the parameter display, and they are also incorporated into the algebraic statement of the current function near the bottom of the control window.  You may alter the scale of the x and y axes, as necessary.  There is also an option to display the derivative of y with respect to x, as a function of x on the same plot.  (Leave this switched off for now.)



  • B. Try some one-parameter plots:


    1. Click and drag the slider for the a parameter all the way to the right.  What happens to the algebraic statement of the function?  Observe what happens in the plot window.  How do you suppose you can get the horizontal line to move higher? (HINT:  you can reset the limits on a.)  What happens if you increase the y scale by moving its slider to the right?  Does everything seem to be working as you would anticipate?


    2. Move the slider for a back to approximately zero, and then fine-tune it to exactly zero by clicking on the arrow keys at each end of the slider bar until the value of the a parameter displayed on the right is exactly zero.  (Notice that everything is rounded to the second decimal place.)


    3. Now experiment with the b parameter.  This is the linear term in the polynomial.  Move its slider back and forth to observe what happens to the plot. At the same time, observe what is going on with the algebraic statement of the function at the bottom of the control window.


    4. Introduce the secondary plot of the derivative of this "linear function through zero" by clicking on the "Show Derivative" button in the control window.  What do you know about the derivative of a straight line?  Move the slider for the b parameter back and forth and observe what happens to the derivative of the main function with respect to x, at each value of x, as b changes.


    5. Move the slider for the b parameter back to approximately zero, then fine-tunit to exactly zero by clicking on the arrow keys at each end of the slider bar until the value of the b parameter displayed on the right is exactly zero.  Click on the "Hide Derivative" button.


    6. Experiment with the slider for the c parameter. With the slider positioned to the right of the middle, recall what you know about the derivative of such a function.  Is it constant?  How does it change as you calculate it at values of x moving from left to right?  Verify your intuition by clicking on the "Show Derivative" button.  Were you right?


    7. What happens to the plots of the function and its derivative as you move the c parameter to exactly zero?  Is this consistent with your intuition?  Now make c go negative.  What happens to the derivative as it is calculated at larger and larger values of x?


    8. Whe you are finished, click the "Hide derivative" button.  If you have ever wonders about higher-order polynomial functions with only a single term, you might want to experiment with the same set of exercises for parameter d, but we will not do these in the lab.



  • C. Try some multi-parameter plots:


    1. A linear model, with intercept and slope, can be displayed by moving both the a and b parameters away from zero.  Try moving both the intercept-term a parameter and the linear-term b parameter to their maximum default-range values. Will the derivative of this function, plotted as a function of x, be particularly interesting?  Click "Show Derivative."  Predict what will happen to the derivative function when you now adjust the value of the intercept a parameter alone.  Explain why.  Now try it.  Was your prediction right?


    2. Move both a and b back to their default-range maximum values, leaving the derivative plot activated.  Predict what will happen to the following plot features as you move thelinear-term b parameter:  (i) the intercept of the main function, (ii) the slope of the main function, (iii) the plot of the derivative.  Try it and verify your predictions.


    3. Click the "Hide Derivative" button and restore all parameters to their default zero values.  Move just the quadratic-term c parameter to its maximum default-range value.  Before attempting it, predict what will happen to the U-shaped curve that you observe when you increase (or decrease) the value of the intercept-term a parameter.  Verify your prediction.  Were you right?  Restore the a parameter to zero, but leave the quadratic-term c parameter at its maximum default-range value..


    4. Now predict what will happen to the U-shaped curve when you alter just the linear-term b parameter, leaving the intercept-term a parameter at zero. (This is where most people's intuition begins to get shaky). Try it.  If the effect is not sufficiently pronounced, you might want to vary b over a wider range of values that the defaults permit.  Change the limits on the b parameter to -50 and 50, remembering to hit the enter key after changing each setting.  The effect, in the plot, of adjusting b will then be more obvious.  Through what point does the main function always pass, regardless of the values of b or c?  If you hold c constant at its maximum value, does the "curvature" of the U-shaped plot change as you adjust the linear-term b parameter?  How would you describe the nature of the change in the position of the curve as b changes?


    5. Move the b parameter back to zero, keeping c at its maximum.  Predict what the derivative plot will show, and then click the "Show Derivative" button.  Now recall what happened to the U-shaped curve as you adjusted the linear-term b parameter.  What, therefore, whould happen to the derivative of the main function as you adjust the b parameter?  Try it.  Is the slope of the derivative function affected by changes in the linear-term b parameter?  What about the vertical intercept of the derivative function?  (What is the exact value of the intercept of the derivative function, for each value of b?)  To what does the horizontal intercept of the derivative function correspond?



  • D. Quadratic functions--the corresponding algebra:

    1. Reset the coefficients in the control window to their default values and hide the derivative plot.


    2. In a quadratic form, the sign of the quadratic-term c coefficient determines whether the U-shaped curve opens up or down. The curve opens upwards if the derivative increases with x; it opens downwards if the derivative decreases with x.  The derivative of the function with respect to x is given by the formula:  b + 2cx. (This is the function of x that is plotted when you display the derivative in the plot window.  This derivative function is "increasing in x" if c is positive.  The second derivative the main function is constant and equal to just 2c.)


    3. Which way does the curve open if c is positive?  Negative?  Verify your predictions using the sliders.  Use the "Show Derivative" option to confirm the algebraic insight in terms of what is happen to the derivative value as you move from left to right in the plot.  The coefficient c can be said to control the degree of curvature in the function.


    4. If you take the derivative of a quadratic function, set it equal to zero, and solve for the value of x that makes the equation true, you have found the value of x that represents the minimum (or maximum) of the quadratic function in question.  Here, the algebra is:
      y = a + b x + c x2
      dy/dx = b + 2c x = 0
      x* = -b/(2c)
      Specifically, the minimum or maximum of the function is given by "the negative of the linear-term coefficient divided by twice the quadratic-term coefficient."



  • E. Test Your Comprehension


    1. Review the ideas covered in this lab. 

    2. Try the on-line self-grading quiz to see how many of these concepts you have digested.


  • F. Use the 2D Function Studio to Display results from a SHAZAM regression


    1. Using the SHAZAM program fragment in lifecyc.sha and the data in lifecyc.dat, regress the first variable (income, y) on the second variable (age, x) and on the square of age. You will first have to generate the x2 variable.


    2. Make a note of the approximate values of the intercept (a), linear (b) and quadratic (c) coefficients produced by the regression analysis.


    3. Now use a STAT command to reveal the minimum and maximum values of income and age in the data set. Keep these in mind as you view the shape of the plot


    4. Activate the window for the 2D Function Studio and adjust the first three coefficients to match what you have estimated in the lifecycle income regression. Do the results match your intuition?



    Trudy Ann Cameron; Updated: 2:54 PM 9/6/98; Site Index