Skip to content

Commit

Permalink
Merge pull request #14 from LucasKook/dev
Browse files Browse the repository at this point in the history
Fix paths simulations
  • Loading branch information
LucasKook authored Jul 11, 2024
2 parents c7c5c55 + 7d2c9c3 commit 46dd0b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 37 deletions.
2 changes: 1 addition & 1 deletion inst/code/dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ install.packages("remotes", repos = "https://cloud.r-project.org")

### GitHub packages
remotes::install_github("igraph/rigraph")
remotes::install_github("strobl/RCIT")
remotes::install_github("ericstrobl/RCIT")

### Bioconductor packages
remotes::install_bioc(c("graph", "Rgraphviz", "RBGL"))
Expand Down
20 changes: 10 additions & 10 deletions inst/code/run-simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

set.seed(27) # Seed
parall <- FALSE # Parallel computing?
.libPaths(c("~/tutu/lib", .libPaths()))

### Command line args and defaults
args <- as.numeric(commandArgs(TRUE))
Expand Down Expand Up @@ -110,14 +109,15 @@ fobs <- list(types = types, fml = fml, resp = resp, env = env, preds = preds,
affect_variance = affect_variance)

if (save) {
pvec <- c("nanc", nanc, "ndec", ndec, "panc", panc, "pdec", pdec, "penv", penv,
"stdz", stdz, "sde", round(sde, 2), "errDist", errDistAnY, errDistDeY,
"spec", spec)
outdir <- file.path(
"inst", "results", Sys.Date(), paste0(paste0(
names(pvec), pvec, collapse = ""), collapse = "_"))
specname <- switch(spec, "correct" = "results_main",
"link" = "results_link", "hidden" = "results_hidden",
"roc" = "results_binary-roc", "larger" = "results_larger")
outdir <- file.path("inst", "results", specname)
resdir <- file.path(outdir, "results")
if (!dir.exists(outdir))
dir.create(outdir, recursive = TRUE)
if (!dir.exists(resdir))
dir.create(resdir, recursive = TRUE)

write_rds(fobs, file.path(outdir, "fobs.rds"))
}
Expand All @@ -138,7 +138,6 @@ if (TEST) {
Design <- Design[ROW <- 1, ]
}


# Run ---------------------------------------------------------------------

suppressWarnings(file.remove(list.files(pattern = "SIMDESIGN-TEMPFILE")))
Expand All @@ -158,7 +157,8 @@ res <- runSimulation(
packages = pkgs,
filename = file.path(outdir, paste0("sim-results", ROW, ".rds")),
save_details = list(
safe = TRUE, save_results_dirname = file.path(outdir, paste0("results-row-", ROW)),
save_seeds_dirname = file.path(outdir, "seeds")
safe = TRUE, save_results_dirname = file.path(resdir, paste0("results-row-", ROW)),
save_results_filename = paste0("results-row-", ROW),
save_seeds_dirname = file.path(resdir, "seeds")
)
)
29 changes: 3 additions & 26 deletions inst/code/vis-simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Visualize simulation results
# LK 2023

settings <- c("main", "app", "hidden", "link", "wald-extended", "larger")
settings <- c("main", "app", "hidden", "link", "larger")

setting <- settings[as.numeric(commandArgs(TRUE))[1]]
if (is.na(setting))
Expand Down Expand Up @@ -112,29 +112,6 @@ if (setting == "main") {
fobs <- readRDS(file.path(bpath, "fobs.rds"))
res <- read_sim_results(file.path(bpath, "results"))
res$oicp[res$oicp == "empty"] <- "Empty"
} else if (setting == "wald-extended") {
### paths
bpath <- file.path(rpath, "results_main")
tmods <- c(mods[-1], amods)
ttests <- tests
out <- "sim-wald-extended.pdf"
th <- 4.5
tw <- 11

fobs <- readRDS(file.path(bpath, "fobs.rds"))
res <- read_sim_results(file.path(bpath, "results"))
res$oicp[res$oicp == "empty"] <- "Empty"
res <- dplyr::filter(res, test == "wald")

bpath <- file.path(rpath, "results_wald-extended")
bfobs <- readRDS(file.path(bpath, "fobs.rds"))
bres <- read_sim_results(file.path(bpath, "results"))
bres$oicp[bres$oicp == "empty"] <- "Empty"
bres <- dplyr::filter(bres, test == "wald")
bres$test <- "wald.test"

res <- full_join(res, bres)

}

### Summarize for plotting
Expand Down Expand Up @@ -163,5 +140,5 @@ if (setting == "hidden") {
# Vis ---------------------------------------------------------------------

p1 <- vis(tmods, ttests)
ggsave(file.path(rpath, out), p1, height = th, width = tw, scale = 1)
ggsave(file.path("inst", "figures", out), p1, height = th, width = tw, scale = 1)
ggsave(file.path(rpath, out), p1, height = th, width = tw, scale = 1, create.dir = TRUE)
ggsave(file.path("inst", "figures", out), p1, height = th, width = tw, scale = 1, create.dir = TRUE)

0 comments on commit 46dd0b6

Please sign in to comment.