knitr::opts_chunk$set(echo = TRUE) knitr::opts_chunk$set(cache = F) knitr::opts_chunk$set(eval = T,fig.width=4, fig.height=4, dpi=200,out.width='80%') knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file()) mc.cores=1
library(occOutliers) library(sp)
We start by finding n obvious spatial outlier.
myPres=read.csv(system.file('extdata/SpeciesCSVs/Astraea_macroura.csv', package='occOutliers')) myPres=myPres[complete.cases(myPres),] sp::coordinates(myPres)=c(1,2) myEnv=raster::stack(system.file('extdata/AllEnv.tif',package='occOutliers')) names(myEnv)=read.table(system.file('extdata/layerNames.csv',package='occOutliers'))[,1] myPresDF=sp::SpatialPointsDataFrame(myPres,data.frame(raster::extract(myEnv,myPres))) presOut=findOutlyingPoints(pres=myPresDF, spOutliers=TRUE, pval=1e-5) world.shp=readRDS(system.file('extdata/worldShpMollwide.rds',package='occOutliers')) plotOutliers(presOut,shpToPlot = world.shp)
Using the IQR test
presOut=findOutlyingPoints(pres=myPresDF, spOutliers=TRUE, envOutliers = FALSE, method='iqr') plotOutliers(presOut,shpToPlot = world.shp,outlierNames = 'spOutlier')
Using dixon
presOut=findOutlyingPoints(pres=myPresDF, spOutliers=TRUE, envOutliers = FALSE, method='dixon') plotOutliers(presOut,shpToPlot = world.shp,outlierNames = 'spOutlier')
Using Rosner
presOut=findOutlyingPoints(pres=myPresDF, spOutliers=TRUE, envOutliers = FALSE, method='rosner', kRosner=3) plotOutliers(presOut,shpToPlot = world.shp,outlierNames = 'spOutlier')
Next, we find outliers in evironmental space.
myPres2=read.csv(system.file('extdata/SpeciesCSVs/Anarthria_scabra.csv',package='occOutliers')) myPres2=myPres2[complete.cases(myPres2),] sp::coordinates(myPres2)=c(1,2) myPres2DF=sp::SpatialPointsDataFrame(myPres2,data.frame(raster::extract(myEnv,myPres2))) presOut2=findOutlyingPoints(pres=myPres2DF, spOutliers=TRUE, envOutliers=TRUE, pval=1e-5) plotOutliers(presOut2,shpToPlot = world.shp,legLoc='topleft')
Here's an example finding both spatial and environmental outliers at the same time.
#should test for normality shapiro.test(dat_hist value) myPres3=read.csv(system.file('extdata/SpeciesCSVs/Camissonia_tanacetifolia.csv', package='occOutliers')) myPres3=myPres3[complete.cases(myPres3),] sp::coordinates(myPres3)=c(1,2) myPres3DF=sp::SpatialPointsDataFrame(myPres3,data.frame(raster::extract(myEnv,myPres3))) presOut3=findOutlyingPoints(pres=myPres3DF, spOutliers=TRUE, envOutliers=TRUE, pval=1e-3) plotOutliers(presOut3,shpToPlot = world.shp)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.