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 then:
If then:
Generate two random variables and from two different normal distribution and . Take for both variables. Next, create a variable .
Calculate the mean and variance for the combined variable by applying the theoretical equations for combining random variables given above and the values for the population parameters of and .
The mean of
The variance of
First, you should create the random variables and 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 as follows:
The variance of
First, you should create the random variables and with the function
rnorm(n, mean, sd)
. X1 <- rnorm(10000, -2, 4)Now, combine these following the function as described in the question.
X2 <- rnorm(10000, 5, 2)
Y <- -5*X1 + X2
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 as follows:
EY <- -5*-2 + 5
VarY <- (-5)^2*4^2 + 2^2 + 2*-5*0
Unlock full access