Run K-fold cross validation predictions of the model m on a specified dataset.

jtdmCV(m, K = 5, sample = 1000, partition = NULL)

Arguments

m

a model fitted with jtdm_fit

K

The number of folds of the K-fold cross validation

sample

Number of samples from the posterior distribution. Since we sample from the exact posterior distribution, the number of samples is relative lower than MCMC samplers. As a rule of thumb, 1000 samples should provide correct inference.

partition

A partition of the dataset specified by the user. It is a vector (whose length are the number of sites), where each element specifies the fold index of the site.

Value

A list containing:

Pred

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

PredMean

Posterior mean of posterior predictive distribution in cross validation.

Predq975,Predq025

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

R2

R squared of predictions in cross validation.

RMSE

Root square mean error between squared of predictions in cross validation.

Examples

data(Y)  
data(X)  
m = jtdm_fit(Y=Y, X=X, formula=as.formula("~GDD+FDD+forest"), sample = 1000)  
# Run 3-fold cross validation on m
pred = jtdmCV(m, K = 5, sample = 1000)
#> Fold  1  out of  5 
#> Fold  2  out of  5 
#> Fold  3  out of  5 
#> Fold  4  out of  5 
#> Fold  5  out of  5