0

我想在 gnuplot 中显示一组观察结果以及它们的均值和协方差。有谁知道我怎么做这样的事情?是否有另一个程序可以很好地做到这一点?像 Octave 这样的程序能做到这一点吗?我看到了获取统计信息的方法,但我没有找到任何关于显示这些统计信息的信息。

为了澄清,我想显示数据点(2d 或 3d),显示它们在数据集中绘制的平均值,并显示一个表示协方差的椭圆。

4

2 回答 2

1

是的,你可以用 Octave 做到这一点。

## create 2x1000 matrix of random data with normal distribution
data = randn (1000, 2);

## plot data (the o is for dots)
plot (data(:,1), data(:,2), "o");

## get mean from each
mu   = mean (data);

## calculate covariance matrix
R    = cov (data);

## calculate the ellipse points
A     = chol (R, "lower");
theta = linspace (0, 2*pi, 1000);
x     = mu' + 2.5 .* A * [cos(theta); sin(theta)];

## plot the ellipse
hold on;
plot(x(1,:), x(2,:), "r", "LineWidth", 2);
于 2012-10-02T10:29:27.393 回答
0

我在 octave 4.0.2 中遇到了错误,并更改了 carandraug 对此的回答中的“x =”行:

x     = mu' + 2.5 .* A * [cos(theta); sin(theta)];
于 2016-05-27T16:16:29.267 回答