如何从R中的拟合copula求概率?
我需要用拟合的copula求概率。例如,使用了Student t copula。然后使用范围[0,1]上的如何从R中的拟合copula求概率?,r,graph,3d,probability-theory,R,Graph,3d,Probability Theory,我需要用拟合的copula求概率。例如,使用了Student t copula。然后使用范围[0,1]上的rCopula()函数生成随机双变量变量tsim01 据我所知,我应该计算对应点0
rCopula()
函数生成随机双变量变量tsim01
据我所知,我应该计算对应点0tcopula
library(copula)
rm(list=ls(all=TRUE))
N <- 100
set.seed(1)
df = cbind(as.data.frame(rnorm(N)),
as.data.frame(rnorm(N)));
mymargins = c("norm", "norm")
myparamMargins = list(list(mean=mean(df[,1]), sd=sd(df[,1])),
list(mean=mean(df[,2]), sd=sd(df[,2])))
# Student t copula
tcopula <- tCopula(dim=2, dispstr="un", df=2, df.fixed=TRUE)
tfit <- fitCopula(tcopula, pobs(as.matrix(df)), method='ml')
trho <- coef(tfit);
tcopula <- mvdc(copula=tCopula(trho, dim=2, df=3),
margins=mymargins,
paramMargins=myparamMargins)
tsim01 <- rCopula(N, tCopula(trho, dim=2, df=3))
p1 <- 0.4; p2 <- 0.7; delta <- 1e-3
prob(tCopula(trho, dim=2, df=3), c(p1, p1+delta), c(p2, p2+delta))
# [1] 0.1036955
par(mfrow=c(1,3))
persp(tcopula, dMvdc, main="pdf", xlim=c(-2,2), ylim=c(-2,2),
xlab="x", ylab="y", zlab="c(x,y)")
contour(tcopula, dMvdc, main="Contour pdf", xlim=c(-2,2), ylim=c(-2,2),
xlab="x", ylab="y")
plot(tsim01, main="tCopula, Simulated values on [0,1]^2",
xlab="z1", ylab="z2", pch=16, col="blue")
abline(h=p2,v=p1)
p1_new <- qt(p1, df=3) # t_df_trho^-1(p1) is the inverce of t_df_trho()
p2_new <- qt(p2, df=3) # t_df_trho^-1(p2)