Академический Документы
Профессиональный Документы
Культура Документы
Michael King
Fall 2019
Introduction
In this quiz you will calculate the covariance of two jointly distributed continuous random
variables. The below formulas review some of the equations about covariance.
= E[XY ] − E[X]E[Y ]
Cov(X, Y ) = ρXY σX σY
Question 1
# Define f
f <- function(x, y){(8 / 3) * x * y * (0 < x & x < 1) * (x <= y & y <= 2
# Calculate E[X]
EX <- iterated_integral(
f = function(x, y){x * f(x, y)},
xl = xl,
xu = xu,
yl = yl,
yu = yu,
dx = 2)$value
EX
[1] 0.8
# Calculate E[Y]
EY <- iterated_integral(
f = function(x, y){y * f(x, y)},
xl = xl,
xu = xu,
yl = yl,
yu = yu,
dx = 2)$value
EY
[1] 1.244444
# Calculate E[XY]
EXY <- iterated_integral(
f = function(x, y){x * y * f(x, y)},
xl = xl,
xu = xu,
yl = yl,
yu = yu,
dx = 2)$value
EXY
[1] 1.037037
# Calculate the Covariance
covariance <- EXY - EX * EY
covariance
[1] 0.04148148
Question 2
In this part of the quiz you will explor the gapminder data set. Filter the data to only
include data from 2007 . Group the data by continent and compute the average life
expectancy. Arrange the data in descending order of life expectancy and report the results
as a bar graph.
# Clear the environment
rm(list = ls())
continent avg_life
Oceania 81.06215
Europe 77.89057
Americas 75.35668
Asia 69.44386
Africa 54.56441
G
Life Epectancy by Continent for 2007
Africa
Asia
Americas
Europe
Oceania
0 20 40 60 80
Life Expectancy
Quiz 10
Question 3
8
xy , 0 ≤ x ≤ 1, x ≤ y ≤ 2x
f (x, y) =
3
0 , otherwise