Learn R Programming

jtdm (version 0.1-3)

joint_trait_prob: Computes joint probabilities.

Description

Computes the joint probability of CWM traits in regions in the community-trait space specified by bounds and in sites specified in Xnew.

Usage

joint_trait_prob(
  m,
  indexTrait,
  bounds,
  Xnew = NULL,
  FullPost = FALSE,
  samples = NULL,
  parallel = FALSE
)

Value

A list containing:

PROBsamples

Samples from the posterior distribution of the joint probability.NULL if FullPost=FALSE.

PROBmean

Posterior mean of the joint probability.

PROBq975,PROBq025

97.5% and 0.25% posterior quantiles of the joint probability. NULL if FullPost=FALSE.

Arguments

m

a model fitted with jtdm_fit

indexTrait

A vector of the names (as specified in the column names of Y) of the two (or more!) traits we want to compute the joint probabilities of.

bounds

The parameter to specify a region in the community-trait space where the function computes the joint probabilities of traits. It is a list of the length of "indexTrait", each element of the list is a vector of length two. The vector represents the inferior and superior bounds of the region for the specified trait. For example, if we consider two traits, bounds=list(c(10,Inf),c(10,Inf)) corresponds to the region in the community-trait space where both traits both take values greater than 10.

Xnew

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

FullPost

If FullPost = TRUE, the function returns samples from the predictive distribution of joint probabilities, thus allowing the computation of credible intervals. If FullPost= FALSE, joint probabilities are computed only using the posterior mean of the parameters. FullPost cannot be equal to "mean" here.

samples

Optional, default to NULL, only works when FullPost=FALSE. Defines the number of posterior samples to compute the posterior distribution of joint probabilities. Needs to be between 1 the total number of samples drawn from the posterior distribution.

parallel

Optional, only works when FullPost = TRUE. When parallel = TRUE, the function uses mclapply to parallelise the calculation of the posterior distribution joint probabilities.

Details

This function is time consuming when FullPost = TRUE. Consider setting parallel = TRUE and/or to set samples to a value smaller than the total number of posterior samples .

Examples

Run this code
data(Y)  
data(X)  
#We sample only few samples from the posterior in order to reduce
# the computational time of the examples.
#Increase the number of samples to obtain robust results
m = jtdm_fit(Y = Y, X = X, formula = as.formula("~GDD+FDD+forest"), sample = 10)  
# Compute probability of SLA and LNC to be joint-high at sites in the studies
joint = joint_trait_prob(m, indexTrait = c("SLA","LNC"),
                         bounds = list(c(mean(Y[,"SLA"]),Inf), c(mean(Y[,"SLA"]),Inf)),
                         FullPost = TRUE)

Run the code above in your browser using DataLab