1. Density and cumulative density for multivariate-t
To calculate the density, cdf, and inverse cdf of a multivariate t-distribution, we will use the dmvt(), pmvt(), and qmvt() functions from the mvtnorm library.
2. Example of multivariate t-distribution
In the financial market, due to the volatility of stock prices, individual stocks are often modeled by a univariate t-distribution.
If you have a portfolio containing three stocks, you will now need to model them with a multivariate t-distribution.
If you want to find the probability that all three stocks are valued between 100 and 150 dollars, you can simply use the pmvt() function with a lower limit of 100 and an upper limit of 150, for each of the three stocks.
If, instead, you are interested in finding out the range of values these stocks fluctuate between 95 percent of the time, you can simply calculate the 0.95 quantile using the inverse cdf function, qmvt().
3. Density using dmvt
We start with the density calculation, using the dmvt() function. The first argument is the location x, and the second and the third arguments, delta and sigma, specify the non-centrality location parameter and the variance-covariance matrix. Unlike the dmvnorm() function, the dmvt() function calculates the density in log scale by default. Use the argument log equals FALSE to calculate the densities on a natural scale.
4. Calculating the density of a multivariate t-distribution on a grid
Here is the code to calculate the multivariate t-distribution density across a grid of values ranging from -3 to 6 in the x and y direction. We first create the grid, similar to the normal perspective plot example. Then we use the dmvt() function with the grid values as the first argument and the delta, sigma, and df parameters.
Finally, we use the scatterplot3d() function to plot the density heights at each grid point by specifying the matrix of three columns as the first argument. The first two columns contain the location and the last column contains the density heights.
5. Effect of changing the degrees of freedom
This animation is generated by cycling through the df argument from 1 to 30 and shows how the density heights change as the value of the degrees of freedom changes. As the degrees of freedom decrease, the vertical bars in the middle decrease in height, while the bars farther away from the center increase. This is because lower degrees of freedom implies fatter tails, which implies a larger proportion of extreme observations, with a flatter center.
6. Cumulative density using pmvt
Like the pmvnorm() function, pmvt() calculates the probability between the lower and upper limits.
To calculate the probability of x lying between -1 and 2, and y lying between -2 and 2 for a t-distribution with 6 degrees of freedom and noncentrality parameter given by the vector 1 2, we need to specify the arguments lower, upper, delta, sigma, and df. The value 0 point 3857 represents the probability of any observation from the specified multivariate-t distribution lying within the given ranges of x and y.
Similar to the pmvnorm() function, this integration is also done numerically, and the error precision and completion messages are provided.
7. Inverse cdf of t-distribution
To calculate the inverse cdf or quantile of a t-distribution we use the qmvt() function. In this example, we exclude the delta argument, since it takes the default value of zeroes, and specify sigma as a 2 by 2 diagonal matrix.
As with the qmvnorm() function, we need to specify the arguments p, sigma, and tail. For the qmvt() function, we also need to specify the df argument. For three degrees of freedom, the resulting quantile for the bivariate-t is a circle with a radius of 3 point 96.
8. Let's put these functions into practice!
Now let's use these three functions.