Learn R Programming

lg (version 0.4.1)

partial_cor: Calculate the local Gaussian partial correlation

Description

A function that calculates the local Gaussian partial correlation for a pair of variables, given the values of some conditioning variables.

Usage

partial_cor(lg_object, grid = NULL, condition = NULL, level = NULL)

Arguments

lg_object

An object of type lg, as produced by the lg_main-function.

grid

A matrix of grid points, where we want to evaluate the density estimate. Number of columns *must* be equal to 2.

condition

A vector with conditions for the variables that we condition upon. Length of this vector *must* be the same as the number of variables in X3. The function will throw an error of there is any discrepancy in the dimensions of the grid, condition and data set.

level

Specify a level if asymptotic standard deviations and confidence intervals should be returned. If not, set to NULL.

Value

A list containing the local partial Gaussian correlations as well as all the running parameters that has been used. The elements are:

  • grid The grid where the estimation was performed, on the original scale.

  • partial_correlations The estimated local partial Gaussian correlations.

  • cond_density The estimated conditional density of X1 and X2 given X3, as described by Otneim & Tj<U+00F8>stheim (2018).

  • transformed_grid: The grid where the estimation was performed, on the marginal standard normal scale.

  • bw: The bandwidth object.

  • partial_correlations_sd Estimated standard deviations of the local partial Gaussian correlations, as described in a forthcoming paper.

  • partial_correlations_lower Lower confidence limit based on the asymptotic standard deviation.

  • partial_correlations_upper Upper confidence limit based on the asymptotic standard deviation.

Details

This function is a wrapper for the clg-function (for conditional density estimation) that returns the local conditional, or partial, correlations described by Otneim & Tj<U+00F8>stheim (2018). The function takes as arguments an lg-object as produced by the main lg_main- function, a grid of points where the density estimate should be estimated, and a set of conditions.

The variables must be sorted before they are supplied to this function. It will always assume that the free variables come before the conditioning variables, see ?clg for details.

Assume that X is a stochastic vector with scalar components X1 and X2, and a possibly d-dimensional component X3. This function will thus compute the local *partial* correlation between X1 and X2 given X3 = x3.

References

Otneim, H<U+00E5>kon, and Dag Tj<U+00F8>stheim. "Conditional density estimation using the local Gaussian correlation" Statistics and Computing 28, no. 2 (2018): 303-321.

Examples

Run this code
# NOT RUN {
  # A 3 variate example
  x <- cbind(rnorm(100), rnorm(100), rnorm(100))

  # Generate the lg-object with default settings
  lg_object <- lg_main(x)

  # Estimate the local partial Gaussian correlation between X1 and X2 given X3 = 1 on
  # a small grid
  partial_correlations <- partial_cor(lg_object,
                                     grid = cbind(-4:4, -4:4),
                                     condition = 1)

# }

Run the code above in your browser using DataLab