rnorm_pre
Produces a random normally distributed vector with the specified correlation to one or more existing vectors
Arguments
- x
the existing vector or data table of all vectors
- mu
desired mean of returned vector
- sd
desired SD of returned vector
- r
desired correlation(s) between existing and returned vectors
- empirical
logical. If true, mu, sd and r specify the empirical not population mean, sd and covariance
- threshold
for checking correlation matrix
Examples
v1 <- rnorm(10)
v2 <- rnorm_pre(v1, 0, 1, 0.5)
cor(v1, v2)
#> [1] 0.5193761
x <- rnorm_multi(50, 2, .5)
x$y <- rnorm_pre(x, r = c(0.5, 0.25))
cor(x)
#> X1 X2 y
#> X1 1.0000000 0.2420217 0.3814651
#> X2 0.2420217 1.0000000 0.1004442
#> y 0.3814651 0.1004442 1.0000000