Get startedGet started for free

Calculating dmvnorm over a grid

To visualize a bivariate normal density surface, one has to calculate the density over a dense grid of x and y coordinates, and use 3D surface plotting functions like persp() to visualize the surface.

The 40 by 40 dense grid generated from the command mvals <- expand.grid(seq(-5, 10, length.out = 40), seq(-8, 4, length.out = 40)) is preloaded for you.

This exercise is part of the course

Multivariate Probability Distributions in R

View Course

Exercise instructions

  • Calculate the densities of a normal with the mean mu.sim and variance-covariance matrix sigma.sim on the grid values in the object mvals.
  • Use the persp() plot function to visualize the density surface over the grid.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Calculate density over the specified grid
mvds <- ___
matrix_mvds <-  matrix(___, nrow = 40)

# Create a perspective plot
persp(___, theta = 80, phi = 30, expand = 0.6, shade = 0.2, col = "lightblue", xlab = "x", ylab = "y", zlab = "dens")
Edit and Run Code