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

fix bugs in random crossvalidation

parent 5c6f4940
No related branches found
No related tags found
No related merge requests found
...@@ -52,7 +52,7 @@ option_list <- list ( ...@@ -52,7 +52,7 @@ option_list <- list (
dest = "exclude_grid_rand_perc", dest = "exclude_grid_rand_perc",
type = "integer", type = "integer",
default = NA, default = NA,
help = "percemt cells to be excluded", help = "percent cells to be excluded",
metavar = "10"), metavar = "10"),
make_option(c("-q", "--quiet"), dest = "verbose_script", make_option(c("-q", "--quiet"), dest = "verbose_script",
action = "store_false", action = "store_false",
...@@ -115,6 +115,9 @@ if(is_verbose){print(paste("exclude grid", exclude_grid))} ...@@ -115,6 +115,9 @@ if(is_verbose){print(paste("exclude grid", exclude_grid))}
exclude_grid_rand <- options$exclude_grid_rand exclude_grid_rand <- options$exclude_grid_rand
if(is_verbose){print(paste("exclude grid random", exclude_grid_rand))} if(is_verbose){print(paste("exclude grid random", exclude_grid_rand))}
exclude_grid_rand_perc <- options$exclude_grid_rand_perc
if(is_verbose){print(paste("exclude_grid_rand_perc", exclude_grid_rand_perc))}
#---------# #---------#
# Globals # # Globals #
#---------# #---------#
...@@ -364,7 +367,7 @@ m_terms <- c("1", ...@@ -364,7 +367,7 @@ m_terms <- c("1",
"I(rain_dry^2)") "I(rain_dry^2)")
save.image(file.path(outdir, "image_before_model.RData")) save.image(file.path(outdir, paste0("image_before_model_", exclude_grid_rand, ".RData")))
# save model_terms here # save model_terms here
model_terms <- names(glm.nb(as.formula(paste("nr_nests~", paste(m_terms, model_terms <- names(glm.nb(as.formula(paste("nr_nests~", paste(m_terms,
...@@ -513,13 +516,13 @@ results_res <- foreach(i = 1:nrow(all_model_terms), ...@@ -513,13 +516,13 @@ results_res <- foreach(i = 1:nrow(all_model_terms),
} }
if (!is.na(exclude_grid_rand)){ if (!is.na(exclude_grid_rand)){
predictors_excluded_grid_pred <- predictors_excluded_grid_rand predictors_excluded_grid_rand_pred <- predictors_excluded_grid_rand
predictors_excluded_grid_pred$offset_term <- 0 predictors_excluded_grid_rand_pred$offset_term <- 0
prediction_transect_excluded_grid <- predict.glm(res, prediction_transect_excluded_grid_rand<- predict.glm(res,
newdata = predictors_excluded_grid_rand, newdata = predictors_excluded_grid_rand,
type = "response") type = "response")
cross_lm_random = lm(log(predictors_excluded_grid_rand$ou_dens+ 1) ~ cross_lm_random = lm(log(predictors_excluded_grid_rand$ou_dens+ 1) ~
log(prediction_transect_excluded_random + 1)) log(prediction_transect_excluded_grid_rand+ 1))
result[ , "R2_cross"] <- summary(cross_lm_random)$r.squared result[ , "R2_cross"] <- summary(cross_lm_random)$r.squared
result[ , "nr_excluded"] <- nr_excluded result[ , "nr_excluded"] <- nr_excluded
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment