Get startedGet started for free

Calculating the density of multivariate normal

For many statistical tasks, like hypothesis testing, clustering, and likelihood calculation, you are required to calculate the density of a specified multivariate normal distribution. In this exercise, you will use the dmvnorm() function to calculate multivariate normal densities with specified mean and variance-covariance matrix at each of the observations from your previously generated sample multnorm.sample.

The mean and the variance-covariance matrix are preloaded for you as objects mu.sim and sigma.sim.

This exercise is part of the course

Multivariate Probability Distributions in R

View Course

Exercise instructions

  • Use dmvnorm() to calculate the density heights of the 100 samples in multnorm.sample for a bivariate normal.
  • Use scatterplot3d() to plot a 3D scatterplot of the density heights at each of the generated sample points.

Hands-on interactive exercise

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

# Calculate density
multnorm.dens <- dmvnorm(multnorm.sample, mean = ___, sigma = ___)

# Create scatter plot of density heights 
___(cbind(___),    
               color="blue", pch="", type = "h",             
                              xlab = "x", ylab = "y", zlab = "density")
Edit and Run Code