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

adding the part where output for excluding grid-cells is written into results

parent ab626e9e
No related branches found
No related tags found
No related merge requests found
...@@ -388,8 +388,7 @@ results_res <- foreach(i = 1:nrow(all_model_terms), ...@@ -388,8 +388,7 @@ results_res <- foreach(i = 1:nrow(all_model_terms),
paste("SE", model_terms, sep = "_"), paste("SE", model_terms, sep = "_"),
"theta", "SE.theta", "AIC", "R2" "theta", "SE.theta", "AIC", "R2"
)} else { )} else {
result <- as.data.frame(matrix(NA, ncol = 3 * result <- as.data.frame(matrix(NA, ncol = 3 * length(model_terms) + 6,
length(model_terms) + 6,
nrow = 1)) nrow = 1))
names(result) <- c("model", paste("coeff", model_terms, sep = "_"), names(result) <- c("model", paste("coeff", model_terms, sep = "_"),
paste("P",model_terms,sep = "_"), paste("P",model_terms,sep = "_"),
...@@ -446,17 +445,28 @@ results_res <- foreach(i = 1:nrow(all_model_terms), ...@@ -446,17 +445,28 @@ results_res <- foreach(i = 1:nrow(all_model_terms),
result[ , "R2"] <- summary(comparison_lm)$r.squared result[ , "R2"] <- summary(comparison_lm)$r.squared
# if we are excluding years, this is the test of predicted data vs observed data # if we are excluding years, this is the test of predicted data vs observed data
# for this year (with which the model wasn't fitted) # for this year (with which the model wasn't fitted)
if (!is.na(exclude_year)){ if (!is.na(exclude_year)){
predictors_excluded_year_pred <- predictors_excluded_year predictors_excluded_year_pred <- predictors_excluded_year
predictors_excluded_year_pred$offset_term <- 0 predictors_excluded_year_pred$offset_term <- 0
prediction_transect_excluded_year <- predict.glm(res, prediction_transect_excluded_year <- predict.glm(res,
newdata = predictors_excluded_year, newdata = predictors_excluded_year,
type = "response") type = "response")
cross_lm = lm(log(predictors_excluded_year$ou_dens+ 1) ~ cross_lm_year = lm(log(predictors_excluded_year$ou_dens+ 1) ~
log(prediction_transect_excluded_year + 1)) log(prediction_transect_excluded_year + 1))
result[ , "R2_cross"] <- summary(cross_lm)$r.squared result[ , "R2_cross"] <- summary(cross_lm_year)$r.squared
} }
if (!is.na(exclude_grid)){
predictors_excluded_grid_pred <- predictors_excluded_grid
predictors_excluded_grid_pred$offset_term <- 0
prediction_transect_excluded_grid <- predict.glm(res,
newdata = predictors_excluded_grid,
type = "response")
cross_lm_grid = lm(log(predictors_excluded_grid$ou_dens+ 1) ~
log(prediction_transect_excluded_grid + 1))
result[ , "R2_cross"] <- summary(cross_lm_grid)$r.squared
}
return(result) return(result)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment