Skip to content

Commit

Permalink
nop
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasKook committed Aug 24, 2023
1 parent b223836 commit e96d285
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
11 changes: 8 additions & 3 deletions inst/code/run-simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ devtools::load_all()
devtools::load_all("inst/helpers")
library("colorspace")
library("RCIT")
library("CondIndTests")
theme_set(theme_bw() + theme(legend.position = "top"))

save <- TRUE # Save simulation results in current R session
Expand All @@ -44,7 +45,7 @@ ltest <- c("Wald", "cor.test", "KCI", "gcm.test")
names(ltest) <- tests

# ROC-specific args
pkgs <- c("magrittr", "tramicp")
pkgs <- c("magrittr", "tramicp", "RCIT", "CondIndTests")
tANA <- ANA
if (spec == "roc") {
mods <- mods[1]
Expand All @@ -53,6 +54,9 @@ if (spec == "roc") {
pkgs <- c(pkgs, "pROC")
}

# KCI
tcoin <- RCIT # CondIndTest

# Params
ndags <- ifelse(spec == "correct", 100, 50) # Number of DAGs
nsim <- 20 # Number of repetitions
Expand All @@ -77,7 +81,7 @@ env <- "E" # Name of environment var
cfb <- c(-22, 8) # baseline cf
rmc <- FALSE # Whether to remove censoring
stdz <- TRUE # Whether to standardize
sde <- sqrt(30)
sde <- sqrt(10)
errDistAnY <- "normal"
errDistDeY <- "normal"
mixAnY <- 0.1
Expand All @@ -96,7 +100,8 @@ fobs <- list(types = types, fml = fml, resp = resp, env = env, preds = preds,
blfix = blfix, cfb = cfb, K = tK, polrK = polrK, rmc = rmc,
stdz = stdz, nsim = nsim, sde = sde, errDistAnY = errDistAnY,
errDistDeY = errDistDeY, mixAnY = mixAnY, mixDeY = mixDeY,
dags = dags, mods = mods, tests = tests, spec = spec)
dags = dags, mods = mods, tests = tests, spec = spec,
coin = tcoin)

if (save) {
pvec <- c("nanc", nanc, "ndec", ndec, "panc", panc, "pdec", pdec, "penv", penv,
Expand Down
2 changes: 1 addition & 1 deletion inst/helpers/R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ AUCANA <- function(condition, dat, fixed_objects = NULL) {
oicp <- attr(dat, "oracle_icp")
pvals <- if (ttype == "kci") {
tmp <- cdkci(fixed_objects$resp, fixed_objects$env, fixed_objects$preds,
data = dat)
data = dat, coin = fixed_objects$coin)
inv <- attr(tmp, "intersection")
tmp
} else {
Expand Down
28 changes: 17 additions & 11 deletions inst/helpers/R/kci.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
#' @examples
#' \dontrun{
#' set.seed(1)
#' d <- dgp_random_dag(n = 1e3, mod = "colr", dag = random_dag(nanc = 2,
#' d <- dgp_random_dag(n = 5e1, mod = "colr", dag = random_dag(nanc = 2,
#' ndec = 2, panc = 1, pdec = 1, penv = 1))
#' cdkci("Y", "E", paste0("X", 1:4), data = d, seed = 1)
#' cdkci("Y", "E", paste0("X", 1:4), data = d, coin = CondIndTests::CondIndTest)
#' cdkci("Y", "E", paste0("X", 1:4), data = d)
#' }
#'
#'
Expand All @@ -47,16 +48,21 @@ cdkci <- function(Y, E, X, data, coin = RCIT, verbose = FALSE, ...) {

ret <- apply(ps[[npred]], 2, function(set) {
tset <- X[set]
tst <- try(coin(as.matrix(as.numeric(data[, Y])), as.numeric(data[, E]),
as.matrix(data[, tset]), ... = ...), silent = TRUE)
if (inherits(tst, "try-error"))
tst <- coin(as.matrix(as.numeric(data[, Y])), as.matrix(data[, E]),
as.matrix(data[, tset]), ... = ...)
pval <- tst[["pvalue"]]
if (is.null(pval)) pval <- tst[["p.value"]]
if (is.null(pval)) pval <- tst[["p"]]
if (identical(tset, character(0)))
if (identical(tset, character(0))) {
tset <- "Empty"
pval <- 0
} else {
tst <- try(coin(as.numeric(data[, Y]), data[, E],
data[, tset], ... = ...), silent = TRUE)
if (inherits(tst, "try-error"))
tst <- coin(as.matrix(as.double(data[, Y])),
as.matrix(as.double(data[, E])),
as.matrix(data[, tset]), ... = ...)
pval <- tst[["pvalue"]]
if (is.null(pval)) pval <- tst[["p.value"]]
if (is.null(pval)) pval <- tst[["p"]]

}
structure(pval, names = paste(tset, collapse = "+"))
}, simplify = FALSE)
tests <- c(tests, unlist(ret))
Expand Down
2 changes: 1 addition & 1 deletion inst/helpers/R/simdesign.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ANA <- function(condition, dat, fixed_objects = NULL) {
oicp <- attr(dat, "oracle_icp")
pvals <- if (ttype == "kci") {
tmp <- cdkci(fixed_objects$resp, fixed_objects$env, fixed_objects$preds,
data = dat)
data = dat, coin = fixed_objects$coin)
inv <- attr(tmp, "intersection")
tmp
} else {
Expand Down

0 comments on commit e96d285

Please sign in to comment.