cE.: Conditional expectation

Description Usage Arguments Value Examples

Description

Conditional expectation

Usage

1
2
3
4
5
cE.(x, g, p)

cvar.(x, g, p)

ccov.(x, y, g, p)

Arguments

x

A numeric vector giving the population

g

An atomic vector on which to condition

p

weights

y

another vector

Value

The conditional expectation of x.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
n <- 100
x <- rnorm(n)
y <- rnorm(n)
g <- rep(letters[1:10], 10)

# law of total expectation
E.(x)
E.(cE.(x, g))

# law of total variance
var.(x)
E.(cvar.(x, g)) + var.(cE.(x, g))

# law of total covariance
cov.(x, y)
E.(ccov.(x, y, g)) + cov.(cE.(x, g), cE.(y, g))

popmoments documentation built on May 2, 2019, 5 p.m.