knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of monkeytools is to provide some utilities functions that I use routinely. Every contribution is welcomed.
You can install the development version of monkeytools from GitHub with:
devtools::install_github("emilio-berti/monkeytools")
monkeytools is not released on CRAN.
Let's first generate some data for a virtual species that never goes above 130 meters.
library(monkeytools) library(raster) data(volcano) r <- raster(volcano) xy <- xyFromCell(r, sample(1:ncell(r), 100)) x <- extract(r ,xy) #elevation p <- ifelse(x < 130, 1, 0) #real presence/absence - doesn't like heights occ <- data.frame(x = xy[, 1], y = xy[, 2], p = p) #combined in a dataframe head(occ) # sdm potential output sdm <- 1 / r + rnorm(ncell(r), 0, .001) #sdm predictions sdm <- sdm - sdm@data@min sdm <- sdm / sdm@data@max
A very useful summary table is the confusion matrix. The confusion table calculates the fraction of correctly predicted occurrences based on observed data. For this, SDM output needs to be binarized.
sdm_bin <- sdm sdm_bin[sdm < .5] <- 0 sdm_bin[sdm >= .5] <- 1 confusion(sdm_bin, occ)
The confusion matrix is used in the famous AUROC curve, which shows how much some statistics extracted from the confusion matrix change for different binarization thresholds. The area under the AUROC curve (AUC) measures how well the SDM fits data better than random (dashed line). There are other (and better) summary statistics for goodness-of-fit of SDMs, but AUC remains one the most adopted.
null <- AUROC(sdm, occ, th = seq(0, 1, length.out = 50))
And for a very bad SDM the two lines largely overlap.
values(sdm) <- rnorm(ncell(sdm)) null <- AUROC(sdm, occ, th = seq(0, 1, length.out = 50))
This is wrapper to DiagrammeR
pacakge. It works only in HTML files.
dag_data <- data.frame( from = c("Rain", "Moisture", "Hair drier", "Rain"), to = c("Wet hair", "Wet hair", "Wet hair", "Moisture") ) draw_dag(dag_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.