Is there a matlab function that calculates joint probability for more than 2 random variables ("histc" for more than 3 rvs)?

24 views (last 30 days)
Hi I would like to ask if there is a function that works like 'histc' for as much as 10 random variables. For short illustration:
if there are 3 random variables with 2 states each. The various combinations of the 3 random variables would give 2*2*2=8 states. And the function would return the counts (obversations) for a given dataset of the the 3 rvs, very much like the 'histc' function.
Does matlab have a built in function like that or is there a not too complicated way of calculating it?
Thanks a bunch

Accepted Answer

Jonathan LeSage
Jonathan LeSage on 16 Oct 2013
Edited: Jonathan LeSage on 16 Oct 2013
If you are dealing with discrete random variables, you really only need to use the accumarray function.
Here is an example for three random variables with two possible states:
% Generate three discrete random variables (uncorrelated)
numRealizations = 100;
numStates = 2;
x = randi(numStates,numRealizations,1);
y = randi(numStates,numRealizations,1);
z = randi(numStates,numRealizations,1);
% Count the number of (x,y,z) values in each possible state
rvCount = accumarray([x y z],1);
To include additional random variables, you can just append more values to the matrix input to accumarray ([x y z t], etc.). Counting the values shouldn't be too much of a problem, however, visualization is another problem entirely!
Hope this helps to get you started and good luck!
  3 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!