Determining probability mass function of random variable

后端 未结 6 767
一整个雨季
一整个雨季 2021-01-13 04:01

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)?

6条回答
  •  难免孤独
    2021-01-13 04:46

    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:

    pmf = accumarray(X(:),1)./numel(X);
    

    Here's an example:

    >> X = [1 1 1 1 2 2 2 3 3 4];          %# A sample distribution of values
    >> pmf = accumarray(X(:),1)./numel(X)  %# Compute the probability mass function
    
    pmf =
    
        0.4000      %# 1 occurs 40% of the time
        0.3000      %# 2 occurs 30% of the time
        0.2000      %# 3 occurs 20% of the time
        0.1000      %# 4 occurs 10% of the time
    

提交回复
热议问题