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, 3)# and #N(8, 3)#. Take #n = 10000# for both variables. Next, create a variable #Y = -6X1 + 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 = 14#
The variance of #Y = 333#
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 = 333#
First, you should create the random variables #X1# and #X2# with the function
rnorm(n, mean, sd)
. X1 <- rnorm(10000, -1, 3)Now, combine these following the function as described in the question.
X2 <- rnorm(10000, 8, 3)
Y <- -6*X1 + X2
Following the equation for the combination of random variables, the mean (expected value) and variance can be calculated as follows:
- #E[Y] = -6 \cdot E[X1] + E[X2]#
- #Var[Y] = -6^2 \cdot Var[X1] + Var[X2] + 2 \cdot -6 \cdot Cov[X1,X2]#
Therefore, you can calculate the mean and variance of #Y# as follows:
EY <- -6*-1 + 8
VarY <- (-6)^2*3^2 + 3^2 + 2*-6*0
Unlock full access