Obtains predictions from a fitted joint trait distribution model and optionally computes their R squared and root mean square error (RMSE)

jtdm_predict(
  m = m,
  Xnew = NULL,
  Ynew = NULL,
  validation = FALSE,
  FullPost = "mean"
)

Arguments

m

a model fitted with jtdm_fit

Xnew

optionally, a data frame in which to look for variables with which to predict. If omitted, the fitted linear predictors are used

Ynew

Optional. The observed response variables at sites specified in Xnew. It is used to compute goodness of fit metrics when validation= T.

validation

boolean parameter to decide whether we want to compute goodness of fit measures. If true, then Ynew is needed.

FullPost

The type of predictions to be obtain. If FullPost = TRUE, the function returns samples from the predictive distribution, the credible intervals are thus the predictive credible interval. If FullPost="mean", the function computes the posterior distribution of the regression term \(BXnew\)), i.e., classical credible intervals. If FullPost=FALSE, the function only returns the posterior mean of the regression term (\(BmeanXnew\)), i.e., no credible intervals.

Value

A list containing:

Pred

Sample from the posterior distribution of the posterior predictive distribution. It is an array where the first dimension is the number of sites in Xnew, the second is the number of traits modelled and the third the number of MCMC samples. NULL if FullPost=FALSE.

PredMean

Posterior mean of posterior predictive distribution

Predq975,Predq025

97.5% and 0.25% posterior quantiles of the posterior predictive distribution. NULL if FullPost=FALSE.

R2

R squared of predictions (squared Pearson correlation between Ynew and the predictions). NULL if validation=FALSE.

RMSE

Root square mean error between squared of predictions. NULL if validation=FALSE.

Details

To obtain a full assessment of the posterior distribution, the function should be ran with FullPost=TRUE, although this can be time consuming. FullPost="mean" is used to compute partial response curves, while FullPost=FALSE is used to compute goodness of fit metrics.

Examples

data(Y)  
data(X)  
m = jtdm_fit(Y = Y, X = X, formula=as.formula("~GDD+FDD+forest"), sample = 1000)
# marginal predictions of traits in the sites of X
pred = jtdm_predict(m)