【问题标题】:Copula result in RCopula导致R
【发布时间】:2019-12-08 06:54:23
【问题描述】:

我有一个两列的表,它包含一个已经计算的 2 个变量的索引,一个简单的引用如下:

 V1, V2
 0.46,1.08
 0.84,1.05
-0.68,0.93
-0.99,0.68
-0.87,0.30
-1.08,-0.09
-1.16,-0.34
-0.61,-0.43
-0.65,-0.48
 0.73,-0.48

为了找出我拥有的上述数据之间的相关性,我使用了 R 中的 copula 包。

我用以下 VineCopula 代码来确定要使用哪个 Copula 家族:

library(VineCopula)
selectedCopula <- BiCopSelect(u,v,familyset=NA)
selectedCopula

建议使用生存 Gumbel,根据 copula R 手册旋转版本的 Gumbel Copula (Link)

但是,我选择了 Frank copula,因为它提供了对称的依赖结构,并且允许将数据中的正依赖建模为负依赖,这有多合理?

还有一件事,在运行以下不言自明的 copula 代码后:


# Estimate V1 distribution parameters and visually compare simulated vs observed data
x_mean <- mean(mydata$V1)
#Normal Distribution
hist(mydata$V1, breaks = 20, col = "green", density = 30)
hist(rnorm( nrow(mydata), mean = x_mean, sd = sd(mydata$V1)), 
breaks = 20,col = "blue", add = T, density = 30, angle = -45)

# Same for V2
y_mean <- mean(mydata$V2)
#Normal Distribution
hist(mydata$V2, breaks = 20, col = "green", density = 30)
hist(rnorm(nrow(mydata), mean = y_mean,sd = sd(mydata$V2)), 
breaks = 20, col = "blue", add = T, density = 30, angle = -45)


# Measure association using Kendall's Tau
cor(mydata, method = "kendall")


#Fitting process with copula choice
# Estimate copula parameters
cop_model <- frankCopula(dim = 2)
m <- pobs(as.matrix(mydata))
fit <- fitCopula(cop_model, m, method = 'ml')
coef(fit)

# Check Kendall's tau value for the frank copula with  = 3.236104 
tau(frankCopula(param = 3.23))

#Building the bivariate distribution using frank copula

# Build the bivariate distribution
sdx =sd(mydata$V1)
sdy =sd(mydata$V2)
my_dist <- mvdc(frankCopula(param = 3.23, dim = 2), margins = c("norm","norm"), 
                paramMargins = list(list(mean = x_mean, sd=sdx), 
                                    list(mean = y_mean, sd=sdy)))

# Generate 439 random sample observations from the multivariate distribution
v <- rMvdc(439, my_dist)
# Compute the density
pdf_mvd <- dMvdc(v, my_dist)
# Compute the CDF
cdf_mvd <- pMvdc(v, my_dist)

# Sample 439 observations from the distribution
sim <- rMvdc(439,my_dist)

# Plot the data for a visual comparison
plot(mydata$V1, mydata$V2, main = 'Test dataset x and y', col = "blue")
points(sim[,1], sim[,2], col = 'red')
legend('bottomright', c('Observed', 'Simulated'), col = c('blue', 'red'), pch=21)

绘制的数据集即使对于极值也显示出良好的拟合结果。

在这里,我想在同一个折线图中显示应用 frank copula 和原始数据的相关值, 我不知道如何提取坦率的 copula 结果? (单列,以便我可以使用原始数据进行绘图并进行视觉比较)

【问题讨论】:

    标签: r correlation cran probability-distribution


    【解决方案1】:

    我不确定我是否正确理解了您的问题。但是,如果您想获取 copula 数据(从 Frank copula 生成),它们存储在 sim 中。如果您要求Kendall tau,那么它们应该存储在fitcopula 中。您不能将坦率的 copula 数据作为一列,因为它必须是矩阵。此外,pobs 函数会给你一个矩阵的结果,所以你不需要使用as.matrix。如果您需要更多帮助,我很乐意提供帮助。

    【讨论】:

    • 感谢您的回答。函数 sim 有一个两列矩阵,正如你所说的来自新的双变量分布的样本观测值。但是,我正在寻找由 Frank Copula 构造的多元分布,因此我使用了 pMvdc 函数,它给出了用原始数据表示的累积分布函数(一列)。你觉得对吗?
    • 是否要将模拟数据的pdf与原始数据进行比较?如果是这样,那很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 2016-07-27
    • 2017-05-03
    • 1970-01-01
    相关资源
    最近更新 更多