cex.main=0.7 ) Notice that the number of distances initially increases, peaks ~250 km, then declines. Normally we'd stratify by thinning points so they're no closer than half this distance (~125 km). Initially we did indeed try this but found that it removed so many points that the predictions were much worse... since our goal is to demonstrate removal of bias (and presumably production of better models), let's use a smaller distance (50 km) so we have more points remaining. We can thin the records using a script we wrote inspired by the package. The function spThin randomly removes points based on minimum distances, so your and my results may vary. # thinning distance in meters minDist <- 50000 set.seed(12345) # thin records spatiallyThinnedRecords <- geogThinApprox( x=records, minDist=minDist, longLat=c('longitude', 'latitude') ) # save records! saveRDS(spatiallyThinnedRecords, './Species Records/06 Species Records - Randomly Thinned Presences.rds') nrow(records) ## [1] 29 nrow(spatiallyThinnedRecords) ## [1] 16 How many records did thinning remove? # plot par(mfrow=c(1, 2), pty='s', cex.main=0.7) plot(rangeMap, main=paste0('Unthinned Presences (n=', nrow(records), ')')) sp::plot(countries, add=TRUE, col='white') plot(rangeMap, add=TRUE) points(records$longitude, records$latitude, pch=21, bg='mediumseagreen') plot(rangeMap, main=paste0('Thinned Presences (n=', nrow(spatiallyThinnedRecords), ')')) sp::plot(countries, add=TRUE, col='white') plot(rangeMap, add=TRUE) points(spatiallyThinnedRecords$longitude, spatiallyThinnedRecords$latitude, pch=21, bg='mediumseagreen')
cex.main=0.7 ) Notice that the number of distances initially increases, peaks ~250 km, then declines. Normally we'd stratify by thinning points so they're no closer than half this distance (~125 km). Initially we did indeed try this but found that it removed so many points that the predictions were much worse... since our goal is to demonstrate removal of bias (and presumably production of better models), let's use a smaller distance (50 km) so we have more points remaining. We can thin the records using a script we wrote inspired by the spThin package. The function randomly removes points based on minimum distances, so your and my results may vary. # thinning distance in meters minDist <- 50000 set.seed(12345) # thin records spatiallyThinnedRecords <- geogThinApprox( x=records, minDist=minDist, longLat=c('longitude', 'latitude') ) # save records! saveRDS(spatiallyThinnedRecords, './Species Records/06 Species Records - Randomly Thinned Presences.rds') nrow(records) ## [1] 29 nrow(spatiallyThinnedRecords) ## [1] 16 How many records did thinning remove? # plot par(mfrow=c(1, 2), pty='s', cex.main=0.7) plot(rangeMap, main=paste0('Unthinned Presences (n=', nrow(records), ')')) sp::plot(countries, add=TRUE, col='white') plot(rangeMap, add=TRUE) points(records$longitude, records$latitude, pch=21, bg='mediumseagreen') plot(rangeMap, main=paste0('Thinned Presences (n=', nrow(spatiallyThinnedRecords), ')')) sp::plot(countries, add=TRUE, col='white') plot(rangeMap, add=TRUE) points(spatiallyThinnedRecords$longitude, spatiallyThinnedRecords$latitude, pch=21, bg='mediumseagreen')
Exercise_08_Bias_Correction.docx