Predict.msgdm: Predict zeta values for new environmental and distance data

View source: R/zetadiv.R

Predict.msgdmR Documentation

Predict zeta values for new environmental and distance data

Description

Predict the zeta values for new environmental and distance data from the models returned by Zeta.msgdm.

Usage

Predict.msgdm(model.msgdm, reg.type, newdata, type = "response")

Arguments

model.msgdm

A model returned by Zeta.msgdm. The class of the model depends on the type of regression used in Zeta.msgdm.

reg.type

Type of regression used in Zeta.msgdm. Options are "glm" for generalised linear models, "ngls" for negative linear models, "gam" for generalised additive models, "scam" for shape constrained additive models (with monotonic decreasing by default), and "ispline" for I-spline models (forcing monotonic decreasing), as recommended in generalised dissimilarity modelling by Ferrier et al. (2007).

newdata

A data frame with the new environmental and distance data. The names of the columns must be the same as the names used in the data frame used in Zeta.msgdm. For I-splines, the data frame must be generated beforehand from the original data by the function Ispline.

type

The type of prediction required, as for predict.glm. The default is on the scale of the response variable; the alternative "link" is on the scale of the linear predictors.

Value

Predict.msgdm returns a vector of predicted zeta values.

References

Ramsay, J. O. (1988). Monotone regression splines in action. Statistical Science, 425-441.

Ferrier, S., Manion, G., Elith, J., & Richardson, K. (2007). Using generalized dissimilarity modelling to analyse and predict patterns of beta diversity in regional biodiversity assessment. Diversity and Distributions, 13(3), 252-264.

See Also

Zeta.msgdm

Examples

utils::data(bird.spec.fine)
xy.bird <- bird.spec.fine[1:500,1:2]
data.spec.bird <- bird.spec.fine[1:500,3:192]
utils::data(bird.env.fine)
data.env.bird <- bird.env.fine[1:500,3:9]

zeta.glm <- Zeta.msgdm(data.spec.bird, data.env.bird, sam = 100, order = 3)
newdata <- data.frame(matrix(NA,100,ncol(data.env.bird)))
names(newdata) <- names(data.env.bird)
for(z in 1:100){
  samp <- sample(1:104, 3, replace = FALSE)
  newdata[z,] <- apply(apply(bird.env.fine[501:604,3:9][samp,], 2,
     stats::dist), 2, mean)
}
##rescale the data like during MS-GDM
newdata <- newdata/matrix(rep(zeta.glm$rescale.factor,100),
   100,length(zeta.glm$rescale.factor),byrow=TRUE)
new.zeta.glm <- Predict.msgdm(model.msgdm = zeta.glm$model, reg.type = "glm",
   newdata = newdata)



zeta.ngls <- Zeta.msgdm(data.spec.bird, data.env.bird, sam = 100, order = 3,
   reg.type = "ngls", normalize = "Jaccard")
newdata <- data.frame(matrix(NA,100,ncol(data.env.bird)))
names(newdata) <- names(data.env.bird)
for(z in 1:100){
  samp <- sample(1:104, 3, replace = FALSE)
  newdata[z,] <- apply(apply(bird.env.fine[501:604,3:9][samp,], 2, stats::dist),
     2, mean)
}
##rescale the data like during MS-GDM
newdata <- newdata/matrix(rep(zeta.ngls$rescale.factor,100),
   100,length(zeta.ngls$rescale.factor),byrow=TRUE)
new.zeta.ngls <- Predict.msgdm(model.msgdm = zeta.ngls$model, reg.type = "ngls",
   newdata = newdata)

zetadiv documentation built on June 11, 2022, 1:12 a.m.