get_random_diffusivity_matrix {castor} | R Documentation |
Create a random diffusivity matrix for a Brownian motion model of multi-trait evolution. This may be useful for testing purposes. The diffusivity matrix is drawn from the Wishart distribution of symmetric, nonnegative-definite matrixes:
D = X^T \cdot X,\quad X[i,j]\sim N(0,V),\quad i=1,..,n, j=1,..,p,
where n is the degrees of freedom, p is the number of traits and V is a scalar scaling.
get_random_diffusivity_matrix(Ntraits, degrees=NULL, V=1)
Ntraits |
The number of traits modelled. Equal to the number of rows and the number of columns of the returned matrix. |
degrees |
Degrees of freedom for the Wishart distribution. Must be equal to or greater than |
V |
Positive number. A scalar scaling for the Wishart distribution. |
A real-valued quadratic symmetric non-negative definite matrix of size Ntraits x Ntraits. Almost surely (in the probabilistic sense), this matrix will be positive definite.
Stilianos Louca
get_random_mk_transition_matrix
,
simulate_bm_model
# generate a 5x5 diffusivity matrix D = get_random_diffusivity_matrix(Ntraits=5) # check that it is indeed positive definite if(all(eigen(D)$values>0)){ cat("Indeed positive definite\n"); }else{ cat("Not positive definite\n"); }