346

December 15, 2016, at 12:44 PM

I am trying to evaluate the density of multivariate t distribution of a 13-d vector. Using the dmvt function from the mvtnorm package in R, the result I get is

```
[1] 1.009831e-13
```

When i tried to write the function by myself in Python (thanks to the suggestions in this post: multivariate student t-distribution with python), I realized that the gamma function was taking very high values (given the fact that I have n=7512 observations), making my function going out of range.

I tried to modify the algorithm, using the math.lgamma() and np.linalg.slogdet() functions to transform it to the log scale, but the result I got was

```
8.97669876e-15
```

This is the function that I used in python is the following:

```
def dmvt(x,mu,Sigma,df,d):
'''
Multivariate t-student density:
output:
the density of the given element
input:
x = parameter (d dimensional numpy array or scalar)
mu = mean (d dimensional numpy array or scalar)
Sigma = scale matrix (dxd numpy array)
df = degrees of freedom
d: dimension
'''
Num = math.lgamma( 1. *(d+df)/2 ) - math.lgamma( 1.*df/2 )
(sign, logdet) = np.linalg.slogdet(Sigma)
Denom =1/2*logdet + d/2*( np.log(pi)+np.log(df) ) + 1.*( (d+df)/2 )*np.log(1 + (1./df)*np.dot(np.dot((x - mu),np.linalg.inv(Sigma)), (x - mu)))
d = 1. * (Num - Denom)
return np.exp(d)
```

Any ideas why this functions does not produce the same results as the R equivalent?

Using as `x = (0,0)`

produces similar results (up to a point, die to rounding) but with `x = (1,1)`

1 I get a significant difference!

POPULAR ONLINE

- search for elements in a list 107655 visits
- typescript: tsc is not recognized as an internal or external command, operable program or batch file 98236 visits
- In Chrome 55, prevent showing Download button for HTML 5 video 94209 visits
- RxJS5 - error - TypeError: You provided an invalid object where a stream was expected 91584 visits
- Ionic 2 - how to make ion-button with icon and text on two lines? 88283 visits
- NetBeans IDE - ClassNotFoundException: net.ucanaccess.jdbc.UcanaccessDriver 56959 visits
- Adding methods to es6 child class 20182 visits

READ ALSO

Given a pandas dataframe in the following format:

I found come old TCP reverse shell made in python online and im editing it to fix it up, when it prints the output of the command it doesnt print it all if the command is too bigThis is the code for sending the commands and then printing the output

I'm following a turtorial on LDA and encountering a problem since the turtorial is made in python 3 and I'm working in 27 (the turtorial claims to work in both)