Get model predictions

Share:

Description

This function allows getting the predictions of multiple models when applied to a given dataset. It can be useful if you have a list of model objects (e.g. resulting from multGLM) and want to apply them to a new data set containing the same variables for another region or time period. There are options to include the logit link (Y) and/or Favourability (see Fav).

Usage

1
2
getPreds(data, models, id.col = NULL, Y = FALSE, P = TRUE, Favourability = TRUE,
incl.input = FALSE)

Arguments

data

the data frame to which to apply the models to get their predictions; must contain all variables (with the same names, case-sensitive) included in any of the models.

models

a list of model objects obtained e.g. with function glm or multGLM.

id.col

optionally, the index number of a column of data containing row identifiers, to be included in the result. Ignored if incl.input = TRUE.

Y

logical, whether to include the logit link (y) value in the predictions.

P

logical, whether to include the probability value in the predictions.

Favourability

logical, whether to include Favourability in the predictions (see Fav).

incl.input

logical, whether to include input columns in the output. The default is FALSE.

Value

This function returns a data frame containing the model predictions, next to the id.col if provided, and to the input data if incl.input = TRUE.

Author(s)

A. Marcia Barbosa

See Also

multGLM, predict

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
data(rotif.env)

names(rotif.env)


# identify rotifer data corresponding to the Eastern and Western hemispheres:

unique(rotif.env$CONTINENT)

rotif.env$HEMISPHERE <- "Eastern"

rotif.env$HEMISPHERE[rotif.env$CONTINENT %in%
c("NORTHERN_AMERICA", "SOUTHERN_AMERICA")] <- "Western"

head(rotif.env)


# separate the rotifer data into hemispheres

east.hem <- rotif.env[rotif.env$HEMISPHERE == "Eastern", ]
west.hem <- rotif.env[rotif.env$HEMISPHERE == "Western", ]


# make models for 3 of the species in rotif.env based on their distribution
# in the Eastern hemisphere:

mods <- multGLM(east.hem, sp.cols = 18:20, var.cols = 5:17, id.col = 1,
step = FALSE, FDR = FALSE, trim = FALSE)


# get the models' predictions for the Western hemisphere dataset:

preds <- getPreds(west.hem, models = mods$models, P = TRUE, Favourability = TRUE)

head(preds)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.