在对数域中绘制负值的误差条 (Matlab)

发布于 2024-10-06 17:30:56 字数 353 浏览 0 评论 0原文

我有一个向量,称之为 x,其中包含我根据平均值计算得出的非常小的数字。我想绘制 x 的对数变换,例如 y=10*log10(x),以及在查找平均值时计算出的等于 +- 2 个标准差的误差条。

为此,我使用以下代码:

figure
errorbar(lengths, 10*log10(x), ...
    10*log10(x-2*std_x), 10*log10(x+2*std_x), 'o')

我的问题是,由于 x 包含如此小的值,x-2*std_x 通常是负数,并且您不能取负数的对数。

所以我想我的问题是,当减去线性域中的标准差得到负数时,如何在对数域中绘制误差线?我不能做 +-

I have a vector, call it x, which contains very small numbers that I calculated from a mean. I'd like to plot the logarithmic transform of x, say y=10*log10(x), along with errorbars equal to +- 2 standard deviations calculated when finding the mean.

To do this, I'm using the following code:

figure
errorbar(lengths, 10*log10(x), ...
    10*log10(x-2*std_x), 10*log10(x+2*std_x), 'o')

My problem is that since x contains such small values, x-2*std_x is usually a negative number, and you can't take the log of negative numbers.

So I suppose my question is how can I plot errorbars in the logarithmic domain when subtracting the standard deviation in the linear domain gives me negative numbers? I can't do the +-

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情深缘浅 2024-10-13 17:30:56

实际上,您调用 errorbar 是错误的。您应该调用

figure
errorbar(lengths, 10*log10(x),10*log10(2*std_x), 'o')

如果std_x太小而无法工作,您可以通过从10*log10(x-2)绘制垂直线来编写自己的errorbar版本*std_x)10*log10(x+2*std_x)

Actually you're calling errorbar wrong. You should call

figure
errorbar(lengths, 10*log10(x),10*log10(2*std_x), 'o')

If std_x is too small for this to work, you can write your own version of errorbar by plotting vertical lines from 10*log10(x-2*std_x) to 10*log10(x+2*std_x)

悲欢浪云 2024-10-13 17:30:56

在两个错误配置中使用 errorbar,然后将 y 轴更改为对数:

eps = 1E-4;  %whatever you consider to be a very small fraction
ebl = min(2*std_x, x*(1-eps));
ebu = 2*std_x;
errorbar(lengths, x, ebl, ebu, 'o');
set(gca, 'YScale', 'log');

您可能需要使用 ylim 手动调整 y 轴范围

use errorbar in the two error configuration, then change the y-axis to be logarithmic:

eps = 1E-4;  %whatever you consider to be a very small fraction
ebl = min(2*std_x, x*(1-eps));
ebu = 2*std_x;
errorbar(lengths, x, ebl, ebu, 'o');
set(gca, 'YScale', 'log');

you may want to adjust your yaxis range manually using ylim

多情癖 2024-10-13 17:30:56

您可以用一个较小但可记录的值替换这些值(例如,低 40 dB):

minb = x-2*std_x;
mask = (minb <= 0);
minb(mask) = x/1e4;
... use 10*log10(minb) instead

或者只是阈值到某个最小值:

K = min(x) / 1e4; % so that K is 40 db below the smallest x
... use 10*log10(max(K, x-2*std_x)) instead.

或者类似的东西。

编辑总结评论和进一步的想法:

人们可能应该考虑为什么有误差线。通常,误差线倾向于指示某种置信度/概率的度量(例如,x% 的时间,该值位于指示的界限之间)。在这种情况下,如果对某个量取一些对数,则该量很可能是从非负分布中得出的。在这种情况下,使用非平均值 +/- K * std_deviation 的边界来指示边界可能更正确。

假设具有 cdf F(x) 的单峰分布,“适当”边界(即对于给定概率而言最小)可能是这样的:

F'(x1) = F'(x2), F(x2) - F(x1 )=desired_probability,并且x1<=众数<=x2。

这是对称分布的平均值 +/- K std_deviation,但如上所述,严格的正分布可能需要不同的处理。

You can replace those values with a small value but log-able (say, 40 dB lower):

minb = x-2*std_x;
mask = (minb <= 0);
minb(mask) = x/1e4;
... use 10*log10(minb) instead

Or just threshold to some minimum:

K = min(x) / 1e4; % so that K is 40 db below the smallest x
... use 10*log10(max(K, x-2*std_x)) instead.

Or similar stuff.

EDIT to summarize comments and further thoughts:

One should probably think about why have error bars. Normally error bars tend to indicate some measure of confidence / probability (e.g. x% of the time, the value is between the indicated bounds). In this case, where some logarithm is taken of a quantity, it is likely that the quantity is drawn from a non-negative distribution. In that case, it is probably more correct to use bounds that are not mean +/- K * std_deviation to indicate bounds.

Assuming a unimodal distribution with cdf F(x), the "proper" bounds (i.e. smallest, for a given probability) would probably be such that

F'(x1) = F'(x2), F(x2) - F(x1) = desired_probability, and x1 <= mode <= x2.

This is mean +/- K std_deviation for a symmetric distribution, but as mentioned, a strictly positive distribution probably requires a different treatment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文