Learn R Programming

modEvA (version 3.5)

mod2obspred: Extract observed and predicted values from a model object.

Description

This function takes a model object and returns the observed and (optionally) the fitted values in that model.

Usage

mod2obspred(model, obs.only = FALSE)

Value

A data frame with one column containing the observed and (if obs.only=FALSE, the default) another column containing the predicted values from 'model'.

Arguments

model

a model object of class "glm", "gam", "gbm", "randomForest" or "bart" from which the response variable and fitted (predicted) values can be extracted. Note that, for "randomForest" models, only the out-of-bag prediction is available from the model object (see ?predict.randomForest if you have that package installed), so here you'll get different results if you provide 'model' or the modelled 'obs' (and corresponding 'pred') values.

obs.only

logical value indicating whether only 'obs' should be obtained (saves computing time when 'pred' not needed -- used e.g. by prevalence). Defaults to FALSE.

Author

A. Marcia Barbosa

See Also

prevalence

Examples

Run this code
data(rotif.mods)
mod <- rotif.mods$models[[1]]
obspred <- mod2obspred(mod)
head(obspred)

Run the code above in your browser using DataLab