loo: Leave-one-out cross-validation

Description Usage Arguments Details Value Author(s) References Examples

View source: R/loo.R

Description

Computes the RMSE/log-likelihood based on leave-one-out cross-validation.

Usage

1
loo(object, type = c("loglik", "rmse"), ...)

Arguments

object

a fitted object model, currently only lm/glm is accepted.

type

the criterion to use, given as a character string, either "rmse" for Root-Mean-Square Error or "loglik" for log-likelihood.

...

other arguments are currently ignored.

Details

Leave-one-out cross validation is a K-fold cross validation, with K equal to the number of data points in the set N. For all i from 1 to N, the model is fitted to all the data except for i-th row and a prediction is made for that value. The average error is computed and used to evaluate the model.

Value

loo returns a single numeric value of RMSE or mean log-likelihood.

Author(s)

Kamil Bartoń, based on code by Carsten Dormann

References

Dormann, C. et al. (2018) Model averaging in ecology: a review of Bayesian, information-theoretic, and tactical approaches for predictive inference. Ecological Monographs, 88, 485–504.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
fm <- lm(y ~ X1 + X2 + X3 + X4, Cement)
loo(fm, type = "l")
loo(fm, type = "r")

## Compare LOO_RMSE and AIC/c
options(na.action = na.fail)
dd <- dredge(fm, rank = loo, extra = list(AIC, AICc), type = "rmse")
plot(loo ~ AIC, dd, ylab = expression(LOO[RMSE]), xlab = "AIC/c")
points(loo ~ AICc, data = dd, pch = 19)
legend("topleft", legend = c("AIC", "AICc"), pch = c(1, 19))

Example output

[1] 1.79803
[1] 2.913451
Fixed term is "(Intercept)"

MuMIn documentation built on April 17, 2020, 1:14 a.m.