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

fixing crucial bug: resultsdataframe in foreach loop

otherwise the values of other coefficients are used and nothing makes sense
parent 9ed19512
No related branches found
No related tags found
No related merge requests found
...@@ -365,16 +365,23 @@ write.csv(dfbeta_frame, file.path(outdir, ...@@ -365,16 +365,23 @@ write.csv(dfbeta_frame, file.path(outdir,
if(is_verbose){print(paste("8. Start running models", Sys.time()))} if(is_verbose){print(paste("8. Start running models", Sys.time()))}
results_res <- foreach(i = 1:nrow(all_model_terms),
.combine = rbind) %dopar%{
# make results dataframe
if (is.na(exclude_year)){ if (is.na(exclude_year)){
result <- as.data.frame(matrix(NA, ncol = 3 * length(model_terms) + 4, #5, result <- as.data.frame(matrix(NA, ncol = 3 *
length(model_terms) + 4, #5
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 = "_"),
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) +5, #+ 6, length(model_terms) +5, #+ 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 = "_"),
...@@ -382,10 +389,7 @@ names(result) <- c("model", paste("coeff", model_terms, sep = "_"), ...@@ -382,10 +389,7 @@ names(result) <- c("model", paste("coeff", model_terms, sep = "_"),
"theta", "SE.theta", "AIC", #"R2", "theta", "SE.theta", "AIC", #"R2",
"R2_cross") "R2_cross")
} }
# make model
results_res <- foreach(i = 1:nrow(all_model_terms),
.combine = rbind) %dopar%{
model <- as.formula( model <- as.formula(
paste("nr_nests ~", paste("nr_nests ~",
paste(m_terms[all_model_terms[i, ] == 1], collapse = "+"), paste(m_terms[all_model_terms[i, ] == 1], collapse = "+"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment