I am trying to create a bivariate normal distribution of random numbers in Matlab that is symmetrical. I know the standard deviation of the gaussian (15 for example) and that it is the same in both directions. How do I use this standard deviation information to get the covariance in a form that Matlab will accept for the mvnrnd command? Thanks, I would really appreciate any advice.
我试图在Matlab中创建一个对称的随机数的双变量正态分布。我知道高斯的标准偏差(例如15),并且它在两个方向上都是相同的。如何使用此标准差信息以Matlab将接受mvnrnd命令的形式获得协方差?谢谢,我真的很感激任何建议。
3 个解决方案
#1
1
First of all, you need to know the correlation between the two normal variables. Like @Luis said, the diagonal will be 15 each but for the covariance, you need to know the correlation between both.
首先,您需要知道两个正常变量之间的相关性。就像@Luis所说的那样,对角线将是15,但对于协方差,你需要知道两者之间的相关性。
They are related by this equation:
它们与以下等式相关:
cov(x,y) = correlation(x,y)*std(x)*std(y)
But if you do not know the correlation, then you can calculate the sample covariance.
但如果您不知道相关性,则可以计算样本协方差。
Forumla for sample covariance:
Forumla样本协方差:
To calculate in Matlab:
要在Matlab中计算:
cov = (1/n)*(x-mean(x))*(y-mean(y))'
With reference to:http://www.cogsci.ucsd.edu/~desa/109/trieschmarksslides.pdf
参考:http://www.cogsci.ucsd.edu/~desa/109/trieschmarksslides.pdf
#2
1
If the random variables are independent, the off-diaginal elements of the covariance matrix are zero. So that matrix will be diag(std1,std2)
, where std1
and std2
are the standard deviations of your two variables. In your example you would use diag(15,15)
.
如果随机变量是独立的,则协方差矩阵的偏外元素为零。因此矩阵将是diag(std1,std2),其中std1和std2是两个变量的标准偏差。在你的例子中,你将使用diag(15,15)。
If the random variables are not independent, you need to specify all four elements of the covariance matrix.
如果随机变量不是独立的,则需要指定协方差矩阵的所有四个元素。
#3
0
You can use the command cov in Matlab:
您可以在Matlab中使用命令cov:
SIGMA = cov([x y]);
HTH
HTH
#1
1
First of all, you need to know the correlation between the two normal variables. Like @Luis said, the diagonal will be 15 each but for the covariance, you need to know the correlation between both.
首先,您需要知道两个正常变量之间的相关性。就像@Luis所说的那样,对角线将是15,但对于协方差,你需要知道两者之间的相关性。
They are related by this equation:
它们与以下等式相关:
cov(x,y) = correlation(x,y)*std(x)*std(y)
But if you do not know the correlation, then you can calculate the sample covariance.
但如果您不知道相关性,则可以计算样本协方差。
Forumla for sample covariance:
Forumla样本协方差:
To calculate in Matlab:
要在Matlab中计算:
cov = (1/n)*(x-mean(x))*(y-mean(y))'
With reference to:http://www.cogsci.ucsd.edu/~desa/109/trieschmarksslides.pdf
参考:http://www.cogsci.ucsd.edu/~desa/109/trieschmarksslides.pdf
#2
1
If the random variables are independent, the off-diaginal elements of the covariance matrix are zero. So that matrix will be diag(std1,std2)
, where std1
and std2
are the standard deviations of your two variables. In your example you would use diag(15,15)
.
如果随机变量是独立的,则协方差矩阵的偏外元素为零。因此矩阵将是diag(std1,std2),其中std1和std2是两个变量的标准偏差。在你的例子中,你将使用diag(15,15)。
If the random variables are not independent, you need to specify all four elements of the covariance matrix.
如果随机变量不是独立的,则需要指定协方差矩阵的所有四个元素。
#3
0
You can use the command cov in Matlab:
您可以在Matlab中使用命令cov:
SIGMA = cov([x y]);
HTH
HTH