Problems with Matlab Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you Matlab Codes for Registered Members of this site only, at free service...Follow Me.

Function of Random Vectors

Summary: For a pair {X, Y} having joint distribution on the plane, the approach is analogous to the single variable case. To find the probability an absolutely continuous pair takes on values in a set Q on the plane, integrate the joint density over the set. In the discrete case, identify those pairs of values which meet the defining conditions for Q and add the associated probabilities. To find the probability that g(X, Y ) takes on a a value in set M, determine the set Q of those pairs (t, u) mapped into M by the function g and then determine, as in the previous case, the probability the pair {X, Y} takes on values in Q.





Introduction
The general mapping approach for a single random variable and the discrete alternative extends to functions of more than one variable. It is convenient to consider the case of two random variables, considered jointly. Extensions to more than two random variables are made similarly, although the details are more complicated.

The general approach extended to a pair

Consider a pair {X,Y{ having joint distribution on the plane. The approach is analogous to that for a single random variable with distribution on the line.
  1. To find P((X,Y)Q).
    1. Mapping approach. Simply find the amount of probability mass mapped into the set Q on the plane by the random vector W=(X,Y).
      • In the absolutely continuous case, calculate QfXY.
      • In the discrete case, identify those vector values (ti,uj) of (X,Y) which are in the set Q and add the associated probabilities.
    2. Discrete alternative. Consider each vector value (ti,uj) of (X,Y). Select those which meet the defining conditions for Q and add the associated probabilities. This is the approach we use in the MATLAB calculations. It does not require that we describe geometrically the region Q.
  2. To find P(g(X,Y)M)g is real valued and M is a subset the real line.
    1. Mapping approach. Determine the set Q of all those (t,u) which are mapped into M by the function g. Now
      W(ω)=(X(ω),Y(ω))Qiffg((X(ω),Y(ω))MHence(1)
      {ω:g(X(ω),Y(ω))M{={ω:(X(ω),Y(ω))Q{(2)
      Since these are the same event, they must have the same probability. Once Q is identified on the plane, determine P((X,Y)Q) in the usual manner (see part a, above).
    2. Discrete alternative. For each possible vector value (ti,uj) of (X,Y), determine whether g(ti,uj) meets the defining condition for M. Select those (ti,uj) which do and add the associated probabilities.
We illustrate the mapping approach in the absolutely continuous case. A key element in the approach is finding the set Q on the plane such that g(X,Y)M iff (X,Y)Q. The desired probability is obtained by integrating fXY over Q.
Figure 1: Distribution for Example 1.
A graph with a Diagonal line from points (0,0) to (2,2). Another line extends from (2,0) to (2,2) creating a triangle with the diagonal line. This line is labeled t=2 and this triangle is shaded. There is one more line originating at (0,1) and ending at (1,1). This line is labeled u=1. The diagonal line is labeled u=t. Below this graph is the equation f_XY(t,u)=(6/37)(t+2u).

EXAMPLE 1: A numerical example

The pair {X,Y{ has joint density fXY(t,u)=
6
37
 (t+2u) on the region bounded by t=0t=2u=0u=max{1,t{ (see Figure 1). Determine P(YX)=P(XY0). Here g(t,u)=tu andM=[0,). Now Q={(t,u):tu0{={(t,u):ut{ which is the region on the plane on or below the line u=t. Examination of the figure shows that for this region, fXY is different from zero on the triangle bounded by t=2u=0, and u=t. The desired probability is
P(YX)=020t
6
37
 (t+2u)dudt=32/370.8649
(3)

EXAMPLE 2: The density for the sum X+Y

Suppose the pair {X,Y{ has joint density fXY. Determine the density for
Z=X+Y(4)
SOLUTION
FZ(v)=P(X+Yv)=P((X,Y)Qv)whereQv={(t,u):t+uv{={(t,u):uvt{(5)
For any fixed v, the region Qv is the portion of the plane on or below the line u=vt (see Figure 2). Thus
FZ(v)=QvfXY=vtfXY(t,u)dudt(6)
Differentiating with the aid of the fundamental theorem of calculus, we get
fZ(v)=fXY(t,vt)dt(7)
This integral expresssion is known as a convolution integral.
Figure 2: Region Qv for X+Yv.
A graph of the equation Q_V{(t,u):u<=v-t}. A line ascends to the upper left intersecting the x and y axes. The area to the left of this line is shaded and the area contained on the positive side of the graph is labeled Q_V the point at which the diagonal line intersects the y axis is labeled (0,V) and where the line intersects the x axis the line is labeled (V,0). The diagonal line is labeled u=v-t

EXAMPLE 3: Sum of joint uniform random variables

Suppose the pair {X,Y{ has joint uniform density on the unit square 0t10u1. Determine the density for Z=X+Y.
SOLUTION
FZ(v) is the probability in the region Qv:uvt. Now PXY(Qv)=1PXY(Qvc), where the complementary set Qvc is the set of points above the line. As Figure 3 shows, for v1, the part of Qv which has probability mass is the lower shaded triangular region on the figure, which has area (and hence probability) v2/2. For v>1, the complementary region Qvc is the upper shaded region. It has area (2v)2/2. so that in this case,
PXY(Qv)=1(2v)2/2. Thus,
FZ(v)=
v2
2
 for0v1andFZ(v)=1
(2v)2
2
 for1v2
(8)
Differentiation shows that Z has the symmetric triangular distribution on [0,2], since
fZ(v)=vfor0v1andfZ(v)=(2v)for1v2(9)
With the use of indicator functions, these may be combined into a single expression
fZ(v)=I[0,1](v)v+I(1,2](v)(2v)(10)
Figure 3: Geometry for sum of joint uniform random variables.
This ia graph of the equation u=v-1, for v<=1. The x-axis is labeled t and the y-axis is labeled u. A square is formed by a line ascending from the x-axis and a line originating at the y-axis. There are two parallel line that proceed up and to the left intersecting the x and y axes for the bottom line and the two lines originating at either of the axes. These two parallel lines create two triangles. The bottom triangle contains Q_V with each one of the sides of the right angle being labeled V. The upper triangle contains Q_V^C with each of the sides of the right angle labeled 2-v and the long side being labeled u=v-t, for v > 1
ALTERNATE SOLUTION
Since fXY(t,u)=I[0,1](t)I[0,1](u), we have fXY(t,vt)=I[0,1](t)I[0,1](vt). Now 0vt1 iff v1tv, so that
fXY(t,vt)=I[0,1](v)I[0,v](t)+I(1,2](v)I[v1,1](t)(11)
Integration with respect to t gives the result above.
Independence of functions of independent random variables
Suppose {X,Y{ is an independent pair. Let Z=g(X),W=h(Y). Since
Z1(M)=X1[g1(M)]andW1(N)=Y1[h1(N)(12)
the pair {Z1(M),W1(N){ is independent for each pair {M,N{. Thus, the pair {Z,W{ is independent.
If {X,Y{ is an independent pair and Z=g(X),W=h(Y), then the pair {Z,W{ is independent. However, if Z=g(X,Y) and W=h(X,Y), then in general {Z,W{ is not independent. This is illustrated for simple random variables with the aid of the m-procedure jointzw at the end of the next section.

EXAMPLE 4: Independence of simple approximations to an independent pair

Suppose {X,Y{ is an independent pair with simple approximations Xs and Ys as described in Distribution Approximations.
Xs=
n
i=1
 tiIEi=
n
i=1
 tiIMi(X)andYs=
m
j=1
 ujIFj=
m
j=1
 ujINj(Y)
(13)
As functions of X and Y, respectively, the pair {Xs,Ys{ is independent. Also each pair {IMi(X),INj(Y){ is independent.

Use of MATLAB on pairs of simple random variables

In the single-variable case, we use array operations on the values of X to determine a matrix of values of g(X). In the two-variable case, we must use array operations on the calculating matrices t and u to obtain a matrix G whose elements are g(ti,uj). To obtain the distribution for Z=g(X,Y), we may use the m-function csort on G and the joint probability matrix P. A first step, then, is the use of jcalc or icalc to set up the joint distribution and the calculating matrices. This is illustrated in the following example.

EXAMPLE 5

% file jdemo3.m
% data for joint simple distribution
X = [-4 -2 0 1 3];
Y = [0 1 2 4];
P = [0.0132    0.0198    0.0297    0.0209    0.0264;
     0.0372    0.0558    0.0837    0.0589    0.0744;
     0.0516    0.0774    0.1161    0.0817    0.1032;
     0.0180    0.0270    0.0405    0.0285    0.0360];
jdemo3                % Call for data
jcalc                 % Set up of calculating matrices t, u.
Enter JOINT PROBABILITIES (as on the plane)  P
Enter row matrix of VALUES of X  X
Enter row matrix of VALUES of Y  Y
 Use array operations on matrices X, Y, PX, PY, t, u, and P
G = t.^2 -3*u;        % Formation of G = [g(ti,uj)]
M = G >= 1;           % Calculation using the XY distribution
PM = total(M.*P)      % Alternately, use total((G>=1).*P)
PM =  0.4665
[Z,PZ] = csort(G,P);
PM = (Z>=1)*PZ'     % Calculation using the Z distribution
PM =  0.4665
disp([Z;PZ]')         % Display of the Z distribution
  -12.0000    0.0297
  -11.0000    0.0209
   -8.0000    0.0198
   -6.0000    0.0837
   -5.0000    0.0589
   -3.0000    0.1425
   -2.0000    0.1375
         0    0.0405
    1.0000    0.1059
    3.0000    0.0744
    4.0000    0.0402
    6.0000    0.1032
    9.0000    0.0360
   10.0000    0.0372
   13.0000    0.0516
   16.0000    0.0180
We extend the example above by considering a function W=h(X,Y) which has a composite definition.

EXAMPLE 6: Continuation of Example 5

Let
W={
XforX+Y1
X2+Y2forX+Y<1
DeterminethedistributionforW
(14)
H = t.*(t+u>=1) + (t.^2 + u.^2).*(t+u<1);  % Specification of h(t,u)
 
 
 
[W,PW] = csort(H,P);                       % Distribution for W = h(X,Y)
disp([W;PW]')
   -2.0000    0.0198
         0    0.2700
    1.0000    0.1900
    3.0000    0.2400
    4.0000    0.0270
    5.0000    0.0774
    8.0000    0.0558
   16.0000    0.0180
   17.0000    0.0516
   20.0000    0.0372
   32.0000    0.0132
ddbn                                        % Plot of distribution function
Enter row matrix of values  W
Enter row matrix of probabilities  PW
print                                       % See Figure 4
Figure 4: Distribution for random variable W in Example 6.
A graph of distribution function for random variable W. This graph is a series of plotted points with lines drawn between them. The line goes up and to the right.
Joint distributions for two functions of (X,Y)
In previous treatments, we use csort to obtain the marginal distribution for a single function Z=g(X,Y). It is often desirable to have the joint distribution for a pair Z=g(X,Y) andW=h(X,Y). As special cases, we may have Z=X or W=Y. Suppose
Zhasvalues[z1z2zc]andWhasvalues[w1w2wr](15)
The joint distribution requires the probability of each pair, P(W=wi,Z=zj). Each such pair of values corresponds to a set of pairs of X and Y values. To determine the joint probability matrixPZW for (Z,W) arranged as on the plane, we assign to each position (i,j) the probability P(W=wi,Z=zj), with values of W increasing upward. Each pair of (W,Z) values corresponds to one or more pairs of (Y,X) values. If we select and add the probabilities corresponding to the latter pairs, we have P(W=wi,Z=zj). This may be accomplished as follows:
  1. Set up calculation matrices t and u as with jcalc.
  2. Use array arithmetic to determine the matrices of values G=[g(t,u)] and H=[h(t,u)].
  3. Use csort to determine the Z and W value matrices and the PZ and PW marginal probability matrices.
  4. For each pair (wi,zj), use the MATLAB function find to determine the positions a for which
    (H==W(i))&(G==Z(j))(16)
  5. Assign to the (i,j) position in the joint probability matrix PZW for (Z,W) the probability
    PZW(i,j)=total(P(a))(17)
We first examine the basic calculations, which are then implemented in the m-procedure jointzw.

EXAMPLE 7: Illustration of the basic joint calculations

% file jdemo7.m
P = [0.061  0.030  0.060  0.027  0.009;
       0.015  0.001  0.048  0.058  0.013;
       0.040  0.054  0.012  0.004  0.013;
       0.032  0.029  0.026  0.023  0.039;
       0.058  0.040  0.061  0.053  0.018;
       0.050  0.052  0.060  0.001  0.013];
X = -2:2;
Y = -2:3;
jdemo7                      % Call for data in jdemo7.m
jcalc                       % Used to set up calculation matrices t, u
- - - - - - - - - -
H = u.^2                    % Matrix of values for W = h(X,Y)
H =
     9     9     9     9     9
     4     4     4     4     4
     1     1     1     1     1
     0     0     0     0     0
     1     1     1     1     1
     4     4     4     4     4
G = abs(t)                  % Matrix of values for Z = g(X,Y)
 
G =
     2     1     0     1     2
     2     1     0     1     2
     2     1     0     1     2
     2     1     0     1     2
     2     1     0     1     2
     2     1     0     1     2
[W,PW] = csort(H,P)         % Determination of marginal for W
W =     0     1     4     9
PW =    0.1490    0.3530    0.3110    0.1870
[Z,PZ] = csort(G,P)         % Determination of marginal for Z
Z =     0     1     2
PZ =    0.2670    0.3720    0.3610
r = W(3)                    % Third value for W
r =   4
s = Z(2)                    % Second value for Z
s =   1
To determine P(W=4,Z=1), we need to determine the (t,u) positions for which this pair of (W,Z) values is taken on. By inspection, we find these to be (2,2), (6,2), (2,4), and (6,4). Then P(W=4,Z=1) is the total probability at these positions. This is 0.001 + 0.052 + 0.058 + 0.001 = 0.112. We put this probability in the joint probability matrix PZW at the W=4,Z=1 position. This may be achieved by MATLAB with the following operations.
[i,j] = find((H==W(3))&(G==Z(2)));  % Location of (t,u) positions
disp([i j])                         % Optional display of positions
     2     2
     6     2
     2     4
     6     4
a = find((H==W(3))&(G==Z(2)));      % Location in more convenient form
P0 = zeros(size(P));                % Setup of zero matrix
P0(a) = P(a)                        % Display of designated probabilities in P
P0 =
         0         0         0         0         0
         0    0.0010         0    0.0580         0
         0         0         0         0         0
         0         0         0         0         0
         0         0         0         0         0
         0    0.0520         0    0.0010         0
PZW = zeros(length(W),length(Z))    % Initialization of PZW matrix
PZW(3,2) = total(P(a))              % Assignment to PZW matrix with
PZW =    0         0         0      % W increasing downward
         0         0         0
         0    0.1120         0
         0         0         0
PZW = flipud(PZW)                   % Assignment with W increasing upward
PZW =
         0         0         0
         0    0.1120         0
         0         0         0
         0         0         0
The procedure jointzw carries out this operation for each possible pair of W and Z values (with the flipud operation coming only after all individual assignments are made).

EXAMPLE 8: Joint distribution for Z=g(X,Y)=||X|Y| and W=h(X,Y)=|XY|

% file jdemo3.m   data for joint simple distribution
X = [-4 -2 0 1 3];
Y = [0 1 2 4];
P = [0.0132    0.0198    0.0297    0.0209    0.0264;
     0.0372    0.0558    0.0837    0.0589    0.0744;
     0.0516    0.0774    0.1161    0.0817    0.1032;
     0.0180    0.0270    0.0405    0.0285    0.0360];
jdemo3          % Call for data
jointzw         % Call for m-program
Enter joint prob for (X,Y): P
Enter values for X: X
Enter values for Y: Y
Enter expression for g(t,u): abs(abs(t)-u)
Enter expression for h(t,u): abs(t.*u)
Use array operations on Z, W, PZ, PW, v, w, PZW
disp(PZW)
    0.0132         0         0         0         0
         0    0.0264         0         0         0
         0         0    0.0570         0         0
         0    0.0744         0         0         0
    0.0558         0         0    0.0725         0
         0         0    0.1032         0         0
         0    0.1363         0         0         0
    0.0817         0         0         0         0
    0.0405    0.1446    0.1107    0.0360    0.0477
EZ = total(v.*PZW)
EZ =   1.4398
 
ez = Z*PZ'       % Alternate, using marginal dbn
ez =   1.4398
EW = total(w.*PZW)
EW =   2.6075
ew = W*PW'       % Alternate, using marginal dbn
ew =   2.6075
M = v > w;           % P(Z>W)
PM = total(M.*PZW)
PM =   0.3390
At noted in the previous section, if {X,Y{ is an independent pair and Z=g(X),
W=h(Y), then the pair {Z,W{ is independent. However, if Z=g(X,Y) and
W=h(X,Y), then in general the pair {Z,W{ is not independent. We may illustrate this with the aid of the m-procedure jointzw

EXAMPLE 9: Functions of independent random variables

jdemo3
itest
Enter matrix of joint probabilities  P
The pair {X,Y} is independent           % The pair {X,Y} is independent
jointzw
Enter joint prob for (X,Y): P
Enter values for X: X
Enter values for Y: Y
Enter expression for g(t,u): t.^2 - 3*t  % Z = g(X)
Enter expression for h(t,u): abs(u) + 3  % W = h(Y)
Use array operations on Z, W, PZ, PW, v, w, PZW
itest
Enter matrix of joint probabilities  PZW
The pair {X,Y} is independent           % The pair {g(X),h(Y)} is independent
jdemo3                                  % Refresh data
jointzw
Enter joint prob for (X,Y): P
Enter values for X: X
Enter values for Y: Y
Enter expression for g(t,u): t+u         % Z = g(X,Y)
Enter expression for h(t,u): t.*u        % W = h(X,Y)
Use array operations on Z, W, PZ, PW, v, w, PZW
itest
Enter matrix of joint probabilities  PZW
The pair {X,Y} is NOT independent  % The pair {g(X,Y),h(X,Y)} is not indep
To see where the product rule fails, call for D  % Fails for all pairs

Absolutely continuous case: analysis and approximation

As in the analysis Joint Distributions, we may set up a simple approximation to the joint distribution and proceed as for simple random variables. In this section, we solve several examples analytically, then obtain simple approximations.

EXAMPLE 10: Distribution for a product

Suppose the pair {X,Y{ has joint density fXY. Let Z=XY. Determine Qv such that P(Zv)=P((X,Y),,Qv).
Figure 5: Region Qv for product XYv0.
This graph consist of an area bounded by two curves. One curve exist in the top right section and bottom left portion of a graph. The bottom left curve is labeled u=v/t v>0. The upper right portion is labeled u=v/t v<0. The bounded area is labeled Q_v.
SOLUTION (see Figure 5)
Qv={(t,u):tuv{={(t,u):t>0,uv/t{{(t,u):t<0,uv/t{{(18)
Figure 6: Product of X,Y with uniform joint distribution on the unit square.
This graph contains a square that is intersected by a curve. This curve is labeled u=v/t.

EXAMPLE 11

{X,Y{ uniform on unit square
fXY(t,u)=1,0t1,0u1. Then (see Figure 6)
P(XYv)=Qv1dudtwhereQv={(t,u):0t1,0umin{1,v/t{{(19)
Integration shows
FZ(v)=P(XYv)=v(1,,ln,(,v,))sothatfZ(v)=ln(v)=ln(1/v),0<v1(20)
For v=0.5,FZ(0.5)=0.8466.
% Note that although f = 1, it must be expressed in terms of t, u.
tuappr
Enter matrix [a b] of X-range endpoints  [0 1]
Enter matrix [c d] of Y-range endpoints  [0 1]
Enter number of X approximation points  200
Enter number of Y approximation points  200
Enter expression for joint density  (u>=0)&(t>=0)
Use array operations on X, Y, PX, PY, t, u, and P
G = t.*u;
[Z,PZ] = csort(G,P);
p = (Z<=0.5)*PZ'
p =  0.8465                 % Theoretical value 0.8466, above

EXAMPLE 12: Continuation of Example 5 from "Random Vectors and Joint Distributions"

The pair {X,Y{ has joint density fXY(t,u)=
6
37
 (t+2u) on the region bounded by t=0t=2u=0, and u=max{1,t{ (see Figure 7). Let Z=XY. Determine P(Z1).
Figure 7: Area of integration for Example 12.
A graph of f_xy(t,u)=(6/37)(t+2u)
ANALYTIC SOLUTION
P(Z1)=P((,X,,,,Y,),,Q)whereQ={(t,u):u1/t{(21)
Reference to Figure 7 shows that
P((,X,,,,Y,),,Q)=
6
37
 0101(t+2u)dudt+
6
37
 1201/t(t+2u)dudt=9/37+9/37=18/370.4865
(22)
APPROXIMATE SOLUTION
tuappr
Enter matrix [a b] of X-range endpoints  [0 2]
Enter matrix [c d] of Y-range endpoints  [0 2]
Enter number of X approximation points  300
Enter number of Y approximation points  300
Enter expression for joint density  (6/37)*(t + 2*u).*(u<=max(t,1))
Use array operations on X, Y, PX, PY, t, u, and P
Q = t.*u<=1;
PQ = total(Q.*P)
PQ =  0.4853             % Theoretical value 0.4865, above
G = t.*u;                % Alternate, using the distribution for Z
[Z,PZ] = csort(G,P);
PZ1 = (Z<=1)*PZ'
PZ1 = 0.4853
In the following example, the function g has a compound definition. That is, it has a different rule for different parts of the plane.
Figure 8: Regions for P(Z1/2) in Example 13.
This is a graph of a curve. To the left of the curve is a shaded area labeled Q_B. Below the curve is a shaded area labeled Q_A. The line defining area Q_B is labeled u=1/2-t. The curve is labeled u=t^2. The top of area Q_A is labeled u=1/2. Inside area Q_A is another triangle labled t_1 and an area labeled t_2

EXAMPLE 13: A compound function

The pair {X,Y{ has joint density fXY(t,u)=
2
3
 (t+2u) on the unit square 0t1,0u1.
Z={
YforX2Y0
X+YforX2Y<0
=IQ(X,Y)Y+IQc(X,Y)(X+Y)
(23)
for Q={(t,u):ut2{. Determine P(Z<=0.5).
ANALYTICAL SOLUTION
P(Z1/2)=P(Y1/2,YX2)+P(X+Y1/2,Y>X2)=P((X,Y),,,QA,,QB)(24)
where QA={(t,u):u1/2,ut2{ and QB={(t,u):t+u1/2,u>t2{. Reference to Figure 8 shows that this is the part of the unit square for whichumin(max(1/2t,t2),1/2). We may break up the integral into three parts. Let 1/2t1=t12 and t22=1/2. Then
P(Z1/2)=
2
3
 0t101/2t(t+2u)dudt+
2
3
 t1t20t2(t+2u)dudt+
2
3
 t2101/2(t+2u)dudt=0.2322
(25)
APPROXIMATE SOLUTION
tuappr
Enter matrix [a b] of X-range endpoints  [0 1]
Enter matrix [c d] of Y-range endpoints  [0 1]
Enter number of X approximation points  200
Enter number of Y approximation points  200
Enter expression for joint density  (2/3)*(t + 2*u)
Use array operations on X, Y, PX, PY, t, u, and P
Q = u <= t.^2;
G = u.*Q + (t + u).*(1-Q);
prob = total((G<=1/2).*P)
prob =  0.2328          % Theoretical is 0.2322, above
The setup of the integrals involves careful attention to the geometry of the system. Once set up, the evaluation is elementary but tedious. On the other hand, the approximation proceeds in a straightforward manner from the normal description of the problem. The numerical result compares quite closely with the theoretical value and accuracy could be improved by taking more subdivision points.

0 comments:

Post a Comment

Recent Comments

Popular Matlab Topics

Share your knowledge - help others

Crazy over Matlab Projects ? - Join Now - Follow Me

Sites U Missed to Visit ?

Related Posts Plugin for WordPress, Blogger...

Latest Articles

Special Search For Matlab Projects

MATLAB PROJECTS

counter

Bharadwaj. Powered by Blogger.