Shaked
Shaked

Reputation: 495

How To Fit Multivariate Normal Distribution To Data In MATLAB?

I'm trying to fit a multivariate normal distribution to data that I collected, in order to take samples from it. I know how to fit a (univariate) normal distribution, using the fitdist function (with the 'Normal' option).

How can I do something similar for a multivariate normal distribution?

Doesn't using fitdist on every dimension separately assumes the variables are uncorrelated?

Upvotes: 5

Views: 11857

Answers (3)

Shaheen G.
Shaheen G.

Reputation: 1

You can use [sigma,mu] = robustcov(X) function, where X is your multivariate data, i.e. X = [x1 x2 ... xn] and xi is a column vector data.

Then you can use Y = mvnpdf(X,mu,sigma) to get the values of the estimated normal probability density function.

https://www.mathworks.com/help/stats/normfit.html https://www.mathworks.com/help/stats/mvnpdf.html

Upvotes: 0

Fra_Ve
Fra_Ve

Reputation: 1210

Estimate the mean with mean and the variance-covariance matrix with cov. Then you can generate random numbers with mvnrnd. It is also possible to use fitmgdist, but for just a multivariate normal distribution mean and cov are enough.

Yes, using fitdist on every dimension separately assumes the variables are uncorrelated and it's not what you want.

Upvotes: 0

Robert Dodier
Robert Dodier

Reputation: 17576

There isn't any need for a specialized fitting function; the maximum likelihood estimates for the mean and variance of the distribution are just the sample mean and sample variance. I.e., compute the sample mean and sample variance and you're done.

Upvotes: 1

Related Questions