Skip to content
Snippets Groups Projects
Commit 1c80d57d authored by Maria Voigt's avatar Maria Voigt
Browse files

fixing import bug and adding functions

parent 00f6396c
Branches
No related tags found
No related merge requests found
...@@ -76,6 +76,8 @@ registerDoParallel(cl) ...@@ -76,6 +76,8 @@ registerDoParallel(cl)
source(file.path(indir_fun, "roger_functions/rogers_model_functions.R")) source(file.path(indir_fun, "roger_functions/rogers_model_functions.R"))
source(file.path(indir_fun, "generic/path.to.current.R")) source(file.path(indir_fun, "generic/path.to.current.R"))
source(file.path(indir_fun, "roger_functions/get_conf_set.r")) source(file.path(indir_fun, "roger_functions/get_conf_set.r"))
source(file.path(indir_fun, "roger_functions/helpers.r"))
source(file.path(indir_fun, "roger_functions/diagnostic_fcns.r"))
options("scipen" = 100, "digits" = 4) options("scipen" = 100, "digits" = 4)
...@@ -94,7 +96,7 @@ abundMod_results_path <- path.to.current(indir, "abundMod_results", "rds") ...@@ -94,7 +96,7 @@ abundMod_results_path <- path.to.current(indir, "abundMod_results", "rds")
if(is_verbose){print(paste("abundMod_results_path", abundMod_results_path))} if(is_verbose){print(paste("abundMod_results_path", abundMod_results_path))}
abundMod_results <- readRDS(abundMod_results_path) abundMod_results <- readRDS(abundMod_results_path)
predictors_path <- path.to.current(indir, "predictors_observation", "rds") predictors_path <- path.to.current(indir, "predictors_observation_scaled", "rds")
if(is_verbose){print(paste("predictors-path", predictors_path))} if(is_verbose){print(paste("predictors-path", predictors_path))}
predictors_obs <- readRDS(predictors_path) predictors_obs <- readRDS(predictors_path)
...@@ -103,9 +105,6 @@ if(is_verbose){print(paste("m_terms_path", m_terms_path))} ...@@ -103,9 +105,6 @@ if(is_verbose){print(paste("m_terms_path", m_terms_path))}
m_terms <- readRDS(m_terms_path) m_terms <- readRDS(m_terms_path)
save.image(file.path(outdir, "image_temp.RData"))
ests=apply(abundMod_results [, grepl(x=colnames(abundMod_results ), pattern="coeff")], 2, function(x){ ests=apply(abundMod_results [, grepl(x=colnames(abundMod_results ), pattern="coeff")], 2, function(x){
x[is.na(x)]=0 x[is.na(x)]=0
sum(x*abundMod_results$w_aic) sum(x*abundMod_results$w_aic)
...@@ -132,7 +131,7 @@ if(is_verbose){"finished saving all variables"} ...@@ -132,7 +131,7 @@ if(is_verbose){"finished saving all variables"}
parLapply(cl=cl, X=1:length(cl), function(x){library(MASS)}) parLapply(cl=cl, X=1:length(cl), function(x){library(MASS)})
n.boots=5 n.boots=1000
n.attempts=rep(0, n.boots) n.attempts=rep(0, n.boots)
all.boots=matrix(NA, ncol=length(m_terms), nrow=n.boots) all.boots=matrix(NA, ncol=length(m_terms), nrow=n.boots)
colnames(all.boots)=m_terms colnames(all.boots)=m_terms
...@@ -173,13 +172,20 @@ print(paste("this is the ", i, "boot")) ...@@ -173,13 +172,20 @@ print(paste("this is the ", i, "boot"))
} }
xx=apply(all.ests, 2, function(x){sum(x*w.aic)}) xx=apply(all.ests, 2, function(x){sum(x*w.aic)})
all.boots[i, names(xx)]=xx all.boots[i, names(xx)]=xx
points(i, 1, col=rainbow(n.boots)[i], pch=19, cex=sqrt(n.attempts[i])) # points(i, 1, col=rainbow(n.boots)[i], pch=19, cex=sqrt(n.attempts[i]))
} }
saveRDS(all.boots, file = file.path(outdir, paste0("all_boots_", saveRDS(all.boots, file = file.path(outdir, paste0("all_boots_",
Sys.Date(), ".rds"))) Sys.Date(), ".rds")))
xx=cbind(ests, t(apply(all.boots, 2, quantile, probs=c(0.025, 0.975))))
saveRDS(xx, file = file.path(outdir, paste0("xx_",
Sys.Date(), ".rds")))
save.image(file.path(outdir, paste0("abundance_model_bootstrap_", save.image(file.path(outdir, paste0("abundance_model_bootstrap_",
Sys.Date(), ".RData"))) Sys.Date(), ".RData")))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment