fractions(integrate(function(x){x^2/2},0,2)$value)
[1] 4/3
Given a joint pmf/pdf, calculate and interpret the expected values/means and variances of random variables and functions of random variables.
Differentiate between covariance and correlation, and given a joint pmf/pdf, calculate and interpret the covariance and correlation between two random variables.
Given a joint pmf/pdf, determine whether random variables are independent of one another and justify your conclusion with appropriate calculations and reasoning.
Calculate and interpret conditional expectations for given joint pmfs/pdfs.
Computing expected values of random variables in the joint context is similar to the univariate case. Let
(Note that
In the case of continuous random variables with a joint pdf
Given a joint pmf, one can find the mean of
The
Example:
Letand be discrete random variables with joint pmf below.
Find
First we will use the joint pmf directly, then we find the marginal pmf of
The marginal pmf of
So,
Exercise: Let
and be defined above. Find , , , and .
As with
To find
Note that
Note that
Let’s consider an example with continuous random variables where summation is replaced with integration:
Example:
Letand be continuous random variables with joint pdf: for and .
Exercise: Find
, , , and .
We found the marginal pdf of R
fractions(integrate(function(x){x^2/2},0,2)$value)
[1] 4/3
To find
We’ll use the joint pdf:
Or using R
:
adaptIntegrate(function(x){(x[1]+x[2])*x[1]*x[2]},
lowerLimit = c(0,0),
upperLimit = c(1,2))$integral
[1] 2
If we wanted to use simulation to find this expectation, we could simulate variables from the marginal of
The cdf for
set.seed(1820)
<- data.frame(x=2*sqrt(runif(10000)),y=sqrt(runif(10000)))
new_data %>%
new_data mutate(z=x+y) %>%
summarize(Ex=mean(x),Ey=mean(y),Explusy = mean(z))
Ex Ey Explusy
1 1.338196 0.6695514 2.007748
We can see that
Next, we have
Using R
:
fractions(adaptIntegrate(function(x){(x[1]*x[2])*x[1]*x[2]},
lowerLimit = c(0,0),
upperLimit = c(1,2))$integral)
[1] 8/9
Or by simulating, we have:
set.seed(191)
<- data.frame(x=2*sqrt(runif(10000)),y=sqrt(runif(10000)))
new_data %>%
new_data mutate(z=x*y) %>%
summarize(Ex=mean(x),Ey=mean(y),Extimesy = mean(z))
Ex Ey Extimesy
1 1.33096 0.6640436 0.8837552
Recall that the variance of a random variable is the expected value of the squared difference from its mean. So,
Yuck!! But we will continue because we are determined to integrate after so much Calculus in our core curriculum.
Here’s a better way using R
:
fractions(adaptIntegrate(function(x){(x[1]*x[2]-8/9)^2*x[1]*x[2]},
lowerLimit = c(0,0),
upperLimit = c(1,2))$integral)
[1] 17/81
Next we will estimate the variance using a simulation:
set.seed(816)
<- data.frame(x=2*sqrt(runif(10000)),y=sqrt(runif(10000)))
new_data %>%
new_data mutate(z=(x*y-8/9)^2) %>%
summarize(Var = mean(z))
Var
1 0.2098769
That was much easier. Notice that we are really just estimating these expectations with the simulations. The mathematical answers are the true population values while our simulations are sample estimates. In a few chapters we will discuss estimators in more detail.
We have discussed expected values of random variables and functions of random variables in a joint context. It would be helpful to have some kind of consistent measure to describe how two random variables are related to one another. Covariance and correlation do just that. It is important to understand that these are measures of a linear relationship between variables.
Consider two random variables
We can simplify this expression to make it a little more usable:
Thus,
This expression is a little easier to use, since it’s typically straightforward to find each of these quantities.
It is important to note that while variance is a positive quantity, covariance can be positive or negative. A positive covariance implies that as the value of one variable increases, the other tends to increase. This is a statement about a linear relationship. Likewise, a negative covariance implies that as the value of one variable increases, the other tends to decrease.
Example:
An example of positive covariance is human height and weight. As height increase, weight tends to increase. An example of negative covariance is gas mileage and car weight. As car weight increases, gas mileage decreases.
Remember that if
One disadvantage of covariance is its dependence on the scales of the random variables involved. This makes it difficult to compare covariances of multiple sets of variables. Correlation avoids this problem. Correlation is a scaled version of covariance. It is denoted by
While covariance could take on any real number, correlation is bounded by -1 and 1. Two random variables with a correlation of 1 are said to be perfectly positively correlated, while a correlation of -1 implies perfect negative correlation. Two random variables with a correlation (and thus covariance) of 0 are said to be uncorrelated, that is they do not have a linear relationship but could have a non-linear relationship. This last point is important; random variables with no relationship will have a 0 covariance. However, a 0 covariance only implies that the random variables do not have a linear relationship.
Let’s look at some plots, Figures Figure 15.1, Figure 15.2, Figure 15.3, and Figure 15.4 of different correlations. Remember that the correlation we are calculating in this section is for the population, while the plots are showing sample points from a population.
Suppose
In the last step, we are using the alternative expression for variance (
Regrouping the terms:
Example:
Letand be defined as above. Find , , and .
Quickly,
With such a low
Two random variables
If
For a discrete distribution, you must check that each cell, joint probabilities, are equal to the product of the marginal probability. Back to our joint pmf from above:
The marginal pmf of
An easy way to determine if continuous variables are independent is to first check that the domain only contains constants, it is rectangular, and second that the joint pdf can be written as a product of a function of
Thus for our examples above even though the domains were rectangular, in
An important idea in graph theory, network analysis, Bayesian networks, and queuing theory is conditional expectation. We will only briefly introduce the ideas here so that you have a basic understanding. This does not imply it is not an important topic.
Let’s start with a simple example to illustrate the ideas.
Example:
Sam will read either one chapter of his history book or one chapter of his philosophy book. If the number of misprints in a chapter of his history book is Poisson with mean 2 and if the number of misprints in a chapter of his philosophy book is Poisson with mean 5, then assuming Sam is equally likely to choose either book, what is the expected number of misprints that Sam will find?
Note: in the next chapter we are working with transformations and could attack the problem using that method.
First let’s use simulation to get an idea what value the answer should be and then use algebraic techniques and definitions we have learned in this book.
Simulate 5000 reads from the history book and 5000 from philosophy and combine:
set.seed(2011)
<-data.frame(misprints=c(rpois(5000,2),rpois(5000,5))) my_data
head(my_data)
misprints
1 1
2 1
3 2
4 1
5 2
6 4
dim(my_data)
[1] 10000 1
Figure @ref(fig:hist151-fig) is a histogram of the data.
gf_histogram(~misprints,data=my_data,breaks=seq(-0.5, 15.5, by=1)) %>%
gf_theme(theme_classic()) %>%
gf_labs(x="Number of Misprints")
Or as a bar chart in Figure @ref(fig:bar151-fig)
gf_bar(~misprints,data=my_data)%>%
gf_theme(theme_classic()) %>%
gf_labs(x="Number of Misprints")
And now find the average.
mean(~misprints,data=my_data)
[1] 3.4968
Now for a mathematical solution. Let
Now here is the tricky part, without specifying a value of
The inner expectation in the right hand side is for the conditional distribution and the outer is for the marginal with respect to