Description Usage Arguments Details Value Author(s) Examples
Create two random vectors of traits correlated between each other or a vector
of traits correlated to an existing one. The linear correlation is
defined by the parameter rho
.
1 |
n |
the integer number of values to be generated. |
rho |
a numeric parameter defining the linear correlation between the two traits (default is 0.5). It must belong to the interval [-1, 1]. |
x |
an vector of numeric values. Default is NULL. |
mar.fun |
a function defining the random generation for the trait distribution. Default is
|
... |
other arguments for the |
rho
parameter is set to 0.5 by default. x = NULL
by default.
Code adapted from: http://stats.stackexchange.com/questions/15011/generate-a-random-variable-with-a-defined-correlation-to-an-existing-variable
Return a data.frame with two numeric columns, each column defining a trait.
P. Denelle F. Munoz
1 2 3 4 5 6 7 8 9 10 | # With no predefined trait
traits <- tcor(n = 10000, rho = 0.8)
plot(traits[, 1], traits[, 2])
cor(traits[, 1], traits[, 2])
# With existing trait
existing_trait <- rnorm(10000, 10, 1)
traits <- tcor(n = 10000, rho = 0.8, x = existing_trait)
plot(traits[, 1], traits[, 2])
cor(traits[, 1], traits[, 2])
|
[1] 0.795797
[1] 0.8021336
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.