Learn R Programming

⚠️There's a newer version (1.2.6) of this package.Take me there.

generalCorr (version 1.2.0)

Generalized Correlations, Causal Paths and Portfolio Selection

Description

Since causal paths from data are important for all sciences, the package provides many sophisticated functions. causeSummBlk() gives easy-to-interpret causal paths. Let Z denote control variables and compare two flipped kernel regressions: X=f(Y, Z)+e1 and Y=g(X,Z)+e2. Our criterion Cr1 says that if |e1*Y|>|e2*X| then variation in X is more "exogenous or independent" than in Y and causal path is X to Y. Criterion Cr2 requires |e2|<|e1|. These inequalities between many absolute values are quantified by four orders of stochastic dominance. Our third criterion Cr3 for the causal path X to Y requires new generalized partial correlations to satisfy |r*(x|y,z)|< |r*(y|x,z)|. The function parcorVec() reports generalized partials between the first variable and all others. The package provides several R functions including get0outliers() for outlier detection, bigfp() for numerical integration by the trapezoidal rule, stochdom2() for stochastic dominance, pillar3D() for 3D charts, canonRho() for generalized canonical correlations, depMeas() measures nonlinear dependence, and causeSummary(mtx) reports summary of causal paths among matrix columns is easiest to use. Portfolio selection: decileVote(), momentVote(), dif4mtx(), exactSdMtx() can rank several stocks. Several functions whose names begin with 'boot' provide bootstrap statistical inference including a new bootGcRsq() test for "Granger-causality" allowing nonlinear relations. See five vignettes of the package for theory and usage tips. See Vinod (2019) \doi{10.1080/03610918.2015.1122048}.

Copy Link

Version

Install

install.packages('generalCorr')

Monthly Downloads

543

Version

1.2.0

License

GPL (>= 2)

Maintainer

Hrishikesh Vinod

Last Published

November 10th, 2021

Functions in generalCorr (1.2.0)

allPairs

Report causal identification for all pairs of variables in a matrix (deprecated function). It is better to choose a target variable and pair it with all others, instead of considering all possible targets.
abs_res

Absolute residuals of kernel regression of x on y.
GcRsqYXc

Nonlinear Granger causality between two time series workhorse function.(local constant version)
absBstdrhserC

Block version abs_stdrhser Absolute residuals kernel regressions of standardized x on y and control variables, Cr1 has abs(Resid*RHS).
NLhat

Compute fitted values from kernel regression of x on y and y on x
causeSumNoP

No print (NoP) version of causeSummBlk summary causal paths from three criteria
goodCol

internal goodCol
gmcxy_np

Function to compute generalized correlation coefficients r*(x|y) and r*(y|x) from two vectors (not matrices)
causeSummBlk

Block Version Kernel causality summary causal paths from three criteria
decileVote

Function compares nine deciles of a matrix to reference minimum (eg p stock returns)
gmc1

internal gmc1
gmcmtx0

Matrix R* of generalized correlation coefficients captures nonlinearities.
depMeas

depMeas Signed measure of nonlinear nonparametric dependence between two vectors.
kern_ctrl

Kernel regression with control variables and optional residuals and gradients.
sales2Lag

internal sales2Lag
parcorVecH

Vector of hybrid generalized partial correlation coefficients, hybrid version of parcorVec subtracting only linear effects but using generlized correlation between OLS residuals
p1

internal p1
parcorVec

Vector of generalized partial correlation coefficients (GPCC), always leaving out control variables, if any.
out1

internal out1
rstar

Function to compute generalized correlation coefficients r*(x,y).
mag

Approximate overall magnitudes of kernel regression partials dx/dy and dy/dx.
mtx2

internal mtx2
GcRsqX12c

Granger nonlinear causality R^2 for x1=f(x1,x2) minus R^2 for flipped 1 and 2
n

internal n
parcorMtx

Matrix of generalized partial correlation coefficients, always leaving out control variables, if any.
rrij

internal rrij
parcorSilent

Silently compute generalized (ridge-adjusted) partial correlation coefficients from matrix R*.
silentPairs

No-print kernel causality scores with control variables Hausman-Wu Criterion 1
silentPairs0

Older version, kernel causality weighted sum allowing control variables
rrji

internal rrji
silentMtx

No-print kernel-causality unanimity score matrix with optional control variables
stochdom2

Compute vectors measuring stochastic dominance of four orders.
silentMtx0

Older kernel-causality unanimity score matrix with optional control variables
wtdpapb

Creates input for the stochastic dominance function stochdom2
stdz_xy

Standardize x and y vectors to achieve zero mean and unit variance.
Panel2Lag

Function to compute a vector of 2 lagged values of a variable from panel data.
PanelLag

Function for computing a vector of one-lagged values of xj, a variable from panel data.
sort.abse0

internal sort.abse0
sort.e0

internal sort.e0
absBstdres

Block version of abs-stdres Absolute values of residuals of kernel regressions of standardized x on standardized y, no control variables.
abs_stdres

Absolute values of residuals of kernel regressions of x on y when both x and y are standardized.
GcRsqYX

Nonlinear Granger causality between two time series workhorse function.
abs_stdapd

Absolute values of gradients (apd's) of kernel regressions of x on y when both x and y are standardized.
absBstdresC

Block version of Absolute values of residuals of kernel regressions of standardized x on standardized y and control variables.
abs_stdapdC

Absolute values of gradients (apd's) of kernel regressions of x on y when both x and y are standardized and control variables are present.
bigfp

Compute the numerical integration by the trapezoidal rule.
bootDom12

bootstrap confidence intervals for exact stochastic dominance SD1 to SD4.
canonRho

Generalized canonical correlation, estimating alpha, beta, rho.
bootSignPcent

Probability of unambiguously correct (+ or -) sign from bootPairs output transformed to percentages.
causeAllPair

All Pair Version Kernel (block) causality summary paths from three criteria
bootSummary

Compute usual summary stats of 'sum' indexes from bootPairs output
abs_stdrhserC

Absolute residuals kernel regressions of standardized x on y and control variables, Cr1 has abs(RHS*y) not gradients.
abs_stdrhserr

Absolute values of Hausman-Wu null in kernel regressions of x on y when both x and y are standardized.
bootPairs

Compute matrix of n999 rows and p-1 columns of bootstrap `sum' (strength from Cr1 to Cr3).
e0

internal e0
generalCorrInfo

generalCorr package description:
getSeq

Two sequences: starting+ending values from n and blocksize (internal use)
mag_ctrl

After removing control variables, magnitude of effect of x on y, and of y on x.
gmc0

internal gmc0
exactSdMtx

Exact stochastic dominance computation from areas above ECDFs compared to common reference minimum (refmin) for order SD1 to SD4
get0outliers

Function to compute outliers and their count using Tukey method using 1.5 times interquartile range (IQR) to define boundaries.
ibad

internal object
ii

internal ii
momentVote

Function compares Pearson Stats and Sharpe Ratio for a matrix of stock returns
pillar3D

Create a 3D pillar chart to display (x, y, z) data coordinate surface.
pcause

Compute the bootstrap probability of correct causal direction.
minor

Function to do compute the minor of a matrix defined by row r and column c.
min.e0

internal min.e0
nam.goodCol

internal nam.goodCol
napair

Function to do pairwise deletion of missing rows.
nam.badCol

internal nam.badCol
nam.mtx0

internal nam.mtx0
parcor_linear

Partial correlation coefficient between Xi and Xj after removing the linear effect of all others.
someMagPairs

Summary magnitudes after removing control variables in several pairs where dependent variable is fixed.
rij

internal rij
someCPairs2

Kernel causality computations admitting control variables reporting a 7-column matrix, version 2.
ridgek

internal ridgek
abs_stdresC

Absolute values of residuals of kernel regressions of x on y when both x and y are standardized and control variables are present (C for control presence).
bootGcLC

Compute vector of n999 nonlinear Granger causality paths
parcor_ridg

Compute generalized (ridge-adjusted) partial correlation coefficients from matrix R*. (deprecated)
some0Pairs

Function reporting detailed kernel causality results in a 7-column matrix (uses deprecated criterion 1, no longer recommended but may be useful for second and third criterion typ=2,3)
bootGcRsq

Compute vector of n999 nonlinear Granger causality paths
bootPairs0

Compute matrix of n999 rows and p-1 columns of bootstrap `sum' index (strength from older criterion Cr1, with newer Cr2 and Cr3).
someCPairs

Kernel causality computations admitting control variables reporting a 7-column matrix (has older Cr1)
gmcmtxZ

compute the matrix R* of generalized correlation coefficients.
causeSummary

Kernel causality summary of evidence for causal paths from three criteria
causeSummary0

Older Kernel causality summary of evidence for causal paths from three criteria
dif4mtx

order 4 differencing of a matrix of time series
gmcmtxBlk

Matrix R* of generalized correlation coefficients captures nonlinearities using blocks.
dif4

order 4 differencing of a time series vector
comp_portfo2

Compares two vectors (portfolios) using stochastic dominance of orders 1 to 4.
cofactor

Compute cofactor of a matrix based on row r and column c.
nall

internal nall
parcorMany

Report many generalized partial correlation coefficients allowing control variables.
kern2ctrl

Kernel regression with control variables and optional residuals and gradients. version 2 regtype="ll" for local linear, bwmethod="cv.aic" for AIC-based bandwidth selection. It admits control variables.
parcor_ijkOLD

Generalized partial correlation coefficient between Xi and Xj after removing the effect of all others. (older version, deprecated)
kern2

Kernel regression version 2 with optional residuals and gradients with regtype="ll" for local linear, bwmethod="cv.aic" for AIC-based bandwidth selection.
naTriplet

Function to do matched deletion of missing rows from x, y and control variable(s).
parcorHijk

Generalized partial correlation coefficients between Xi and Xj, after removing the effect of Xk, via OLS regression residuals.
parcor_ijk

Generalized partial correlation coefficients between Xi and Xj, after removing the effect of xk, via nonparametric regression residuals.
rijMrji

internal rijMrji
rji

internal rji
salesLag

internal salesLag
seed

internal seed
sudoCoefParcorH

Peudo regression coefficients from hybrid generalized partial correlation coefficients (HGPCC).
stdres

Residuals of kernel regressions of x on y when both x and y are standardized.
sort_matrix

Sort all columns of matrix x with respect to the j-th column.
sudoCoefParcor

Peudo regression coefficients from generalized partial correlation coefficients, (GPCC).
diff.e0

Internal diff.e0
dig

Internal dig
heurist

Heuristic t test of the difference between two generalized correlations.
i

internal i
j

internal j
kern

Kernel regression with options for residuals and gradients.
mtx

internal mtx
mtx0

internal mtx0
parcorBijk

Block version of generalized partial correlation coefficients between Xi and Xj, after removing the effect of xk, via nonparametric regression residuals.
parcorBMany

Block version reports many generalized partial correlation coefficients allowing control variables.
prelec2

Intermediate weighting function giving Non-Expected Utility theory weights.
probSign

Compute probability of positive or negative sign from bootPairs output
rhs.lag2

internal rhs.lag2
rhs1

internal rhs1
siPairsBlk

Block Version of silentPairs for causality scores with control variables
sgn.e0

internal sgn.e0
somePairs

Function reporting kernel causality results as a 7-column matrix.(deprecated)
summaryRank

Compute ranks of rows of matrix and summarize them into a choice suggestion.
somePairs2

Function reporting kernel causality results as a 7-column matrix, version 2.
symmze

Replace asymmetric matrix by max of abs values of [ij] or [ji] elements useful in symmetrizing gmcmtx0 general correlation matrix
bootSign

Probability of unambiguously correct (+ or -) sign from bootPairs output
EuroCrime

European Crime Data
badCol

internal badCol
GcRsqX12

Granger nonlinear causality R^2 for x1=f(x1,x2), R^2 for flipped x1 and x2 and the difference between the two R^2 values
bootQuantile

Compute confidence intervals [quantile(s)] of indexes from bootPairs output
da

internal da
da2Lag

internal da2Lag