graph - How to find probability from a fitted copula in R? -
i need find probability using fitted copula. example, student t copula used. random bivariate variable tsim01
generated rcopula()
function on range [0,1].
as understand should compute value of bivariate copula function tcopula
@ corresponded points 0< p1, p2<1
.
i have tried use function prob()
package copula
. setup values of p1=0.4
, p2=0.7
, small delta=1e-3
. have definded small hypercube. probability 0.1036955. example below.
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)
am correctly applying function prob()
? how check answer 3d pdf plot or contour plot?
edit. possible alternative way use a conditional cdf.
edit 2. possible alternative way 2 use quantile transformation c(p1, p2)=t_df_trho(t_df_trho^-1(p1), t_df_trho^-1(p2)).
p1_new <- qt(p1, df=3) # t_df_trho^-1(p1) inverce of t_df_trho() p2_new <- qt(p2, df=3) # t_df_trho^-1(p2)
but don't know function t_df_trho
should use? function t_df_trho
bivariate student-t distribution function, df
number of degree freedom, , trho
correlation coefficient.
Comments
Post a Comment