predict.dcca {douconca} | R Documentation |
Prediction of traits from environment, environment from traits and response from trait and environment data.
## S3 method for class 'dcca'
predict(
object,
...,
type = c("envFromTraits", "traitsFromEnv", "response", "SNC", "CWM", "lc", "lc_traits"),
rank = "full",
newdata = NULL,
weights = NULL,
scaling = "symmetric"
)
object |
return value of |
... |
Other arguments passed to the function (currently ignored). |
type |
type of prediction, |
rank |
rank (number of axes to use). Default "full" for all axes (no rank-reduction). |
newdata |
Data in which to look for variables with which to predict.
For |
weights |
list of weights of species and of sites in |
scaling |
numeric (1,2 or 3) or character |
Variables that are in the model but not in newdata
are set to their
weighted means in the training data. Predictions are thus at the (weighted)
mean of the quantitative variables not included. Predictions with
not-included factors are at the reference level (the first level of the
factor).
For type = "response"
, many of the predicted values may be negative,
indicating expected absences (0) or small expected response values.
With type = "traitsFromEnv"
and newdata = NULL
, predict gives
the fitted mean traits, i.e. the fitted community weighted means.
With type = "envFromTraits"
and newdata = NULL
, predict gives
the fitted mean environment, i.e. the fitted species niche centroids
(see fitted.dcca
). See fitted.dcca
.
a matrix with the predictions. The exact content of the matrix
depends on the type
of predictions that are being made.
data("dune_trait_env")
# rownames are carried forward in results
rownames(dune_trait_env$comm) <- dune_trait_env$comm$Sites
mod <- dc_CA(formulaEnv = ~ A1 + Moist + Mag + Use + Condition(Manure),
formulaTraits = ~ SLA + Height + LDMC + Condition(Seedmass) + Lifespan,
response = dune_trait_env$comm[, -1], # must delete "Sites"
dataEnv = dune_trait_env$envir,
dataTraits = dune_trait_env$traits,
verbose = FALSE)
# Ten 'new' sites with a subset of the variables in mod
# X_lot will be ignored as it is not part of the model
newEnv <- dune_trait_env$envir[1:10, c("A1", "Mag", "Manure", "X_lot")]
newEnv[2,"A1"] <- 3.0
rownames(newEnv) <- paste0("NewSite", 1:10)
pred.traits <- predict(mod, type = "traitsFromEnv", newdata = newEnv)
head(pred.traits)
# Eight 'new' species with a subset of traits that are included in the model
# Variable "L" will be ignored as it is not in the model
newTraits <- dune_trait_env$traits[1:8, c("Species", "SLA", "LDMC", "L")]
newTraits[3,"SLA"]<- 18
rownames(newTraits) <- paste("Species",LETTERS[1:8] )# or another meaningful name.
pred.env <- predict(mod, type = "envFromTraits", newdata = newTraits)
head(pred.env)
pred.resp <- predict(mod, type = "response", newdata = list(newTraits, newEnv),
weights = list(species = rep(1:2, 4), sites = rep(1, 10)))
colSums(pred.resp) # about alternating 0.8 and 1.6 (reflecting the new species weights)
rowSums(pred.resp) # about equal rowsums