Skip to content

Instantly share code, notes, and snippets.

@njtierney
Last active October 20, 2016 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njtierney/5b3204ebc449091191e6bcc533d2854f to your computer and use it in GitHub Desktop.
Save njtierney/5b3204ebc449091191e6bcc533d2854f to your computer and use it in GitHub Desktop.
R copula code exampl
# install.packages("VineCopula")
# install.packages("copula")
# install.packages("tigerstats")
library(VineCopula)
library(copula)
library(tigerstats)
set.seed(123)
N=200
dim=dim
U=runif(N, min=0,max=1)
# x <- rep(0,N)
x <- vector("list",N)
for (i in 1:N){
if(U[i] < 0.3){
x[[i]]= rCopula(N,claytonCopula(0.5,dim=2))
}else if(U[i]<0.7){
x[[i]]=rCopula(N,frankCopula(-4,dim=2))
}
}
x[[1]]
# densityplot(x[[1]])
plot(density(x[[1]]))
## make rCopula(N...) into rCopular(i,...)-----------------------------------
library(VineCopula)
library(copula)
library(tigerstats)
set.seed(123)
N=200
dim=dim
U=runif(N, min=0,max=1)
# x <- rep(0,N)
x <- vector("list",N)
for (i in 1:N){
if(U[i] < 0.3){
x[[i]]= rCopula(i,claytonCopula(0.5,dim=2))
}else if(U[i]<0.7){
x[[i]]=rCopula(i,frankCopula(-4,dim=2))
}
}
x[[1]]
densityplot(as.numeric(x[[1]]))
plot(density(x[[1]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment