logLike | R Documentation |
This function computes the log-likelihood of a model, given a model object or a set of observed and predicted values (or presence points and raster predictions).
logLike(model = NULL, obs = NULL, pred = NULL, na.rm = TRUE, plot = TRUE)
model |
a model object of class implemented in |
obs |
alternatively to 'model' and together with 'pred', a numeric vector of observed values of the response variable. Alternatively (and if 'pred' is a 'SpatRaster'), a two-column matrix or data frame containing, respectively, the x (longitude) and y (latitude) coordinates of presence points, in which case the 'obs' vector of presences and absences will be extracted with |
pred |
alternatively to 'model' and together with 'obs', a vector with the corresponding predicted values, of the same length and in the same order as 'obs'. Alternatively (and if 'obs' is a set of point coordinates), a 'SpatRaster' map of the predicted values for the entire evaluation region, in which case the 'pred' vector will be extracted with |
na.rm |
logical value indicating whether missing values should be ignored in computations. Defaults to TRUE. |
plot |
logical value indicating whether to plot the sorted values in log() (see Details). The default is TRUE. |
The log-likelihood can be a measure of model calibration (Lawson et al. 2014, Fithian et al. 2015, Fletcher & Fortin 2018). The higher the value, the better the predictions fit the observations.
The log-likelihood is computed as sum(log(pred*obs+(1-pred)*(1-obs))) (Fletcher & Fortin 2018, p. 234). If plot=TRUE, a plot is shown with the values within sum(), both within and outside log().
In the first instance of 'pred' in the formula above, a very small constant is added to the 'pred' values of zero, because the logarithm of zero is undefined. This added constant is smaller (i.e. closer to the original value of zero) here than in the R code accompanying Fletcher & Fortin (2018), specifically 2e-16 rather than 0.001, which may justify some differences in the results when there are predictions of exactly zero. In any case, whatever constant is used, it should be the same across the models being compared.
This function returns a numeric value indicating the log-likelihood of the input model predictions given the input observations.
A. Marcia Barbosa
Fithian, W., Elith, J., Hastie, T., Keith, D.A., 2015. Bias correction in species distribution models: pooling survey and collection data for multiple species. Methods in Ecology and Evolution 6:424-438. https://doi.org/10.1111/2041-210X.12242
Fletcher R. & Fortin M.-J. (2018) Spatial Ecology and Conservation Modeling. Applications with R. Springer Nature Switzerland. Cham: 532 pp. https://www.fletcherlab.com/spatial-ecology-conservation-modeli
Lawson, C.R., Hodgson, J.A., Wilson, R.J., Richards, S.A., 2013. Prevalence, thresholds and the performance of presence-absence models. Methods in Ecology and Evolution 5, 54-64. https://doi.org/10.1111/2041-210X.12123
logLik
, MillerCalib
, HLfit
,
Boyce
, RMSE
, Dsquared
,
RsqGLM
# load sample models:
data(rotif.mods)
# choose a particular model to play with:
mod <- rotif.mods$models[[1]]
logLike(model = mod)
# you can also use logLike with vectors of observed and predicted values
# instead of with a model object:
obs <- mod$y
pred <- mod$fitted.values
logLike(obs = obs, pred = pred)
# 'obs' can also be a table of presence point coordinates
# and 'pred' a SpatRaster of predicted values
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.