rnorm_pre: Make a normal vector correlated to existing vectors

Description Usage Arguments Value Examples

Description

rnorm_pre Produces a random normally distributed vector with the specified correlation to one or more existing vectors

Usage

1
rnorm_pre(x, mu = 0, sd = 1, r = 0, empirical = FALSE, threshold = 1e-12)

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

Value

vector

Examples

1
2
3
4
5
6
7
v1 <- rnorm(10)
v2 <- rnorm_pre(v1, 0, 1, 0.5)
cor(v1, v2)

x <- rnorm_multi(50, 2, .5)
x$y <- rnorm_pre(x, r = c(0.5, 0.25))
cor(x)

faux documentation built on Sept. 14, 2021, 1:08 a.m.