You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Calculating measures of predictive skill for binary data
225
+
226
+
For delta models, or models of presence-absence data, several measures of predictive ability are available.
227
+
These are applicable to cross validation, although we demonstrate them here first in a non-cross validation context for simplicity.
228
+
229
+
A first commonly used diagnostic is the AUC (Area Under the Curve), which quantifies the ability of a model to discriminate between the two classes; this is done from the Receiver Operating Characteristic (ROC) curve, which plots the true positive rate vs. false positive rate.
230
+
There are several packages to calculate AUC in R, but this can be done with the `pROC` package, where inputs are a vector of 0s and 1s (or factor equivalents) in the raw data, and a vector of estimated probabilities (generated from a call to `predict()`, as shown below).
231
+
The `plogis()` function is needed to convert estimated values in logit space to probabilities in natural (zero to one) space.
232
+
233
+
```{r roc}
234
+
mesh <- make_mesh(pcod, c("X", "Y"), cutoff = 10)
235
+
fit <- sdmTMB(present ~ s(depth), data = pcod, mesh = mesh)
236
+
pred <- predict(fit) # presence-absence model
237
+
roc <- pROC::roc(pcod$present, plogis(pred$est))
238
+
auc <- pROC::auc(roc)
239
+
auc
240
+
```
241
+
242
+
With a delta model, two estimated values are returned, so only the first would be used. E.g.,
243
+
244
+
```{r}
245
+
fit <- sdmTMB(density ~ 1, data = pcod,
246
+
mesh = mesh, family = delta_gamma())
247
+
pred <- predict(fit)
248
+
249
+
# the first linear predictor is the binomial component (est1):
250
+
roc <- pROC::roc(pcod$present, plogis(pred$est1))
251
+
auc <- pROC::auc(roc)
252
+
auc
253
+
```
254
+
255
+
If we wanted to apply this in the context of cross validation, we could do it like this:
0 commit comments