我有一个矩阵,它在 Matlab 中为我提供了一个二维离散分布 (N²->R)。
Matlab(R2011b,带有统计工具箱)中是否有提供中心矩和均值的内置函数?如果它们存在于 (R²->R) 的函数中,那也很好。否则我将不得不自己建造它们,但我不想重新发明轮子。
谢谢
我有一个矩阵,它在 Matlab 中为我提供了一个二维离散分布 (N²->R)。
Matlab(R2011b,带有统计工具箱)中是否有提供中心矩和均值的内置函数?如果它们存在于 (R²->R) 的函数中,那也很好。否则我将不得不自己建造它们,但我不想重新发明轮子。
谢谢
A quick look and I couldn't turn up any functions, though this isn't a fact by any means.
However, working it out from scratch, and assuming you mean a matrix such as:
% x=1 x=2 x=3
P = [ 0.1 0.2 0.1 % y = 1
0.1 0.1 0.2 % y = 2
0.0 0.0 0.2 ] % y = 3
And you mean that this describes the joint discrete distribution (joint probability mass function). That is, the entry at (X,Y)
contains the probability of (X,Y)
occurring.
I'm also assuming by your use of N
in mathematical notation means the natural numbers. If so, then you can use the following code.
Mean:
meanX = sum(P,1) * (1:size(P,2))';
meanY = sum(P,2)' * (1:size(P,1))';
For the central moment K,L
(K
correspnding to X
and L
corresponding to Y
):
[X,Y] = meshgrid(1:size(P,2),1:size(P,1));
integrandXY_KL = (X - meanX).^K .* (Y-meanY).^L .* P;
momentXY_KL = sum(integrandXY_KL(:));
And you can generalize it further if the values of X are arbitrary (and not just natural numbers) as follows. If Xvals = [ 1 2 4 ]
and Yvals = [ 4 5 6 ]
. All of the above still works, you just replace all occurences of 1:size(P,2)
with Xvals
and all occurences of 1:size(P,1)
with Yvals
.