Copula Estimation
Purpose
Simulate a copula with some specific parameters and then estimate the params using a copula
> set.seed(1977) > library(scatterplot3d) > library(copula) > gaus.cop <- ellipCopula(family = "normal", dim = 2, dispstr = "ex", + param = 0.2) > gaus.mvdc <- mvdc(copula = gaus.cop, margins = c("norm", "norm"), + paramMargins = list(list(mean = 0, sd = 2), list(mean = 0, + sd = 3))) > contour(gaus.mvdc, dmvdc, xlim = c(-8, 8), ylim = c(-8, 8), main = paste("Marginal gaussian (rho) = ", + 0.2)) |
Estimate the copula parameters
> n <- 500 > dat <- rmvdc(gaus.mvdc, n) > mm <- apply(dat, 2, mean) > vv <- apply(dat, 2, var) > corr <- cor(dat[, 1], dat[, 2]) > fit <- fitMvdc(dat, gaus.mvdc, start = c(mm[1], vv[1], mm[2], + vv[2], corr)) > print(fit) The Maximum Likelihood estimation is based on 500 observations. Margin 1 : Estimate Std. Error m1.mean -0.0870828 0.09170276 m1.sd 2.0505380 0.06484346 Margin 2 : Estimate Std. Error m2.mean -0.01427850 0.13933827 m2.sd 3.11570712 0.09852853 Copula: Estimate Std. Error rho.1 0.2247160 0.04246269 The maximized loglikelihood is -2333.254 The convergence code is 0 see ?optim. |
Estimate the parameters using IFM method
> loglik.marg <- function(b, x) { + return(sum(dnorm(x, b[1], b[2], log = T))) + } > b1hat <- optim(c(0, 1), fn = loglik.marg, x = dat[, 1], control = list(fnscale = -1))$par > b2hat <- optim(c(0, 1), fn = loglik.marg, x = dat[, 2], control = list(fnscale = -1))$par > udat <- cbind(pnorm(dat[, 1], b1hat[1], b2hat[2]), pnorm(dat[, + 2], b2hat[1], b2hat[2])) |
Inference Functions for Margins
> u <- udat > fit.ifl <- fitCopula(gaus.cop, u, start = c(0.1), method = "ml") > print(fit.ifl) The estimation method is Maximum Likelihood based on 500 observations. Estimate Std. Error z value Pr(>|z|) rho.1 0.3069664 0.05124425 5.990261 2.095050e-09 The maximized loglikelihood is 12.53464 The convergence code is 0 |
Canonical Maximum Likelihood Method
> u1 <- apply(dat, 2, rank)/(n + 1) > fit.ifl <- fitCopula(gaus.cop, u1, start = c(0.1), method = "ml") > print(fit.ifl) The estimation method is Maximum Likelihood based on 500 observations. Estimate Std. Error z value Pr(>|z|) rho.1 0.2237456 0.04224145 5.296827 1.178323e-07 The maximized loglikelihood is 12.33080 The convergence code is 0 |
The only purpose of running this fitCopula is to get an idea of running the function