View source: R/get_target_corr.R
get_target_corr | R Documentation |
This function generates two variables with a specified target Kendall's tau correlation using copula-based methods. The user can specify the type of copula (Gaussian or t), the type of inverse CDF method to apply to the variables, and the degree of the polynomial interpolation if applicable.
get_target_corr(
x1,
x2,
target_corr_kendall,
copula_type = "gaussian",
inv_cdf_type = "quantile_7",
degree = 10
)
x1 |
A numeric vector. The first dataset used for generating inverse CDFs. |
x2 |
A numeric vector. The second dataset used for generating inverse CDFs. |
target_corr_kendall |
A numeric value. The desired target Kendall's tau correlation between the two generated variables. |
copula_type |
A string. The type of copula to use, either "gaussian" or "t" (default is "gaussian"). |
inv_cdf_type |
A string. The type of inverse CDF method to use. Options include: "quantile_1", "quantile_4", "quantile_7", "quantile_8", "linear", "akima", "poly" (default is "quantile_7"). |
degree |
An integer. The degree of the polynomial interpolation (default is 10). |
This function works by:
Generating two variables using the specified copula type (Gaussian or t) with the target Kendall's tau correlation.
Applying the chosen inverse CDF transformation to the generated copula samples.
Returning the modified variables that have the target correlation.
A list containing two components: x1
and x2
, which are the modified
versions of the input datasets x1
and x2
with the desired target
Kendall's tau correlation.
gaussian_copula_two_vars
, t_copula_two_vars
,
genCDFInv_quantile
, genCDFInv_linear
,
genCDFInv_akima
, genCDFInv_poly
# Example usage:
x1 <- ChickWeight$weight
x2 <- ChickWeight$Time
cor(x1, x2, method = "kendall") # Calculate original Kendall's tau correlation
res <- get_target_corr(x1, x2, target_corr_kendall = 0,
copula_type = "gaussian", inv_cdf_type = "poly")
cor(res$x1, res$x2, method = "kendall") # Calculate modified Kendall's tau correlation
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.