corgen {ecodist}R Documentation

Generate correlated data

Description

Generate correlated data vectors of a given length.

Usage

corgen(len, x, r, population = FALSE, epsilon = 0)

Arguments

len Length of data vectors.
x Independent data.
r Correlation between data vectors.
population TRUE for vectors drawn from two populations with correlation r, otherwise r is the sample correlation.
epsilon If epsilon = 0, it has no effect, otherwise the sampling process is repeated until the sample correlation is within epsilon of r. This option allows the production of exactly-correlated data, within the limits of epsilon. Setting epsilon > 0 invalidates the population setting; data will be correlated within that range, rather than sampled from that population.

Details

Either x or len must be specified. If x is given, population must be TRUE, otherwise x is only used as the basis for generating uncorrelated starting data. This function has additional capabilities than the corgen function available in the stats package.

Value

x First data vector, either generated by corgen or given by the user.
y Second data vector.

...

Author(s)

Sarah Goslee

Examples


# create two random variables of length 100 with correlation 
# of 0.10 +/- 0.01
corgen(len=100, r=.1, epsilon=0.01)

# create a variable y drawn from a population with the given correlation to x
x <- 1:100
y <- corgen(x=x, r=.25, population=FALSE)$y


[Package ecodist version 1.1.3 Index]