-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5626d38
commit a0d35c1
Showing
87 changed files
with
1,949 additions
and
2,248 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
library(boostCopula) | ||
library(VineCopula) | ||
library(tictoc) | ||
logit <- function(x, inv = FALSE) { | ||
if (!inv) { | ||
log(x/(1-x)) | ||
} else { | ||
exp(x)/(1+exp(x)) | ||
} | ||
} | ||
link_fun <- function(family, x) { | ||
if (family %in% 1:2) { | ||
sin(pi/2*tanh(x)) | ||
} else if (family %in% c(3,13)) { | ||
2*logit(x, inv = T)/(1-logit(x, inv = T)) | ||
} else if (family %in% c(23, 33)) { | ||
-2*logit(x, inv = T)/(1-logit(x, inv = T)) | ||
} else if (family %in% c(4,14)) { | ||
1/(1-logit(x, inv = T)) | ||
} else if (family %in% c(24, 34)) { | ||
-1/(1-logit(x, inv = T)) | ||
} | ||
} | ||
# copula families | ||
fams <- c(1, 2, 3, 13, 23, 33, 4, 14, 24, 34) | ||
n <- 100 # number of simulation repetitions | ||
N <- 60 # number of samples for each simulation | ||
p <- 100 # number of variables | ||
d <- 5 | ||
coef_mat <- array(0, dim = c(p+1, d, d), dimnames = list(c("intercept", paste("x", sep = "", 1:p)), c(), c())) | ||
positives_lin <- array(NA, dim = c(2, d, d), dimnames = list(c("true", "false"), c(), c())) | ||
par_mae_lin <- array(NA, dim = c(d, d)) | ||
fams_lin <- array(0, dim = c(d, d)) | ||
# define 5-dimensional R-vine tree structure matrix | ||
Matrix <- c(5, 0, 0, 0, 0, | ||
2, 2, 0, 0, 0, | ||
3, 3, 3, 0, 0, | ||
1, 4, 4, 4, 0, | ||
4, 1, 1, 1, 1) | ||
Matrix <- matrix(Matrix, 5, 5, byrow = T) | ||
# define R-vine pair-copula family matrix | ||
family <- c(0, 0, 0, 0, 0, | ||
1, 0, 0, 0, 0, | ||
24, 2, 0, 0, 0, | ||
4, 33, 13, 0, 0, | ||
23, 34, 14, 3, 0) | ||
family <- matrix(family, 5, 5, byrow = T) | ||
# define R-vine pair-copula parameter matrix | ||
par <- c(0, 0, 0, 0, 0, | ||
0.5, 0, 0, 0, 0, | ||
-2, 0.5, 0, 0, 0, | ||
2, -2, 2, 0, 0, | ||
-2, -2, 2, 2, 0) | ||
par <- matrix(par, 5, 5, byrow = T) | ||
# define second R-vine pair-copula parameter matrix | ||
par2 <- c(0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, | ||
0, 4, 0, 0, 0, | ||
0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0) | ||
par2 <- matrix(par2, 5, 5, byrow = T) | ||
boostRVC <- RVineMatrix(Matrix = Matrix, | ||
family = family, | ||
par = par, par2 = par2, | ||
names = c("U1", "U2", "U3", "U4", "U5")) | ||
# set seed for reproducubility | ||
set.seed(5) | ||
x <- sapply(1:p, function(l) runif(N, -1, 1)) | ||
colnames(x) <- paste0("x", 1:p) | ||
u <- matrix(runif(N*d), ncol = d, dimnames = list(c(), paste0("U", 1:d, sep = ""))) | ||
# simulate linear model | ||
U <- boostRVineSimStudy(boostRVC, u, x, mode = "linear") | ||
library(boostCopula) | ||
library(VineCopula) | ||
library(tictoc) | ||
logit <- function(x, inv = FALSE) { | ||
if (!inv) { | ||
log(x/(1-x)) | ||
} else { | ||
exp(x)/(1+exp(x)) | ||
} | ||
} | ||
link_fun <- function(family, x) { | ||
if (family %in% 1:2) { | ||
sin(pi/2*tanh(x)) | ||
} else if (family %in% c(3,13)) { | ||
2*logit(x, inv = T)/(1-logit(x, inv = T)) | ||
} else if (family %in% c(23, 33)) { | ||
-2*logit(x, inv = T)/(1-logit(x, inv = T)) | ||
} else if (family %in% c(4,14)) { | ||
1/(1-logit(x, inv = T)) | ||
} else if (family %in% c(24, 34)) { | ||
-1/(1-logit(x, inv = T)) | ||
} | ||
} | ||
# copula families | ||
fams <- c(1, 2, 3, 13, 23, 33, 4, 14, 24, 34) | ||
n <- 100 # number of simulation repetitions | ||
N <- 6000 # number of samples for each simulation | ||
p <- 100 # number of variables | ||
d <- 5 | ||
coef_mat <- array(0, dim = c(p+1, d, d), dimnames = list(c("intercept", paste("x", sep = "", 1:p)), c(), c())) | ||
positives_lin <- array(NA, dim = c(2, d, d), dimnames = list(c("true", "false"), c(), c())) | ||
par_mae_lin <- array(NA, dim = c(d, d)) | ||
fams_lin <- array(0, dim = c(d, d)) | ||
# define 5-dimensional R-vine tree structure matrix | ||
Matrix <- c(5, 0, 0, 0, 0, | ||
2, 2, 0, 0, 0, | ||
3, 3, 3, 0, 0, | ||
1, 4, 4, 4, 0, | ||
4, 1, 1, 1, 1) | ||
Matrix <- matrix(Matrix, 5, 5, byrow = T) | ||
# define R-vine pair-copula family matrix | ||
family <- c(0, 0, 0, 0, 0, | ||
1, 0, 0, 0, 0, | ||
24, 2, 0, 0, 0, | ||
4, 33, 13, 0, 0, | ||
23, 34, 14, 3, 0) | ||
family <- matrix(family, 5, 5, byrow = T) | ||
# define R-vine pair-copula parameter matrix | ||
par <- c(0, 0, 0, 0, 0, | ||
0.5, 0, 0, 0, 0, | ||
-2, 0.5, 0, 0, 0, | ||
2, -2, 2, 0, 0, | ||
-2, -2, 2, 2, 0) | ||
par <- matrix(par, 5, 5, byrow = T) | ||
# define second R-vine pair-copula parameter matrix | ||
par2 <- c(0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, | ||
0, 4, 0, 0, 0, | ||
0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0) | ||
par2 <- matrix(par2, 5, 5, byrow = T) | ||
boostRVC <- RVineMatrix(Matrix = Matrix, | ||
family = family, | ||
par = par, par2 = par2, | ||
names = c("U1", "U2", "U3", "U4", "U5")) | ||
# set seed for reproducubility | ||
set.seed(5) | ||
x <- sapply(1:p, function(l) runif(N, -1, 1)) | ||
colnames(x) <- paste0("x", 1:p) | ||
u <- matrix(runif(N*d), ncol = d, dimnames = list(c(), paste0("U", 1:d, sep = ""))) | ||
# simulate linear model | ||
U <- boostRVineSimStudy(boostRVC, u, x, mode = "linear") | ||
tic() | ||
object <- boostRVineCopSelect(U = U, | ||
X = x, | ||
boostRVM = boostRVineMatrix(Matrix = Matrix, | ||
family = family, | ||
formula = matrix("~.", d, d, byrow = T)), | ||
selectioncrit = "loglik", | ||
familyset = NA, | ||
par = FALSE, | ||
type = "glm", | ||
control = boost_control(mstop = 500), | ||
cval = cval_control(cval = F), | ||
deselect = deselect_control(deselect = T), | ||
center = TRUE, | ||
stabilization = "none", | ||
na.action = na.omit, | ||
cores = 10) | ||
toc() | ||
253.249/60 | ||
ll_true <- boostRVineTrueLL(U = U, | ||
X = x, | ||
boostRVM = boostRVineMatrix(Matrix = Matrix, | ||
family = family, | ||
formula = matrix("~.", d, d, byrow = T)), | ||
cores = 10) | ||
sum(unlist(ll_true), na.rm = T) | ||
object$loglik | ||
100/17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.