Skip to content

Instantly share code, notes, and snippets.

@dpastoor
Created August 5, 2014 01:35
Show Gist options
  • Save dpastoor/135a8fbe7adf9150d31a to your computer and use it in GitHub Desktop.
Save dpastoor/135a8fbe7adf9150d31a to your computer and use it in GitHub Desktop.
sse_covariance_checks
library(ggplot2)
library(stringr)
### functions -------------
cov_convergence <- function(wd) {
setwd(wd)
dir_list <- list.dirs(recursive=FALSE)
results <- lapply(str_replace_all(dir_list, pattern="./", ""), function(x) {
num <- str_replace_all(x, pattern="sse_", "")
csv <- paste0("sse_", num, "/raw_results_",num,".csv")
dat <- read.csv(csv, stringsAsFactors=F)
cov_success <- aggregate(covariance_step_successful ~ hypothesis, data=dat, mean)
cov_success$info <- x
return(cov_success)
})
resultsdf <- do.call(rbind, results)
process_info <- str_split(resultsdf$info, "n")
process_info <- lapply(process_info, '[', 2:3)
process_info <- do.call(rbind,lapply(process_info, function(x) {
ninds <- as.numeric(x[1])
ncovinds <- as.numeric(str_split(x[2], "cov")[[1]][2])
return(data.frame(ninds,ncovinds))
}))
resultsdf <- cbind(resultsdf, process_info)
return(resultsdf)
}
base_theme_obs <- function() { theme(legend.text = element_text(size = 14),
legend.title = element_text(size = 16),
axis.title.x = element_text(size = 14, face = "bold"),
axis.title.y = element_text(size = 14, face = "bold"),
axis.text.x = element_text(color = "black", size = 12),
axis.text.y = element_text(color = "black", size = 12),
strip.text.x = element_text(color = "black", size = 14, face = "bold"))
}
### run ----
get_cov_convergence <- function(dir) {
mag <- gsub(x=dir, pattern=".*sse_", replacement="", perl=TRUE)
setwd(dir)
subdirs <- list.dirs(recursive=F,full.names=TRUE)
subdirs <- str_split(subdirs, pattern="n")
subdirs <- unlist(lapply(subdirs, "[",2))
sse_dirs <- paste0(dir, "/n",subdirs)
cov_results <- lapply(sse_dirs, cov_convergence)
cov_results_df <- do.call(rbind, cov_results)
cov_results_df$mag <- mag
return(cov_results_df)
}
dirs <- c("/SFS/scratch/pastoor/sse_mag12",
"/SFS/scratch/pastoor/sse_mag15",
"/SFS/scratch/pastoor/sse_mag2"
)
all_cov_results <- lapply(dirs, get_cov_convergence)
all_df <- do.call(rbind,all_cov_results)
ggplot(cov_results_df,
aes(x = factor(ninds), y = covariance_step_successful, color = factor(ncovinds))) +
geom_point(size = 4, position=position_jitter(width=0.1, height=0))+
facet_grid(~hypothesis) +
ggtitle(mag) + base_theme_obs()
ggplot(all_df[all_df$hypothesis=="mc-alternative_4",],
aes(x = factor(ninds), y = covariance_step_successful, group = mag)) +
geom_point(aes(color = factor(ncovinds)),size = 4) + facet_grid(~mag) + base_theme_obs()
ggplot(all_df[all_df$hypothesis=="mc-alternative_2" | all_df$hypothesis=="mc-alternative_4",],
aes(x = factor(ninds), y = covariance_step_successful, group = mag)) +
geom_point(aes(color = factor(ncovinds)),size = 4) + facet_grid(mag~hypothesis) + base_theme_obs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment