January 1st, 2005, 12:19 am
I wrote the S-Plus script below for 2 dimensions - cause I wanted to plot 2 dimensions. Should be straightforward to do for n-dimensions (except for the plotting).genClaytonCopulaSamples = function(n, theta){#Effects: Draw n pairs from a Clayton copula.#--------------------------------------------------------- #Generate n pairs of independent uniforms. x = matrix(0, n, 2) x[, 1] = runif(n) x[, 2] = runif(n) #Generate n mixing variables. y = rgamma(n, 1 / theta, 1) #Generate n pairs from a Clayton copula. for(i in 1:2) { x[, i] = (1 / (1 - log(x[, i]) / y))^ (1 / theta) } return (x)}main = function(){ par(mfcol = c(1, 2)) x = genClaytonCopulaSamples(1000, 2) plot(x[, 1], x[, 2], main = "Clayton (theta = 2)", xlab = "u1", ylab = "u2") x = genClaytonCopulaSamples(1000, 50) plot(x[, 1], x[, 2], main = "Clayton (theta = 50)", xlab = "u1", ylab = "u2")}main()