predict.DI {DImodels}R Documentation

Predict Method for Diversity-Interactions (DI) Models


Generates predictions for a fitted DI models object and, optionally, the associated standard errors for those predictions.


## S3 method for class 'DI'
predict(object, newdata, = FALSE,
interval = c("none", "confidence", "prediction"), 
level = 0.95, weights = 1,
type = c("link", "response", "terms"), ...)



a DI or autoDI model object.


optionally, a data frame in which to look for variables with which to predict. If omitted, predictions will be made for data used to fit the model.

A logical switch indicating whether to calculate the associated standard errors.


The type of interval to be calculated. Accepts one of "none", "confidence" or "prediction", with "none"" being the default.


The level (1 - \alpha) at which to calculate the interval. Defaults to 0.95, giving a 95% interval.


The variance weights for calculating the prediction intervals. By default all values get the same weight of 1. Can also specify a numeric vector of same length as number of rows in newdata.


the type of prediction required. One of "link", "response" or "terms". The default "link" is on the scale of the linear predictors while "response" is on the scale of the response variable. The "terms" option returns a matrix giving the fitted values of each term in the model formula on the linear predictor scale.


further arguments passed to or from other methods. For eg: dispersion or na.action arguments from predict.glm function.


If newdata doesn't contain all predictors from the model, necessary numeric predictors will be added in with a value of 0, while categorical predictors will be added in with their baseline value. See examples for more information.


if = FALSE, a vector of predictions is returned.

if = TRUE, a list with the following components is returned.


Predictions, as for = FALSE.

Estimated standard error for each prediction


A scalar giving the square root of the dispersion used in computing the standard errors.


Rafael A. Moral, John Connolly, Rishabh Vishwakarma and Caroline Brophy


Connolly J, T Bell, T Bolger, C Brophy, T Carnus, JA Finn, L Kirwan, F Isbell, J Levine, A Luescher, V Picasso, C Roscher, MT Sebastia, M Suter and A Weigelt (2013) An improved model to predict the effects of changing biodiversity levels on ecosystem function. Journal of Ecology, 101, 344-355.

Kirwan L, J Connolly, JA Finn, C Brophy, A Luescher, D Nyfeler and MT Sebastia (2009) Diversity-interaction modelling - estimating contributions of species identities and interactions to ecosystem function. Ecology, 90, 2032-2038.

See Also

DI autoDI predict.glm


## Load the Switzerland data
## Summarise the Switzerland data

## Fit a DI model
  m1 <- DI(y = "yield", prop = 4:7, treat = 'nitrogen', DImodel = 'AV',
  density = 'density', estimate_theta = TRUE, data = Switzerland)
## Prediction without newdata, full dataset from model fit will be used
  predict(m1, = TRUE)

## Prediction with newdata
  newdata1 <- data.frame('p1' = c(1,0), 'p2' = c(0,1), 'p3' = c(0,0), 'p4' = c(0,0),
                         'nitrogen' = c(50, 150), 'density' = c('low','high'))
  predict(m1, newdata = newdata1, = TRUE)

## If any categorical variable is missing, the baseline level
## of the variable is used for prediction
  newdata2 <- newdata1[, -5]
  predict(m1, newdata = newdata2)
## If a numerical variable is missing, the value 0 is used for it
  newdata3 <- newdata1[, -c(3,4)]
  predict(m1, newdata = newdata3)

[Package DImodels version 1.3 Index]