0% found this document useful (0 votes)
2 views2 pages

Conditional Expectation in R: Examples

The document provides a series of examples related to conditional expectation using simulated data. It includes generating random values from a Poisson distribution based on an exponentially distributed lambda, calculating empirical mean and variance, and comparing them to theoretical values. Additionally, it presents a histogram of the values and calculates the empirical probability of having more than two claims.

Uploaded by

Tanmay Tingre
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Conditional Expectation in R: Examples

The document provides a series of examples related to conditional expectation using simulated data. It includes generating random values from a Poisson distribution based on an exponentially distributed lambda, calculating empirical mean and variance, and comparing them to theoretical values. Additionally, it presents a histogram of the values and calculates the empirical probability of having more than two claims.

Uploaded by

Tanmay Tingre
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

####### Conditional Expectation examples #######

[Link](40)

values<-rep(0,5000) # i)

for(i in 1:5000){

lambda<-rexp(1,1/0.4)

values[i]<-rpois(1,lambda)

} # ii)

# iii) Empirical mean and variance

mean(values)

var(values)

# iv) theoretical mean & variance

# E(X) = E(E(X|lambda))

# E(X) = E(lambda)
# E(X) = 0.4

# Var(X) = E(Var(X|lambda)) + Var(E(X|lambda))

# Var(X) = E(lambda) + Var(lambda)

# Var(X) = 0.4 + 0.16 = 0.56

# v) histogram

hist(values,breaks=c(-0.5:6.5))

table(values)

# empirical probability of more than 2 claims

length(values[values>2])/length(values)

You might also like