| cor_data | R Documentation |
Generates a data set based on 'xandyfor a given target correlationraccording to [stats::cor()]. The algorithm modifies the order of they's, therefore is guaranteed that the (marginal) distribution of x
and y is not modified. Note that is not guaranteed that the final correlation is the desired correlation;
the algorithm iteratively modifies the order. If you are unsatisfied with result it may help to increase maxit.
cor_data(
x,
y,
r,
method = c("pearson", "kendall", "spearman"),
...,
maxit = 1000
)
x |
numeric: given x values |
y |
numeric: given y values |
r |
numeric: desired correlation |
method |
character: indicating which correlation coefficient is to be computed (default: '"pearson") |
... |
further parameters given to |
maxit |
numeric: maximal number of iterations (default: |
a matrix with two columns and an attribute interim for intermediate values as matrix.
The rows of the matrix contain
if method=="pearson": x_i, y_i, x_i-bar{x}, y_i-\bar{y},
(x_i-bar{x})^2, (y_i-\bar{y})^2, and (x_i-bar{x})((y_i-\bar{y}).
if method=="kendall":
if method=="spearman": x_i, y_i, p_i (concordant pairs), and q_i (disconcordant pairs).
In a final step a vector with the row sums is appended as further column.
x <- runif(6)
y <- runif(6)
xy <- cor_data(x, y, r=0.6)
cbind(x, y, xy)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.