Skip to content

Instantly share code, notes, and snippets.

@OterLabb
Created January 25, 2020 13:35
Show Gist options
  • Save OterLabb/d772e28cea7d31620e0d8e2221ce30e8 to your computer and use it in GitHub Desktop.
Save OterLabb/d772e28cea7d31620e0d8e2221ce30e8 to your computer and use it in GitHub Desktop.
library(raster)
library(dismo)
library(usdm)
raster_data <- raster("C:/MinData/satelittdata.tif")
kraake_points <- read.csv("C:/MinData/kraakepoints.csv")
# Remove duplicates (same XY coordinates)
kraake_points <- kraake_points[!duplicated(kraake_points[c("Breddegrad","Lengdegrad")]),]
# Convert observations to spatial data frame
coordinates(kraake_points) <- c('Breddegrad','Lengdegrad')
crs(kraake_points) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84") # set crs
satelite_extract <- cbind(kraake_points,raster::extract(raster_data,kraake_points))
satelite_extract_df <- as.data.frame(satelite_extract) # Convert to data frame
head(satelite_extract_df) # Check data
### VIF test ###
colnames(satelite_extract_df[2:62]) # Check that the right coloumns is selected (only satelite data)
vif(satelite_extract_df[2:62])
vif.cor <- vifcor(satelite_extract_df[2:62], th=0.9) # Vif test
vif.cor # See the vif score of the remained variables
# Help
?vif.cor
?vif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment