Skip to content

Instantly share code, notes, and snippets.

@MirzaCengic
Last active September 8, 2017 12:17
Show Gist options
  • Save MirzaCengic/502a771f6ae82834117d1970644f12f6 to your computer and use it in GitHub Desktop.
Save MirzaCengic/502a771f6ae82834117d1970644f12f6 to your computer and use it in GitHub Desktop.
biomod2 reprex for working with dataframes
library(mapview)
library(raster)
library(dplyr)
library(biomod2)
poppendorf_df <- as.data.frame(poppendorf, xy = TRUE)
poppendorf_df$coords_all <- paste(poppendorf_df$x, poppendorf_df$y, sep = "_")
poppendorf_pts <- sampleRandom(poppendorf, 1000, sp = TRUE)
poppendorf_xy <- as.data.frame(poppendorf_pts@coords)
poppendorf_xy$coords_all <- paste(poppendorf_xy$x, poppendorf_xy$y, sep = "_")
data_df <- left_join(poppendorf_df, poppendorf_xy, by = "coords_all")
data_predictors <- data_df[, c("B001n", "B002n", "B003n", "B004n", "B005n")]
data_df$PA <- ifelse(!is.na(data_df$y.y), 1, 0)
data_pa <- as.data.frame(data_df[, "PA"])
#### Testing with poppendorf data
model_data <- BIOMOD_FormatingData(resp.var = data_pa, expl.var = data_predictors, resp.name = "poppendorf_model")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment