4. Probability Distributions: Practical 4
Combinations of random variables
In the theorical part of this course, you learned the following equations for combining random variables:
If #X = aY + bZ# then:
- #E[X] = a~E[Y] + b~E[Z]#
- #Var[X] = a^2Var[Y] + b^2Var[Z] + 2ab~Cov[Y,Z]#
If #X = aY - bZ# then:
- #E[X] = a~E[Y] - b~E[Z]#
- #Var[X] = a^2Var[Y] + b^2Var[Z] - 2ab~Cov[Y,Z]#
Generate two random variables #X1# and #X2# from two different normal distribution #N(-1, 2)# and #N(6, 2)#. Take #n = 10000# for both variables. Next, create a variable #Y = -4X1 + X2#.
Calculate the mean and variance for the combined variable #Y# by applying the theoretical equations for combining random variables given above and the values for the population parameters of #X1# and #X2#.
The mean of #Y = 10#
The variance of #Y = 68#
First, you should create the random variables #X1# and #X2# with the function
Following the equation for the combination of random variables, the mean (expected value) and variance can be calculated as follows:
Therefore, you can calculate the mean and variance of #Y# as follows:
The variance of #Y = 68#
First, you should create the random variables #X1# and #X2# with the function
rnorm(n, mean, sd)
. X1 <- rnorm(10000, -1, 2)Now, combine these following the function as described in the question.
X2 <- rnorm(10000, 6, 2)
Y <- -4*X1 + X2
Following the equation for the combination of random variables, the mean (expected value) and variance can be calculated as follows:
- #E[Y] = -4 \cdot E[X1] + E[X2]#
- #Var[Y] = -4^2 \cdot Var[X1] + Var[X2] + 2 \cdot -4 \cdot Cov[X1,X2]#
Therefore, you can calculate the mean and variance of #Y# as follows:
EY <- -4*-1 + 6
VarY <- (-4)^2*2^2 + 2^2 + 2*-4*0
Unlock full access