Ожидаемые значения от связки в R - PullRequest
0 голосов
/ 12 июня 2019

У меня есть связка, представляющая зависимость между двумя переменными X и Y. Я хочу вычислить следующую формулу: E (X | Y≤1%). Это ожидаемое значение X при условии, что Y ниже 1%. Я вижу, что несколько похожий вопрос был задан там , но предоставленный код R не дает искомого значения. Ниже приведены некоторые сведения о копуле и краевом распределении.

library(VineCopula)
   library(copula)
#I estimate my Copula and assumes normal distribution for the two marginals
copula_dist <- mvdc(copula=claytonCopula(param=1.0), margins=c("norm","norm"),
                    paramMargins=list(list(mean=0, sd=5),list(mean=0, sd=5)))

#I take a sample of 500 events
sim <- rMvdc(500,copula_dist)
# Compute the density
pdf_mvd <- dMvdc(sim, my_dist)
# Compute the CDF
cdf_mvd <- pMvdc(sim, my_dist)

1 Ответ

0 голосов
/ 12 июня 2019

Вы должны оценить этот двойной интеграл: integral of x*pdf(x,y), -oo < x < +oo, -oo < y < 1% и разделить его на Pr(Y < 1%). Это сделано ниже. Я также выполняю аппроксимацию с помощью симуляций для проверки.

library(copula)

# the distribution
copula_dist <- mvdc(copula=claytonCopula(param=1.0), margins=c("norm","norm"),
                    paramMargins=list(list(mean=0, sd=5),list(mean=0, sd=5)))

### we will calculate E[X | Y < y0]
y0 <- 1/100

### approximation of E[X | Y < y0] using simulations
sim <- rMvdc(100000, copula_dist)
mean(sim[sim[,2]<y0,1])
# [1] -1.967642

### approximation of E[X | Y < y0] using numerical integration
### this is E[X * 1_{Y<y0}] / P(Y < y0)
library(cubature)
# PDF of the distribution 
pdf <- function(xy) dMvdc(xy, copula_dist)
# P(Y < y0)
denominator <- pnorm(y0, mean=0, sd=5)
# integrand
f <- function(xy) xy[1] * pdf(xy)
# integral
integral <- hcubature(f, lowerLimit = c(-Inf, -Inf), upperLimit = c(Inf, y0))
integral$integral / denominator
# [1] -1.942691
...