Copula 101
Defining normalCopula and tCopula
> library(copula) > set.seed(1) > myCop.norm <- ellipCopula(family = "normal", dim = 3, dispstr = "ex", + param = 0.4) > myCop.t <- ellipCopula(family = "t", dim = 3, dispstr = "toep", + param = c(0.8, 0.5), df = 8) > myCop.clayton <- archmCopula(family = "clayton", dim = 3, param = 2) > myMvd <- mvdc(copula = myCop.clayton, margins = c("norm", "norm", + "norm"), paramMargins = list(list(mean = 0, sd = 2), list(mean = 0, + sd = 1), list(mean = 0, sd = 2))) |
Look at the structure of normalCopula
> str(myCop.norm) Formal class 'normalCopula' [package "copula"] with 8 slots ..@ dispstr : chr "ex" ..@ getRho :function (obj) ..@ dimension : num 3 ..@ parameters : num 0.4 ..@ param.names : chr "rho.1" ..@ param.lowbnd: num -1 ..@ param.upbnd : num 1 ..@ message : chr "Normal copula family" |
Look at the structure of tCopula
> str(myCop.t) Formal class 'tCopula' [package "copula"] with 10 slots ..@ df : num 8 ..@ df.fixed : logi FALSE ..@ dispstr : chr "toep" ..@ getRho :function (obj) ..@ dimension : num 3 ..@ parameters : num [1:3] 0.8 0.5 8 ..@ param.names : chr [1:3] "rho.1" "rho.2" "df" ..@ param.lowbnd: num [1:3] -1 -1 1 ..@ param.upbnd : num [1:3] 1 1 Inf ..@ message : chr "t copula family " |
Look at the structure of archmCopula
> str(myCop.clayton) Formal class 'claytonCopula' [package "copula"] with 7 slots ..@ exprdist : structure(expression(cdf = (1 + (u1^(-alpha) - 1 + u2^(-alpha) - 1 + u3^(-alpha) - 1))^(-1/alpha), pdf = (1 + (u1^(-alpha) - 1 + u2^(-alpha) - 1 + u3^(-alpha) - 1))^((((-1/alpha) - 1) - 1) - 1) * ((((-1/alpha) - 1) - 1) * (u3^((-alpha) - 1) * (-alpha))) * (((-1/alpha) - 1) * (u2^((-alpha) - 1) * (-alpha))) * ((-1/alpha) * (u1^((-alpha) - 1) * (-alpha)))), .Names = c("cdf", "pdf")) ..@ dimension : num 3 ..@ parameters : num 2 ..@ param.names : chr "param" ..@ param.lowbnd: num 0 ..@ param.upbnd : num Inf ..@ message : chr "Clayton copula family; Archimedean copula" |
Look at the structure of myMVD
> str(myMvd) Formal class 'mvdc' [package "copula"] with 4 slots ..@ copula :Formal class 'claytonCopula' [package "copula"] with 7 slots .. .. ..@ exprdist : structure(expression(cdf = (1 + (u1^(-alpha) - 1 + u2^(-alpha) - 1 + u3^(-alpha) - 1))^(-1/alpha), pdf = (1 + (u1^(-alpha) - 1 + u2^(-alpha) - 1 + u3^(-alpha) - 1))^((((-1/alpha) - 1) - 1) - 1) * ((((-1/alpha) - 1) - 1) * (u3^((-alpha) - 1) * (-alpha))) * (((-1/alpha) - 1) * (u2^((-alpha) - 1) * (-alpha))) * ((-1/alpha) * (u1^((-alpha) - 1) * (-alpha)))), .Names = c("cdf", "pdf")) .. .. ..@ dimension : num 3 .. .. ..@ parameters : num 2 .. .. ..@ param.names : chr "param" .. .. ..@ param.lowbnd: num 0 .. .. ..@ param.upbnd : num Inf .. .. ..@ message : chr "Clayton copula family; Archimedean copula" ..@ margins : chr [1:3] "norm" "norm" "norm" ..@ paramMargins :List of 3 .. ..$ :List of 2 .. .. ..$ mean: num 0 .. .. ..$ sd : num 2 .. ..$ :List of 2 .. .. ..$ mean: num 0 .. .. ..$ sd : num 1 .. ..$ :List of 2 .. .. ..$ mean: num 0 .. .. ..$ sd : num 2 ..@ marginsIdentical: logi FALSE |
Random Generation using copulas
> u <- rcopula(myCop.t, 4) > print(u) [,1] [,2] [,3] [1,] 0.3508325 0.6165205 0.7459244 [2,] 0.3912433 0.2189641 0.2556491 [3,] 0.3925507 0.7579099 0.9157623 [4,] 0.9822296 0.9611676 0.8896553 |
> cbind(dcopula(myCop.t, u), pcopula(myCop.t, u)) [,1] [,2] [1,] 2.265954 0.3081520 [2,] 3.493735 0.1359238 [3,] 1.878803 0.3777087 [4,] 31.481423 0.8771844 |
> x <- rmvdc(myMvd, 4) > x [,1] [,2] [,3] [1,] 1.9515514 0.6254143 3.4859965 [2,] 0.2446993 1.6817503 1.3283929 [3,] 1.6257827 1.0489920 0.8391207 [4,] -0.2221244 0.7980091 0.1028776 |
> cbind(dmvdc(myMvd, x), pmvdc(myMvd, x)) [,1] [,2] [1,] 0.006334554 0.6489146 [2,] 0.005026580 0.4871090 [3,] 0.016346781 0.5549416 [4,] 0.017295186 0.3509979 |
Scatterplots for normal copula
> par(mfrow = c(1, 2)) > u <- rcopula(myCop.norm, 200) > scatterplot3d(u) > v <- rcopula(myCop.norm, 200) > scatterplot3d(v) |
Graphics for Clayton, Frank and Gumbel package
> myMvd1 <- mvdc(copula = archmCopula(family = "clayton", param = 2), + margins = c("norm", "norm"), paramMargins = list(list(mean = 0, + sd = 1), list(mean = 0, sd = 1))) > myMvd2 <- mvdc(copula = archmCopula(family = "frank", param = 5.736), + margins = c("norm", "norm"), paramMargins = list(list(mean = 0, + sd = 1), list(mean = 0, sd = 1))) > myMvd3 <- mvdc(copula = archmCopula(family = "gumbel", param = 2), + margins = c("norm", "norm"), paramMargins = list(list(mean = 0, + sd = 1), list(mean = 0, sd = 1))) > par(mfrow = c(1, 3)) > contour(myMvd1, dmvdc, xlim = c(-3, 3), ylim = c(-3, 3), main = "clayton") > contour(myMvd2, dmvdc, xlim = c(-3, 3), ylim = c(-3, 3), main = "frank") > contour(myMvd3, dmvdc, xlim = c(-3, 3), ylim = c(-3, 3), main = "gumbel") |