predict.s2bak: Make predictions using fitted SO, S2, BaK or S2BaK class...

View source: R/s2bak_predict.R

predict.s2bakR Documentation

Make predictions using fitted SO, S2, BaK or S2BaK class models #' @description S3 methods for making models predictions using the output from fit.s2bak, fit.s2bak.so, fit.s2bak.s2 and fit.s2bak.bak. If the complete model of class s2bak is provided, the user can specify what type of model predictions to use to allow for specific outputs from the sub-components of the model. When applying predict.s2bak, the function assumes that predict.fun is the same for all models.

Description

The function predict.s2bak.s2 is used for s2bak.so and s2bak.s2 models. It automatically detects which model class is provided and makes the appropriate adjustments. predict.s2bak.so is a wrapper function that detects the class of the inputed model and makes the appropriate prediction.

For s2bak.s2 models, the binary variable denoting sightings-only or survey is stored and will be checked by the function.

predict.s2bak.bak adjusts sightings-only predictions using a fitted s2bak.bak model, using trait, environmental data and sightings-only (predict.s2bak.so) predictions.

Usage

## S3 method for class 's2bak'
predict(
  model,
  newdata,
  trait = NA,
  predict.fun,
  predict.bak.fun,
  output = c("s2bak", "all", "so", "s2", "sobak")[1],
  ncores = 1,
  useReadout = FALSE,
  ...
)

## S3 method for class 's2bak.s2'
predict(model, newdata, predict.fun, useReadout = FALSE, ncores = 1, ...)

## S3 method for class 's2bak.so'
predict(model, newdata, predict.fun, useReadout = FALSE, ncores = 1, ...)

## S3 method for class 's2bak.bak'
predict(
  model,
  predictions,
  trait,
  data,
  predict.bak.fun,
  truncate = c(1e-04, 0.9999)
)

Arguments

model

Output from fit.s2bak.bak(), with fitted BaK model

newdata

A data.frame containing the values . All variables needed for prediction should be included.

trait

Trait data, with column 'species' matching those in predictions.

predict.fun

Predict function linked to the SDM used. Functions have the structure of model and newdata as the first and second arguments, respectively.

predict.bak.fun

Model function for predicting bias adjustment model (e.g., predict.glm). Needs to match bak.fun

output

The choice of how predictions are made using the s2bak model.

Only one type of output can be selected: sightings-only (output = "so"), sightings-survey (S2; output = "s2") and bias-adjusted sightings-only (output = "sobak").

If interested in using the s2bak.bak model on its own with provided model predictions, see predict.s2bak.bak.

The default method is s2bak, which will return a single set of predictions for each species, prioritizing S2 models over bias-adjusted sightings-only models and . If the full S2BaK model is provided, the function will make predictions using s2bak.predict.s2 for species with sightings and survey data, and adjusted sightings-only predictions using BaK for species without survey data. If only s2bak.so and s2bak.bak models are provided (that is, an S2BaK class model with S2 is NA), the functions returns only adjusted sightings-only predictions, requiring trait data for the species. Conversely, if only s2bak.s2 model is provided, then predictions are made only with s2bak.predict.s2.

#' If the all is selected, all sets of predictions are returned as a list: so, s2, sobak and s2bak. If models are missing, then only available predictions are made. For example, if the s2bak model contains only s2bak.s2 and s2bak.so models, then only those model predictions will be returns without BaK adjustment.

ncores

Number of cores to fit the SDMs, default is 1 core but can be automatically set if ncores=NA. If ncores > number of available cores - 1, set to the latter.

useReadout

logical; if TRUE will do readout over stored SDMs. If there are no SDMs then it will automatically check for readout

...

Additional arguments passed into function for prediction (predict.fun).

predictions

Sightings-only predictions as a matrix or data.frame with rows as sites and columns as species. Assumes as type="response", and rows of data.frame correspond to newdata rows.

data

Environmental data, with rows corresponding to rows of predictions

truncate

Numeric minimum and maximum range of predicted values. Values very close to zero or one cannot be meaningfully distinguished, however these extreme values may have disproportionally large consequences on likelihoods due to logit transformation.

survey_var

Character name for the predictor variable determining a site is sightings-only (1) or survey data (0). The column is automatically within the function, and is used to define with formula.

Value

Model predictions as a data.frame with columns for each species and rows for each location. If output = "all" is selected, a lot of data.frame predictions are returned.

Generates a matrix of predictions with rows being indices in the data.frame, and columns representing each species.

Model predictions but with adjustments made by the BaK model. Note the default right now is type="response"


leung-lab/s2bak documentation built on March 1, 2023, 9:10 a.m.