0

I have a set of independent binary random variables (say A,B,C) which take a positive value with some probability and zero otherwise, for which I have generated a matrix of 0s and 1s of all possible combinations of these variables with at least a 1 i.e.

A B C
1 0 0
0 1 0
0 0 1
1 1 0 

etc.

I know the values and probabilities of A,B,C so I can calculate E(X) and E(X^2) for each. I want to treat each combination in the above matrix as a new random variable equal to the product of the random variables which are present in that combination (show a 1 in the matrix). For example, random variable Row4 = A*B.

I have created a matrix of the same size to the above, which shows the relevant E(X)s instead of the 1s, and 1s instead of the 0s. This allows me to easily calculate the vector of Expected values of the new random variables (one per combination) as the product of each row. I have also generated a similar matrix which shows E(X^2) instead of E(X), and another one which shows prob(X>0) instead of E(X).

I'm looking for a Matlab script that computes the Covariance matrix of these new variables i.e. taking each row as a random variable. I presume it will have to use the formula:

Cov(X,Y)=E(XY)-E(X)E(Y) 

For example, for rows (1 1 0) and (1 0 1):

Cov(X,Y)=E[(AB)(AC)]-E(X)E(Y)
        =E[(A^2)BC]-E(X)E(Y)
        =E(A^2)E(B)E(C)-E(X)E(Y)

These values I already have from the matrices I've mentioned above. For each Covariance, I'm just unsure how to know which two variables appear in both rows, because for those I will have to select E(X^2) instead of E(X).

Alternatively, the above can be written as:

Cov(X,Y)=E(X)E(Y)*[1/prob(A>0)-1]

But the problem remains as the probabilities in the denominator will only be the ones of the variables which are shared between two combinations.

Any advice on how automate the computation of the Covariance matrix in Matlab would be greatly appreciated.

rock3000
  • 11
  • 1

1 Answers1

0

I'm pretty sure this is not the most efficient way to do that but that's a start:

Assume r1...n the combinations of the random variables, R is the matrix:

    A  B  C
r1  1  0  0
r2  0  1  0
r3  0  0  1 
r4  1  1  0

If you have the vector E1, E2 and ER as:

E1 = [E(A)  E(B)  E(C)  ...]
E2 = [E(A²) E(B²) E(C²) ...]
ER = [E(r1) E(r2) E(r3) ...]

If you want to compute E(r1,r2) you can:

1) Extract the R1 and R2 columns from R

v1 = R(1,:)
v2 = R(2,:)

2) Sum both vectors in vs

vs = v1 + v2

3) Loop in vs, if you see a 2 that means the value in R2 has to be used, if you see a 1 it is the value in R1, if it is 0 do not use the value.

4) Using the loop, compute your E(r1,r2) as wanted.

AdrienNK
  • 850
  • 8
  • 19