Learn R Programming

petersenlab (version 1.1.0)

complement: Simulate Complement Variable.

Description

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

Usage

complement(y, rho, x)

Value

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

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.

See Also

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

Other simulation: simulateAUC(), simulateIndirectEffect()

Examples

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

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

Run the code above in your browser using DataLab