## simulate dummy data
x <- rnorm(30) * matrix(1, 30, 5) + 0.5 * matrix(rnorm(30 * 5), 30, 5)
u <- pseudo_obs(x)
## fit a model
vc <- vinecop(u, family_set = "clayton")
# simulate from the model
u <- rvinecop(100, vc)
pairs(u)
# evaluate the density and cdf
dvinecop(u[1, ], vc)
pvinecop(u[1, ], vc)
# evaluate derivatives of the log-likelihood
scores(u, vc)
hessian(u, vc)
# derivatives can also be computed for the full likelihood
scores(u, vc, step_wise = FALSE)
hessian(u, vc, step_wise = FALSE)
## Discrete models
vc$var_types <- rep("d", 5) # convert model to discrete
# with discrete data we need two types of observations (see Details)
x <- qpois(u, 1) # transform to Poisson margins
u_disc <- cbind(ppois(x, 1), ppois(x - 1, 1))
dvinecop(u_disc[1:5, ], vc)
pvinecop(u_disc[1:5, ], vc)
# simulated data always has uniform margins
pairs(rvinecop(200, vc))
## Conditional simulation
vc_cond <- vinecop(
u,
family_set = "gaussian",
conditioning_set = c(2, 4)
)
u_cond <- c(0.25, 0.75)
uc <- rvinecop(
100,
vc_cond,
u_cond = u_cond,
conditioning_set = c(2, 4)
)
stopifnot(
isTRUE(all.equal(uc[, 2], rep(0.25, 100))),
isTRUE(all.equal(uc[, 4], rep(0.75, 100)))
)
Run the code above in your browser using DataLab