Articles

13.1E: Functions of Multiple Variables (Exercises)


13.1: Functions of Multiple Variables

For the following exercises, evaluate each function at the indicated values.

1) ( W(x,y)=4x^2+y^2.) Find ( W(2,−1), W(−3,6)).

Answer:
( W(2,−1) = 17,quad W(−3,6) = 72)

2) ( W(x,y)=4x^2+y^2). Find ( W(2+h,3+h).)

3) The volume of a right circular cylinder is calculated by a function of two variables, ( V(x,y)=πx^2y,) where ( x) is the radius of the right circular cylinder and ( y) represents the height of the cylinder. Evaluate ( V(2,5)) and explain what this means.

Answer:
( V(2,5) = 20π, ext{units}^3) This is the volume when the radius is ( 2) and the height is ( 5).

4) An oxygen tank is constructed of a right cylinder of height ( y) and radius ( x) with two hemispheres of radius ( x) mounted on the top and bottom of the cylinder. Express the volume of the cylinder as a function of two variables, ( x) and ( y), find ( V(10,2)), and explain what this means.

For exercises 5 - 10, find the domain and range of the given function. State the domain in set-builder notation and the range in interval notation.

5) ( V(x,y)=4x^2+y^2)

Answer:
Domain: ({(x, y) | x in m I!R, y in m I!R}) That is, all points in the (xy)-plane
Range: ( [0, infty) )

6) ( f(x,y)=sqrt{x^2+y^2−4})

Answer:
Domain: ( {(x, y) | x^2+y^2 ge 4})
Range: ( [0, infty) )

7) ( f(x,y)=4ln(y^2−x))

Answer:
Domain: ( {(x, y) | xRange: ( (-infty, infty) )

8) ( g(x,y)=sqrt{16−4x^2−y^2})

Answer:
Domain: ( {(x, y) | frac{x^2}{4} + frac{y^2}{16} le 1})
Range: ( [0, 4] )

9) ( z=arccos(y−x))

Answer:
Domain: ( {(x, y) | x - 1 le y le x + 1}) That is, all points between the graphs of (y = x -1) and (y = x +1 ).
Range: ( [0, pi] )

10) ( f(x,y)=dfrac{y+2}{x^2})

Answer:
Domain: ( {(x, y) | x eq 0 })
Range: ( (-infty, infty) )

Find the range of the functions.

11) ( g(x,y)=sqrt{16−4x^2−y^2})

Answer:
( {z|0≤z≤4})

12) ( V(x,y)=4x^2+y^2)

13) ( z=y^2−x^2)

Answer:
The set ( m I!R)

In exercises 14 - 29, find the level curves of each function at the indicated values of ( c) to visualize the given function. Sketch a contour plot for those exercises where you are asked for more than 3 values of (c).

14) ( z(x,y)=y^2−x^2, quad c=1)

15) ( z(x,y)=y^2−x^2,quad c=4)

Answer:
( y^2−x^2=4,) a hyperbola

16) ( g(x,y)=x^2+y^2;quad c=0, 1, 2, 3, 4, 9)

17) ( g(x,y)=4−x−y;quad c=0,1, 2, 3, 4)

Answer:
Level curves are lines with ( y = -x + (4 - c) ).
For each value of (c) these are:
( c = 0: , y = -x + 4),
( c = 1: , y = -x + 3),
( c = 2: , y = -x + 2),
( c = 3: , y = -x + 1),
( c = 4: , y = -x ).
The contour plot consists of a series of parallel lines.

18) ( f(x,y)=xy;c=1;quad c=−1)

19) ( h(x,y)=2x−y;quad c=-2,0,2)

Answer:
( 2x−y=0,2x−y=−2,2x−y=2;) three lines

20) ( f(x,y)=x^2−y;quad c=1,2)

21) ( g(x,y)=dfrac{x}{x+y};c=−1,0,1,2)

Answer:
Level curves are lines with the form ( y = x left( frac{1-c}{c} ight) ). At (c = 0), we solve it directly from the equation (dfrac{x}{x+y}=0) to get (x = 0).
For each value of (c) these are:
( c = -1: , y = -2x),
( c = 0: , x = 0, ext{ with }y e 0),
( c = 1: , y = 0, ext{ with }x e 0),
( c = 2: , y = -frac{1}{2}x).

22) ( g(x,y)=x^3−y;quad c=−1,0,2)

23) ( g(x,y)=e^{xy};quad c=frac{1}{2},3)

Answer:
The level curves have the form, ( y = frac{ln c}{x}).
For each value of (c) these are:
( c = frac{1}{2}: , y = frac{ln frac{1}{2}}{x}) that can be rewritten as, (y = -frac{ln 2}{x})
( c = 3: , y = frac{ln 3}{x}).

24) ( f(x,y)=x^2;quad c=4,9)

25) ( f(x,y)=xy−x;quad c=−2,0,2)

Answer:
Level curves have the form: ( y = frac{c}{x} + 1).
Here (y = frac{-2}{x} + 1,quad y = 1,quad y = frac{2}{x} + 1) or ( xy−x=−2,,xy−x=0,,xy−x=2)

26) ( h(x,y)=ln(x^2+y^2);quad c=−1,0,1)

27) ( g(x,y)=ln(frac{y}{x^2});quad c=−2,0,2)

Answer:
The level curves have the form, ( y =e^c x^2).
For each value of (c) these are:
( c = -2: , y = e^{-2} x^2 ),
( c = 0: , y = x^2 ),
( c = 2: , y = e^{2} x^2 ).

28) ( z=f(x,y)=sqrt{x^2+y^2},quad c=3)

29) ( f(x,y)=dfrac{y+2}{x^2},quad c=) any constant

Answer:
The level curves are parabolas of the form ( y=cx^2−2, ext{ with }x e 0).

In exercises 30-32, find the vertical traces of the functions at the indicated values of ( x) and ( y), and plot the traces.

30) ( z=4−x−y, quad x=2)

31) ( f(x,y)=3x+y^3, quad x=1)

Answer:

( z=3+y^3,) a curve in the (zy)-plane with rulings parallel to the (x)-axis

32) ( z=cossqrt{x^2+y^2}, quad x=1)

In exercises 33 - 38, find the domain and range of each function.

33) ( z=sqrt{100−4x^2−25y^2})

Answer:
Domain: ( {(x, y) | frac{x^2}{25}+frac{y^2}{4}≤1})
Range: ( [0, 10] )

34) ( z=ln(x−y^2))

35) ( f(x,y,z)=dfrac{1}{sqrt{36−4x^2−9y^2−z^2}})

Answer:
Domain: ( {(x, y, z) | frac{x^2}{9}+frac{y^2}{4}+frac{z^2}{36}<1})
Range: ( [frac{1}{6}, infty) )

36) ( f(x,y,z)=sqrt{49−x^2−y^2−z^2})

37) ( f(x,y,z)=sqrt[3]{16−x^2−y^2−z^2})

Answer:
Domain: All points in ( xyz)-space
Range: ( ig(-infty, sqrt[3]{16}ig] )

38) ( f(x,y)=cossqrt{x^2+y^2})

In exercises 39 - 40, plot a graph of the function.

39) ( z=f(x,y)=sqrt{x^2+y^2})

Answer:

40) ( z=x^2+y^2)

41) Use technology to graph ( z=x^2y.)

Answer:

In exercises 42 - 46, sketch the function by finding its level curves. Verify the graph using technology, such as CalcPlot3D.

42) ( f(x,y)=sqrt{4−x^2−y^2})

43) ( f(x,y)=2−sqrt{x^2+y^2})

Answer:

44) ( z=1+e^{−x^2−y^2})

45) ( z=cossqrt{x^2+y^2})

Answer:

46) ( z=y^2−x^2)

47) Describe the contour lines for several values of ( c) for ( z=x^2+y^2−2x−2y.)

Answer:
The contour lines are concentric circles centered at the point, ( (1, 1) ).
You can see this by completing the square after setting this function equal to (c).
That is, we write ( x^2-2x+1+y^2−2y+1 = c + 2 ) which can be rewritten as, ( (x - 1)^2 + (y - 1)^2 = c + 2 ).
This gives us circles centered at the point, ( (1, 1) ), each with a radius of ( sqrt{c+2} ).

In exercises, 48 - 52, find the level surface for the given value of (c) for each function of three variables and describe it.

48) ( w(x,y,z)=x−2y+z,quad c=4)

49) ( w(x,y,z)=x^2+y^2+z^2,quad c=9)

Answer:
( x^2+y^2+z^2=9), a sphere of radius ( 3)

50) ( w(x,y,z)=x^2+y^2−z^2,quad c=−4)

51) ( w(x,y,z)=x^2+y^2−z^2,quad c=4)

Answer:
( x^2+y^2−z^2=4,) a hyperboloid of one sheet

52) ( w(x,y,z)=9x^2−4y^2+36z^2,quad c=0)

In exercises 53 - 55, find an equation of the level curve of ( f) that contains the point ( P).

53) ( f(x,y)=1−4x^2−y^2,quad P(0,1))

Answer:
( 4x^2+y^2=1,)

54) ( g(x,y)=y^2arctan x,quad P(1,2))

55) ( g(x,y)=e^{xy}(x^2+y^2),quad P(1,0))

Answer:
( 1=e^{xy}(x^2+y^2))

56) The strength ( E) of an electric field at point ( (x,y,z)) resulting from an infinitely long charged wire lying along the (y)-axis is given by ( E(x,y,z)=k/sqrt{x^2+y^2}), where ( k) is a positive constant. For simplicity, let ( k=1) and find the equations of the level surfaces for ( E=10) and ( E=100.)

57) A thin plate made of iron is located in the (xy)-plane The temperature ( T) in degrees Celsius at a point ( P(x,y)) is inversely proportional to the square of its distance from the origin. Express ( T) as a function of ( x) and ( y).

Answer:
( T(x,y)=frac{k}{x^2+y^2})

58) Refer to the preceding problem. Using the temperature function found there, determine the proportionality constant if the temperature at point ( P(1,2)) is ( 50°C.) Use this constant to determine the temperature at point ( Q(3,4).)

59) Refer to the preceding problem. Find the level curves for ( T=40°C) and ( T=100°C,) and describe what the level curves represent.

Answer:
( x^2+y^2=frac{k}{40}, quad x^2+y^2=frac{k}{100}). The level curves represent circles of radii ( sqrt{10k}/20) and ( sqrt{k}/10)

Contributors

  • Gilbert Strang (MIT) and Edwin “Jed” Herman (Harvey Mudd) with many contributing authors. This content by OpenStax is licensed with a CC-BY-SA-NC 4.0 license. Download for free at http://cnx.org.

  • Paul Seeburger (Monroe Community College) edited the LaTeX and added contour plots to answers for problems 17, 21 and 29.

  1. By drawing diagrams (or by making precise algebraic arguments), determine which of the following sets is convex.
    1. <(x, y): y = ex >.
    2. <(x, y): yex >.
    3. <(x, y): xy ≥ 1, x > 0, y > 0>.
    1. Not convex, because e λx+(1−λ)u ≠ λex + (1 − λ)eu , as illustrated in the following figure.

    Specifically, e 0 = 1 and e 1 = e, but e 1/2 ≈ 1.649 and (1/2)1 + (1/2)e ≈ 1.859.

    The function e x is differentiable, and its second derivative is e x > 0, so that it is (strictly) convex. Hence by a result in the text the set of points above its graph, <(x, y): ye x > is convex.

    To show the result algebraically, let xy ≥ 1 and uv ≥ 1. We need to show that ≥ 1. We have

    x + (1 − λ)u)(λy + (1 − λ)v) = λ 2 xy + λ(1 − λ)(uy + xv) + (1 − λ) 2 uv.
    λ 2 xy + λ(1 − λ)(uy + xv) + (1 − λ) 2 uv λ 2 + 2λ(1 − λ) + (1 − λ) 2
    = (λ + (1 − λ)) 2
    = 1.
    h((1−λ)x + λx') = af((1−λ)x + λx') + bg((1−λ)x + λx')
    a(1−λ)f(x) + aλf(x') + b(1−λ)g(x) + bλg(x')
    = (1−λ)h(x) + λh(x'),
    1. f(x, y) = x + y.
    2. f(x, y) = x 2 . [Note: f is a function of two variables.]
    3. f(x, y) = x + yexex+y .
    4. f(x, y, z) = x 2 + y 2 + 3z 2 − xy + 2xz + yz.
    1. f((1−λ)x + λx',(1−λ)y + λy') = (1−λ)x + λx' + (1−λ)y + λy' = (1−λ)f(x,y) + λf(x',y'), so the function is concave and convex, but not strictly concave or strictly convex. Or you can calculate the Hessian, from which you can conclude that the function is both concave and convex, and then argue as above that the function is not strictly concave or strictly convex. [Note: the fact that some of the minors are zero does not imply that the function is not strictly concave or strictly convex, although in fact it is not.] Or you can appeal to the fact that the function is linear to conclude that it is concave and convex.
    2. The Hessian shows that the function is convex (all principal minors are nonnegative). The Hessian does not satisfy the sufficient condition for strict convexity, but this does not imply that the function is in fact not strictly convex. However, since, for example, f(1, 1) = f(1, 2) = f(1, 3), the function is in fact not strictly convex. (More generally, for all x, y, and y' we have f((1−λ)(x,y) + λ(x,y')) = f(x,(1−λ)y + λy') = x 2 = (1−λ)f(x,y) + λf(x,y').)
    3. The Hessian is
    h((1−λ)x + λy) = af((1−λ)x + λy) − bg((1−λ)x + λy)
    a(1 − λ)f(x) + aλf(y) − b(1 − λ)g(x) − bλg(y).

    The function h is also not necessarily not concave: if, for example, f(x) = x and g(z) = z (which are both concave), then h(x) = x, which is concave.


    Mathematical methods for economic theory

    Definitions

    A function that is neither

    the line segment shown lies

    points and below it at others

    Here is a precise definition.

    • concave if every line segment joining two points on its graph is never above the graph
    • convex if every line segment joining two points on its graph is never below the graph.

    Denote the height of the line segment from (a, f(a)) to (b, f(b)) at the point x by ha,b(x). Then according to the definition, the function f is concave if and only if for every pair of numbers a and b with x1ax2 and x1bx2 we have

    ha,b((1 − λ)a + λb) = (1 − λ)ha,b(a) + λha,b(b)

    Note that a function may be both concave and convex. Let f be such a function. Then for all values of a and b we have

    Economists often assume that a firm's production function is increasing and concave. Examples of such a function for a firm that uses a single input are shown in the next two figures. The fact that such a production function is increasing means that more input generates more output. The fact that it is concave means that the increase in output generated by each one-unit increase in the input does not increase as more input is used. In economic jargon, there are &ldquononincreasing returns&rdquo to the input, or, given that the firm uses a single input, &ldquononincreasing returns to scale&rdquo. In the example in the first of the following two figures, the increase in output generated by each one-unit increase in the input not only does not increase as more of the input is used, but in fact decreases, so that in economic jargon there are &ldquodiminishing returns&rdquo, not merely &ldquononincreasing returns&rdquo, to the input.

    Concave production function

    Concave production function

    The notions of concavity and convexity are important in optimization theory because, as we shall see, a simple condition is sufficient (as well as necessary) for a maximizer of a differentiable concave function and for a minimizer of a differentiable convex function. (Precisely, every point at which the derivative of a concave differentiable function is zero is a maximizer of the function, and every point at which the derivative of a convex differentiable function is zero is a minimizer of the function.)

    The next result shows that a nondecreasing concave transformation of a concave function is concave.

    By the definition of f we have

    Jensen's inequality: another characterization of concave and convex functions

    The function f of a single variable defined on the interval I is convex if and only if for all n ≥ 2

    Differentiable functions

    The fact that the graph of the function lies below this tangent is equivalent to

    The next result states this observation, and the similar one for convex functions, precisely. It is used to show the important result that for a concave differentiable function f every point x for which f'(x) = 0 is a global maximizer, and for a convex differentiable function every such point is a global minimizer.

    I now show that if the first inequality in the result holds then f is concave. Let x* ∈ I and x ∈ I , and define x' = (1 − λ)x* + λx. Then x' ∈ I and by the inequality, which holds for all values of x and x* in I , we have both

    Symmetric arguments apply for a convex function.

    Twice-differentiable functions

      if and only if f"(x) ≤ 0 for all x in the interior of I if and only if f"(x) ≥ 0 for all x in the interior of I .
    • either f"(x) > 0 if a < x < c and f"(x) < 0 if c < x < b
    • or f"(x) < 0 if a < x < c and f"(x) > 0 if c < x < b.

    Concave production function

    Note that some authors, including Sydsæter and Hammond (1995) (p. 308), give a slightly different definition, in which the conditions f"(x) > 0 and f"(x) < 0 are replaced by f"(x) ≥ 0 and f"(x) ≤ 0. According to this alternative definition, f" does not have to change sign at c. For example, for a linear function, every point satisfies the alternative definition.

    Strict convexity and concavity

    A function that is concave

    A concave function that has no linear parts is said to be strictly concave.


    13.1E: Functions of Multiple Variables (Exercises)

    These exercises are based on the variables exercises, so you may start from those (your solutions or ours) or start from scratch.

    The Fortune Teller

    Why pay a fortune teller when you can just program your fortune yourself?

    • Write a function named tellFortune that:
      • takes 4 arguments: number of children, partner's name, geographic location, job title.
      • outputs your fortune to the screen like so: "You will be a X in Y, and married to Z with N kids."

      The Puppy Age Calculator

      You know how old your dog is in human years, but what about dog years? Calculate it!

      • Write a function named calculateDogAge that:
        • takes 1 argument: your puppy's age.
        • calculates your dog's age based on the conversion rate of 1 human year to 7 dog years.
        • outputs the result to the screen like so: "Your doggie is NN years old in dog years!"

        The Lifetime Supply Calculator

        Ever wonder how much a "lifetime supply" of your favorite snack is? Wonder no more!

        • Write a function named calculateSupply that:
          • takes 2 arguments: age, amount per day.
          • calculates the amount consumed for rest of the life (based on a constant max age).
          • outputs the result to the screen like so: "You will need NN to last you until the ripe old age of X"

          The Geometrizer

          Create 2 functions that calculate properties of a circle, using the definitions here.


          3.4 Common problems

          Exercise 3.5.1

          What happens if you facet on a continuous variable?

          The continuous variable is converted to a categorical variable, and the plot contains a facet for each distinct value.

          Exercise 3.5.2

          What do the empty cells in plot with facet_grid(drv

          cyl) mean? How do they relate to this plot?

          The empty cells (facets) in this plot are combinations of drv and cyl that have no observations. These are the same locations in the scatter plot of drv and cyl that have no points.

          Exercise 3.5.3

          What plots does the following code make? What does . do?

          The symbol . ignores that dimension when faceting. For example, drv

          . facet by values of drv on the y-axis.

          cyl will facet by values of cyl on the x-axis.

          Exercise 3.5.4

          Take the first faceted plot in this section:

          What are the advantages to using faceting instead of the colour aesthetic? What are the disadvantages? How might the balance change if you had a larger dataset?

          In the following plot the class variable is mapped to color.

          Advantages of encoding class with facets instead of color include the ability to encode more distinct categories. For me, it is difficult to distinguish between the colors of "midsize" and "minivan" .

          Given human visual perception, the max number of colors to use when encoding unordered categorical (qualitative) data is nine, and in practice, often much less than that. Displaying observations from different categories on different scales makes it difficult to directly compare values of observations across categories. However, it can make it easier to compare the shape of the relationship between the x and y variables across categories.

          Disadvantages of encoding the class variable with facets instead of the color aesthetic include the difficulty of comparing the values of observations between categories since the observations for each category are on different plots. Using the same x- and y-scales for all facets makes it easier to compare values of observations across categories, but it is still more difficult than if they had been displayed on the same plot. Since encoding class within color also places all points on the same plot, it visualizes the unconditional relationship between the x and y variables with facets, the unconditional relationship is no longer visualized since the points are spread across multiple plots.

          The benefit of encoding a variable with facetting over encoding it with color increase in both the number of points and the number of categories. With a large number of points, there is often overlap. It is difficult to handle overlapping points with different colors color. Jittering will still work with color. But jittering will only work well if there are few points and the classes do not overlap much, otherwise, the colors of areas will no longer be distinct, and it will be hard to pick out the patterns of different categories visually. Transparency ( alpha ) does not work well with colors since the mixing of overlapping transparent colors will no longer represent the colors of the categories. Binning methods already use color to encode the density of points in the bin, so color cannot be used to encode categories.

          As the number of categories increases, the difference between colors decreases, to the point that the color of categories will no longer be visually distinct.

          Exercise 3.5.5

          Read ?facet_wrap . What does nrow do? What does ncol do? What other options control the layout of the individual panels? Why doesn’t facet_grid() have nrow and ncol variables?

          The arguments nrow ( ncol ) determines the number of rows (columns) to use when laying out the facets. It is necessary since facet_wrap() only facets on one variable.

          The nrow and ncol arguments are unnecessary for facet_grid() since the number of unique values of the variables specified in the function determines the number of rows and columns.

          Exercise 3.5.6

          When using facet_grid() you should usually put the variable with more unique levels in the columns. Why?

          There will be more space for columns if the plot is laid out horizontally (landscape).


          The .format() was introduced in python 3. It is the new style of formatting the strings. There is no dependency on ‘%’ operator when using this function.

          The above format is not flexible if you want to reorder the values, say you want to print color before fruit or use one value multiple times in the string without altering the tuple value sequence. For example,

          Or if you want to print red multiple times like:

          To solve such problems you can pass numbers which indicate the position of the argument without altering sequence of tuple values like below:

          Another option is to pass named indexes. For example,

          Note: The format() functions will not work in Python 2.x. But, you can import “print_function” from “__future__” library.


          Functions of a Complex Variable

          This is one of over 2,400 courses on OCW. Explore materials for this course in the pages linked along the left.

          MIT OpenCourseWare is a free & open publication of material from thousands of MIT courses, covering the entire MIT curriculum.

          No enrollment or registration. Freely browse and use OCW materials at your own pace. There's no signup, and no start or end dates.

          Knowledge is your reward. Use OCW to guide your own life-long learning, or to teach others. We don't offer credit or certification for using OCW.

          Made for sharing. Download files for later. Send to friends and colleagues. Modify, remix, and reuse (just remember to cite OCW as the source.)


          Directional light

          We want to define a function in the fragment shader that calculates the contribution a directional light has on the corresponding fragment: a function that takes a few parameters and returns the calculated directional lighting color.

          First we need to set the required variables that we minimally need for a directional light source. We can store the variables in a struct called DirLight and define it as a uniform. The struct's variables should be familiar from the previous chapter:

          We can then pass the dirLight uniform to a function with the following prototype:

          Just like C and C++, when we want to call a function (in this case inside the main function) the function should be defined somewhere before the caller's line number. In this case we'd prefer to define the functions below the main function so this requirement doesn't hold. Therefore we declare the function's prototypes somewhere above the main function, just like we would in C.

          You can see that the function requires a DirLight struct and two other vectors required for its computation. If you successfully completed the previous chapter then the content of this function should come as no surprise:

          We basically copied the code from the previous chapter and used the vectors given as function arguments to calculate the directional light's contribution vector. The resulting ambient, diffuse and specular contributions are then returned as a single color vector.


          Description:

          Write a PHP program to calculate area of rectangle by using PHP Function.

          Condition

          View Solution/Program.

          Area Of Rectangle with length 2 & width 4 is 8 .

          • PHP Exercises Categories
          • PHP All Exercises & Assignments
          • PHP String
          • PHP Top Exercises
          • PHP Loops
          • PHP Variables
          • PHP Decision Making
          • PHP Functions
          • PHP Syntax
          • PHP Array
          • PHP Operators
          • All Tutorials
          • PHP Tutorial
          • HTML Tutorial
          • SEO Tutorial
          • C Tutorial
          • CSS Tutorial
          • WordPress Tutorial
          • Python Tutorial
          • PHP REST API
          • jQuery Tutorial
          • JavaScript Tutorial
          • Bootstrap Tutorial

          Training Partner

          About Tutorials Class

          Tutorials Class (TutorialsClass.com) is one stop portal to learn online about different web technologies, preparing for an interview and enhancing your technical skills.

          We provide free online tutorials on the latest web technologies. These tutorials are well structured and easy to use for beginners. With each tutorial, you may find a list of related exercises, assignments, codes, articles & interview questions.

          This website provides tutorials on PHP, HTML, CSS, SEO, C, C++, JavaScript, WordPress, and Digital Marketing for Beginners. Start Learning Now.


          Getting started with Multivariate Multiple Regression

          Multivariate Multiple Regression is the method of modeling multiple responses, or dependent variables, with a single set of predictor variables. For example, we might want to model both math and reading SAT scores as a function of gender, race, parent income, and so forth. This allows us to evaluate the relationship of, say, gender with each score. You may be thinking, “why not just run separate regressions for each dependent variable?” That’s actually a good idea! And in fact that’s pretty much what multivariate multiple regression does. It regresses each dependent variable separately on the predictors. However, because we have multiple responses, we have to modify our hypothesis tests for regression parameters and our confidence intervals for predictions.

          To get started, let’s read in some data from the book Applied Multivariate Statistical Analysis (6th ed.) by Richard Johnson and Dean Wichern. This data come from exercise 7.25 and involve 17 overdoses of the drug amitriptyline (Rudorfer, 1982). There are two responses we want to model: TOT and AMI. TOT is total TCAD plasma level and AMI is the amount of amitriptyline present in the TCAD plasma level. The predictors are as follows:

          GEN, gender (male = 0, female = 1)
          AMT, amount of drug taken at time of overdose
          PR, PR wave measurement
          DIAP, diastolic blood pressure
          QRS, QRS wave measurement

          We’ll use the R statistical computing environment to demonstrate multivariate multiple regression. The following code reads the data into R and names the columns.

          Before going further you may wish to explore the data using the summary and pairs functions.

          Performing multivariate multiple regression in R requires wrapping the multiple responses in the cbind() function. cbind() takes two vectors, or columns, and “binds” them together into two columns of data. We insert that on the left side of the formula operator:

          . On the other side we add our predictors. The + signs do not mean addition per se but rather inclusion. Taken together the formula “cbind(TOT, AMI)

          GEN + AMT + PR + DIAP + QRS” translates to “model TOT and AMI as a function of GEN, AMT, PR, DIAP and QRS.” To fit this model we use the workhorse lm() function and save it to an object we named “mlm1”. Finally we view the results with summary().

          Notice the summary shows the results of two regressions: one for TOT and one for AMI. These are exactly the same results we would get if modeled each separately. You can verify this for yourself by running the following code and comparing the summaries to what we got above. They’re identical.

          The same diagnostics we check for models with one predictor should be checked for these as well. For a review of some basic but essential diagnostics see our post Understanding Diagnostic Plots for Linear Regression Analysis.

          We can use R’s extractor functions with our mlm1 object, except we’ll get double the output. For example, instead of one set of residuals, we get two:

          Instead of one set of fitted values, we get two:

          Instead of one set of coefficients, we get two:

          Instead of one residual standard error, we get two:

          Again these are all identical to what we get by running separate models for each response. The similarity ends, however, with the variance-covariance matrix of the model coefficients. We don’t reproduce the output here because of the size, but we encourage you to view it for yourself:

          The main takeaway is that the coefficients from both models covary. That covariance needs to be taken into account when determining if a predictor is jointly contributing to both models. For example, the effects of PR and DIAP seem borderline. They appear significant for TOT but less so for AMI. But it’s not enough to eyeball the results from the two separate regressions! We need to formally test for their inclusion. And that test involves the covariances between the coefficients in both models.

          Determining whether or not to include predictors in a multivariate multiple regression requires the use of multivariate test statistics. These are often taught in the context of MANOVA, or multivariate analysis of variance. Again the term “multivariate” here refers to multiple responses or dependent variables. This means we use modified hypothesis tests to determine whether a predictor contributes to a model.

          The easiest way to do this is to use the Anova() or Manova() functions in the car package (Fox and Weisberg, 2011), like so:

          The results are titled “Type II MANOVA Tests”. The Anova() function automatically detects that mlm1 is a multivariate multiple regression object. “Type II” refers to the type of sum-of-squares. This basically says that predictors are tested assuming all other predictors are already in the model. This is usually what we want. Notice that PR and DIAP appear to be jointly insignificant for the two models despite what we were led to believe by examining each model separately.

          Based on these results we may want to see if a model with just GEN and AMT fits as well as a model with all five predictors. One way we can do this is to fit a smaller model and then compare the smaller model to the larger model using the anova() function, (notice the little “a” this is different from the Anova() function in the car package). For example, below we create a new model using the update() function that only includes GEN and AMT. The expression “.

          . – PR – DIAP – QRS” says “keep the same responses and predictors except PR, DIAP and QRS.”

          The large p-value provides good evidence that the model with two predictors fits as well as the model with five predictors. Notice the test statistic is “Pillai”, which is one of the four common multivariate test statistics.

          The car package provides another way to conduct the same test using the linearHypothesis() function. The beauty of this function is that it allows us to run the test without fitting a separate model. It also returns all four multivariate test statistics. The first argument to the function is our model. The second argument is our null hypothesis. The linearHypothesis() function conveniently allows us to enter this hypothesis as character phrases. The null entered below is that the coefficients for PR, DIAP and QRS are all 0.

          The Pillai result is the same as we got using the anova() function above. The Wilks, Hotelling-Lawley, and Roy results are different versions of the same test. The consensus is that the coefficients for PR, DIAP and QRS do not seem to be statistically different from 0. There is some discrepancy in the test results. The Roy test in particular is significant, but this is likely due to the small sample size (n = 17).

          Also included in the output are two sum of squares and products matrices, one for the hypothesis and the other for the error. These matrices are used to calculate the four test statistics. These matrices are stored in the lh.out object as SSPH (hypothesis) and SSPE (error). We can use these to manually calculate the test statistics. For example, let SSPH = H and SSPE = E. The formula for the Wilks test statistic is

          In R we can calculate that as follows:

          Likewise the formula for Pillai is

          tr means trace. That’s the sum of the diagonal elements of a matrix. In R we can calculate as follows: