MATLAB Answers

Calculate Expected Value and Variance for Bivariate Normal Distribution

29 views (last 30 days)
I have a bivariate normal distribution wiyh 1000 samples whose mean is mu = [0, 1] and the covariance matrix is Σ=[1 0.7; 0.7 2]
I need to calculate expected value E[XY] and variance VAR[XY] for this distribution.
And I need to find the sample which represent the E[XY] and variance VAR[XY].
I would be appriciated if you help me :)
mu=[0 1];
cov=[1 0.7; 0.7 2];
rng('default');
R = mvnrnd(mu,cov,1000);
plot(R(:,1),R(:,2),'+');
y = mvnpdf(R,mu,cov);
scatter3(R(:,1),R(:,2),y,'filled')
hold on
axis([-4 4 -4 8 0 0.15])
xlabel('x1')
ylabel('x2')
zlabel('Probability Density')

  0 Comments

Sign in to comment.

Accepted Answer

Asvin Kumar
Asvin Kumar on 10 Apr 2020
To find the empirical estimate of variable XY, you can use the following command:
Exy = mean(prod(R,2));
To find the empirical variance of variable XY, you can use the following command:
VARxy = var(prod(R,2));
Your scatter plot merely samples the multivariate PDF of the specified mu and sigma values at the locations queried for. To visualize the multivariate histogram of your sample, try the following command:
hist3(R,nbins,[32 32]);
I’m not sure what you meant when you said you wanted to find the sample which is representative of E[XY] and Var(XY). I’m going to assume you wanted to find a sample which has its E[XY] and Var(XY) closest to the original. You could do that by two way:
  1. Increase your sample size. Try going up by an order of magnitude from 1000 to 10000. By the Law of Large Numbers your empirical estimates will be closer to the actual mu and sigma values.
  2. Randomly sample for 1000 points repeatedly. Calculate and store the empirical means and variances of product of the variables. Pick the one which represents the E[XY] and Var(XY) as you see fit. You can also save the state of the random number generator to recreate that sample. This article should help with that: https://www.mathworks.com/help/matlab/math/controlling-random-number-generation.html

  0 Comments

Sign in to comment.

More Answers (0)