partial_cor: Calculate the local Gaussian partial correlation

Description Usage Arguments Details Value References Examples

View source: R/partial_correlation.R

Description

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

Usage

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

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

Value

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

References

Otneim, Håkon, and Dag Tjøstheim. "Conditional density estimation using the local Gaussian correlation" Statistics and Computing 28, no. 2 (2018): 303-321.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  # 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)

hotneim/lg documentation built on May 9, 2020, 7:35 a.m.