# NOT RUN {
# Example 1: conditional sampling from a C-Vine
# Read data
data(dataset)
data <- dataset$data[1:400,1:4]
# Define the variables Y and X. X are the conditioning variables,
# which have to be positioned in the last columns of the data.frame
colnames(data) <- c("Y1","Y2","X3","X4")
# }
# NOT RUN {
# Select a vine and fit the copula families, specifying that there are 2 conditioning variables
RVM <- CDVineCondFit(data,Nx=2,type="CVine")
# Set the values of the conditioning variables as those used for the calibration.
# Order them with respect to RVM$Matrix, considering that is a C-Vine
d=dim(RVM$Matrix)[1]
cond1 <- data[,RVM$Matrix[(d+1)-1,(d+1)-1]]
cond2 <- data[,RVM$Matrix[(d+1)-2,(d+1)-2]]
condition <- cbind(cond1,cond2)
# Simulate the variables
Sim <- CDVineCondSim(RVM,condition)
# Plot the simulated variables over the observed
Sim <- data.frame(Sim)
overplot(Sim,data)
# Example 2: conditional sampling from a D-Vine
# Read data
data(dataset)
data <- dataset$data[1:100,1:4]
# Define the variables Y and X. X are the conditioning variables,
# which have to be positioned in the last columns of the data.frame
colnames(data) <- c("Y1","Y2","X3","X4")
# Select a vine and fit the copula families, specifying that there are 2 conditioning variables
RVM <- CDVineCondFit(data,Nx=2,type="DVine")
summary(RVM) #It is a D-Vine.
# Set the values of the conditioning variables as those used for the calibration.
# Order them with respect to RVM$Matrix, considering that is a D-Vine.
cond1 <- data[,RVM$Matrix[1,1]]
cond2 <- data[,RVM$Matrix[2,2]]
condition <- cbind(cond1,cond2)
# Simulate the variables
Sim <- CDVineCondSim(RVM,condition)
# Plot the simulated variables over the observed
Sim <- data.frame(Sim)
overplot(Sim,data)
# Example 3
# Read data
data(dataset)
data <- dataset$data[1:100,1:2]
colnames(data) <- c("Y1","X2")
# Fit copula
require(VineCopula)
BiCop <- BiCopSelect(data$Y1,data$X2)
BiCop
# Fix conditioning variable to low values and simulate
condition <- data$X2/10
Sim <- CDVineCondSim(BiCop,condition)
# Plot the simulated variables over the observed
Sim <- data.frame(Sim)
overplot(Sim,data)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab