partial_cor {lg} | R Documentation |
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 |
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 |
level |
Specify a level if asymptotic standard deviations and confidence
intervals should be returned. If not, set to |
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:
-
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ø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.
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
# 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)