complement {petersenlab}R Documentation

Simulate Complement Variable.

Description

Simulate data with a specified correlation in relation to an existing variable.

Usage

complement(y, rho, x)

Arguments

y

The existing variable against which to simulate a complement variable.

rho

The correlation magnitude, ranging from [-1, 1].

x

(optional) Vector with the same length as y. Used for calculating the residuals of the least squares regression of x against y, to remove the y component from x.

Details

Simulates data with a specified correlation in relation to an existing variable.

Value

Vector of a variable that has a specified correlation in relation to a given variable y.

See Also

https://stats.stackexchange.com/a/313138/20338

Other simulation: simulateAUC(), simulateIndirectEffect()

Examples

v1 <- rnorm(100)
complement(y = v1, rho = .5)
complement(y = v1, rho = -.5)

v2 <- complement(y = v1, rho = .85)
plot(v1, v2)


[Package petersenlab version 1.0.0 Index]