Predict.msgdm | R Documentation |
Predict the zeta values for new environmental and distance data from the models returned by Zeta.msgdm
.
Predict.msgdm(model.msgdm, reg.type, newdata, type = "response")
model.msgdm |
A model returned by |
reg.type |
Type of regression used in |
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 |
type |
The type of prediction required, as for |
Predict.msgdm
returns a vector of predicted zeta values.
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.
Zeta.msgdm
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.bird1 <- bird.env.fine[1:500,3:9] ##training data
data.env.bird2 <- bird.env.fine[501:604,3:9] ##data to predict on
##glm
zeta.glm <- Zeta.msgdm(data.spec.bird, data.env.bird1, sam = 100, order = 3,
reg.type = "glm")
newdata <- data.frame(matrix(NA,100,ncol(data.env.bird1)))
names(newdata) <- names(data.env.bird1)
for(z in 1:100){
samp <- sample(1:104, 3, replace = FALSE)
newdata[z,] <- apply(apply(data.env.bird2[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)
##I-splines
zeta.ispline <- Zeta.msgdm(data.spec.bird, data.env.bird1, sam = 100, order = 3,
reg.type = "ispline", normalize = "Jaccard")
data.env.bird.splines <- Ispline(data.env.bird2)
newdata <- data.frame(matrix(NA,100,ncol(data.env.bird.splines$splines)))
names(newdata) <- names(data.env.bird.splines$splines)
for(z in 1:100){
samp <- sample(1:104, 3, replace = FALSE)
newdata[z,] <- apply(apply(data.env.bird.splines$splines[samp,], 2, stats::dist),
2, mean)
}
##rescale the data like during MS-GDM
newdata <- newdata/matrix(rep(zeta.ispline$rescale.factor,100),
100,length(zeta.ispline$rescale.factor),byrow=TRUE)
new.zeta.ispline <- Predict.msgdm(model.msgdm = zeta.ispline$model, reg.type = "ispline",
newdata = newdata)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.