cor_data {exams.forge}R Documentation

Correlation and Data Generation

Description

Generates a data set based on x and y for a given target correlation r according to stats::cor(). The algorithm modifies the order of the y's, therefore is guaranteed that the (marginal) distribution of x and y will not be modified. Please note that it is not guaranteed that the final correlation will be the desired correlation; the algorithm interactively modifies the order. If you are unsatisfied with the result, it might help to increase maxit.

Usage

cor_data(
  x,
  y,
  r,
  method = c("pearson", "kendall", "spearman"),
  ...,
  maxit = 1000
)

dcorr(x, y, r, method = c("pearson", "kendall", "spearman"), ..., maxit = 1000)

Arguments

x

numeric: given x values

y

numeric: given y values

r

numeric: desired correlation

method

character: indicates which correlation coefficient is to be computed (default: '"pearson")

...

further parameters given to stats::cor()

maxit

numeric: maximal number of iterations (default: 1000)

Value

A matrix with two columns and an attribute interim for intermediate values as matrix. The rows of the matrix contain:

Examples

x <- runif(6)
y <- runif(6)
xy <- cor_data(x, y, r=0.6)
cbind(x, y, xy)

[Package exams.forge version 1.0.10 Index]