get_target_corr: Generate Samples with Target Kendall's Tau Correlation Using...

View source: R/get_target_corr.R

get_target_corrR Documentation

Generate Samples with Target Kendall's Tau Correlation Using a Copula Approach

Description

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.

Usage

get_target_corr(
  x1,
  x2,
  target_corr_kendall,
  copula_type = "gaussian",
  inv_cdf_type = "quantile_7",
  degree = 10
)

Arguments

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).

Details

This function works by:

  1. Generating two variables using the specified copula type (Gaussian or t) with the target Kendall's tau correlation.

  2. Applying the chosen inverse CDF transformation to the generated copula samples.

  3. Returning the modified variables that have the target correlation.

Value

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.

See Also

gaussian_copula_two_vars, t_copula_two_vars, genCDFInv_quantile, genCDFInv_linear, genCDFInv_akima, genCDFInv_poly

Examples

# 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


covalchemy documentation built on April 12, 2025, 2:15 a.m.