确定随机变量的概率质量函数
如果我们有一个离散随机变量 x 以及 X(n) 中与其相关的数据,那么在 matlab 中我们如何确定概率质量函数 pmf(X)?
If we have a discrete random variable x and the data pertaining to it in X(n), how in matlab can we determine the probability mass function pmf(X)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以通过至少八种不同的方式来做到这一点(其中一些已经在其他解决方案中提到过)。
假设我们有一个来自离散随机变量的样本:
考虑这些等效解决方案(请注意,我没有假设任何可能值的范围,只是它们是整数):
请注意,GRP2IDX 用于获取从 1 开始的对应索引到
pmf
的条目(映射由labels
给出)。上面的结果是:You can do this in at least eight different ways (some of them were already mentioned in the other solutions).
Say we have a sample from a discrete random variable:
Consider these equivalent solutions (note that I don't assume anything about the range of possible values, just that they are integers):
note that GRP2IDX was used to get indices starting at 1 corresponding to the entries of
pmf
(the mapping is given bylabels
). The result of the above is:以下摘自 MATLAB 文档 显示了如何绘制直方图。对于离散概率函数,频率分布可能与直方图相同。
计算每个 bin 中所有元素的总和。将所有 bin 除以总和即可得到 pdf。通过添加所有元素来测试您的 pdf。结果一定是一。
希望我的说法是正确的。已经很久了……
The following excerpt from the MATLAB documentation shows how to plot a histogram. For a discrete probability function, the frequency distribution might be identical with the histogram.
Calculate the sum of all the elements in every bin. Divide all bins by the sum to get your pdf. Test your pdf by adding up all elements. The result must be one.
Hope I'm right with my statements. It's a long time since ...
这个功能怎么样?
您认为这是正确的吗?
How about this function?
Is this correct in your opinion?
也许尝试只创建一个函数句柄,这样就不需要存储另一个数组:
Maybe try making just a function handle so you don't need to store another array:
要添加另一个选项(因为有许多函数可以完成您想要的操作),您可以使用函数 ACCUMARRAY 如果您的离散值是大于 0 的整数:
下面是一个示例:
To add yet another option (since there are a number of functions available to do what you want), you could easily compute the pmf using the function ACCUMARRAY if your discrete values are integers greater than 0:
Here's an example:
如果我理解正确的话,你需要做的是估计 pdf,除非它不是连续的而是离散的值。
计算 X(n) 中不同值的出现次数并除以 n。为了说明我所说的,请允许我举一个例子。假设您有 10 个观察值:
那么您的 pmf 将如下所示:
编辑: 这原则上是频率直方图,正如 @zellus 也指出的那样
If I understood correctly what you need to do is to estimate the pdf, except it is not continuous but discrete values.
Calculate the occurrences of different values in X(n) and divide by n. To illustrate what I am saying, please allow me to give an example. Assume that you have 10 observations:
then your pmf would look like this:
edit: this is in principle a frequency histogram, as @zellus has also pointed out