Learn R Programming

jtdm (version 0.1-3)

jtdmCV: K-fold cross validation predictions and goodness of fit metrics

Description

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

Usage

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

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.

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.

Examples

Run this code
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)

Run the code above in your browser using DataLab