# install.packages("name.package") library(copula) library(mnormt) library(lattice) library(mvtnorm) library(VGAM) # simulation from copula models # independence copula ic<-indepCopula(dim=2) wireframe2(ic, FUN=pCopula) contourplot2(ic, FUN=pCopula) set.seed(332) n<-1000 U<-rCopula(n, copula=ic) str(U) # matrix nxd plot(U, xlab=quote(U[1]), ylab=quote(U[2]), col=3) # normal copula d<-2 set.seed(332) rho<-0.7 #linear correlation P<-matrix(rho, nrow=d, ncol=d) diag(P)<-1 n<-1000 X<-rmvnorm(n, sigma=P) plot(X, xlim=c(-4,4), ylim=c(-4,4), xlab=quote(X[1]), ylab=quote(X[2])) # PIT U<-pnorm(X) # sample from normal copula with N(0,1) margins plot(U) ## same as set.seed(332) U.<-rCopula(n, normalCopula(rho, dim=2)) plot(U., xlab=quote(U[1]), ylab=quote(U[2])) # exponential margins Exp(2) Y<-qexp(U, 2) plot(Y, xlim=c(0,4), ylim=c(0,4), xlab=quote(Y[1]), ylab=quote(Y[2])) # pseudo-copula observations # rescaled ranks (empirical cdf's) V<-pobs(Y) plot(V, col=4, main="pseudo-copula observations") # sampling from a Clayton and a survival Clayton copula cop<-claytonCopula(param = 2) U<-rCopula(n, copula=cop) plot(U, xlab=quote(U[1]), ylab=quote(U[2])) # survival Clayton Copula V<-1-U plot(V, xlab=quote(V[1]), ylab=quote(V[2])) # sampling from t copula with fixed df # and inversion of Kendall's tau nu<-4 param<-iTau(tCopula(df=nu), tau = 0.6) tc<-tCopula(param, df=nu) tc set.seed(271) U<-rCopula(n, copula=tc) plot(U, col=6) cor(U, method = "kendall") ######################### data(loss) ?loss #View(loss) # loss: claims # alae: expenses LOSS<-loss$loss ALAE<-loss$alae plot(LOSS, ALAE, cex=0.5) plot(log(LOSS), log(ALAE), cex=0.5) #hist(LOSS, breaks=30) Z<-pobs(cbind(LOSS, ALAE)) plot(Z)