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(5, 1)#. Take #n = 10000# for both variables. Next, create a variable #Y = 5X1 + 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 = 226#
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 = 226#
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, 5, 1)
Y <- 5*X1 + X2
Following the equation for the combination of random variables, the mean (expected value) and variance can be calculated as follows:
- #E[Y] = 5 \cdot E[X1] + E[X2]#
- #Var[Y] = 5^2 \cdot Var[X1] + Var[X2] + 2 \cdot 5 \cdot Cov[X1,X2]#
Therefore, you can calculate the mean and variance of #Y# as follows:
EY <- 5*1 + 5
VarY <- (5)^2*3^2 + 1^2 + 2*5*0
Unlock full access