Skip to content

Instantly share code, notes, and snippets.

@CerebralMastication
Created January 29, 2010 22:33
Show Gist options
  • Save CerebralMastication/290222 to your computer and use it in GitHub Desktop.
Save CerebralMastication/290222 to your computer and use it in GitHub Desktop.
require(copula)
rmvdc.new <- function (mvdc, n)
{
dim <- mvdc@copula@dimension
u <- rcopula(mvdc@copula, n)
x <- u
for (i in 1:dim) {
if (mvdc@margins[i]=="Johnson") {
qdf.expr <- copula:::asCall(copula:::P0("q", mvdc@margins[i]), list(mvdc@paramMargins[[i]])) } else {
qdf.expr <- copula:::asCall(copula:::P0("q", mvdc@margins[i]), mvdc@paramMargins[[i]])}
x[, i] <- eval(qdf.expr, list(x = u[, i]))
}
x
}
#examples for testing
#this is the mvdc example from the documentation... implemented to test the rmvdc.new function
gumbel.cop <- gumbelCopula(3, dim=2)
myMvd <- mvdc(gumbel.cop, c("exp","exp"), list(list(rate=2),list(rate=4)))
x <- rmvdc.new(myMvd, 1000)
#this sets up a Johnson example
require(SuppDists)
require(copula)
#create the Johnson mdvc object called myMvdc
myMvdc <- new("mvdc"
, copula = new("normalCopula"
, dispstr = "ex"
, getRho = function (obj)
{
obj@parameters
}
, dimension = 2L
, parameters = 0.305219345195888
, param.names = "rho.1"
, param.lowbnd = -1
, param.upbnd = 1
, message = "Normal copula family"
)
, margins = c("Johnson", "Johnson")
, paramMargins = structure(list(`1` = structure(list(gamma = 0.573499380745508,
delta = 1.27550810038738, xi = -0.362694236870908, lambda = 0.901083112899886,
type = "SB"), .Names = c("gamma", "delta", "xi", "lambda",
"type")), `2` = structure(list(gamma = 0.0897862661272532, delta = 0.95829602909698,
xi = -0.0287783693181873, lambda = 0.121685082081697, type = "SU"), .Names = c("gamma",
"delta", "xi", "lambda", "type"))), .Names = c("1", "2"))
, marginsIdentical = FALSE
)
#using the rmvdc.new() functions things seem to work
rmvdc.new(myMvdc, 10)
#but using the reqular rmvdc() they don't
rmvdc(myMvdc, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment