e-Statistics > 4470-5470 Probability and Statistics I

Drawing bivariate densities

Maxima has a powerful graphics function draw3d. In order to use it we must first load the "draw" package.
--> load(draw)
In a 3D plot a function is described in the format

$\displaystyle \texttt{explicit}(f(x,y),x,x_{min},x_{max},y,y_{min},y_{max})

with the plotting range $ [x_{min},x_{max}]$ and $ [y_{min},y_{max}]$.

In Maxima a function can be defined and works as a macro definition. For example, we can define

$\displaystyle Q(x,y) = \frac{1}{1-\rho^2}
- 2\rho\frac{(x-\mu_x)(y-\mu_y)}{\sigma_x\sigma_y}\right]

by setting it with the symbol ":="
--> Q(x,y) := ((x - m[1])^2/s[1]^2 + (y - m[2])^2/s[2]^2 - 2*r*(x - m[1])*(y - m[2])/(s[1]*s[2]))
Also, we have to give the parameters $ (\mu_x, \mu_y, \sigma_x, \sigma_y, \rho)$ as follows:
--> m: [1,2]
--> s: [2,1]
--> r: 0.3
Then we can define the bivariate density function by
--> f(x,y) := exp(-Q(x,y)/2)/(2*%pi*s[1]*s[2]*sqrt(1-r^2))

We can draw a surface when "enhanced3d=true" is specified.

--> draw3d(enhanced3d=true,
       user_preamble="unset colorbox")
We can obtain contour curves when "contour=map" is specified.
--> draw3d(color=red, contour=map, contour_levels=15,
       user_preamble="unset clabel")
We can draw both the surface and the contour curves when "contour=both" is specified.
--> draw3d(surface_hide=true, contour=both, contour_levels=15,

The option "contour_levels" can be chosen from the following styles.

The following wxm file contains the above code:


© TTU Mathematics